Skip to content

Commit 0258429

Browse files
committed
workflow: split generated updates from tests
1 parent 189e9d5 commit 0258429

2 files changed

Lines changed: 80 additions & 61 deletions

File tree

.github/workflows/fhem_test.yml

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,67 +33,6 @@ on:
3333
workflow_dispatch:
3434

3535
jobs:
36-
update_controls:
37-
if: github.event_name == 'push' && github.event.head_commit.message != 'Automatic update of controls and CHANGED'
38-
env:
39-
CONTROLS_FILENAME: controls_${{ github.event.repository.name }}.txt
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Extract branch name
43-
id: branch
44-
run: echo "name=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
45-
- name: Checkout repository
46-
uses: actions/checkout@v6
47-
with:
48-
fetch-depth: 0
49-
persist-credentials: false
50-
- name: Update controls file
51-
uses: fhem/fhem-controls-actions@v3.0.1
52-
with:
53-
filename: ${{ env.CONTROLS_FILENAME }}
54-
- name: Add authentication helper entries to controls file
55-
uses: fhem/fhem-controls-actions@v3.0.1
56-
with:
57-
filename: ${{ env.CONTROLS_FILENAME }}
58-
directory: lib/FHEM/Core/Authentication
59-
extension: .pm
60-
writemode: a
61-
- name: Update README branch-specific update command
62-
env:
63-
CONTROLS_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ steps.branch.outputs.name }}/${{ env.CONTROLS_FILENAME }}
64-
run: |
65-
perl -0pi -e 's{(<!-- BEGIN GENERATED FHEM UPDATE URL: one-shot -->\n```text\nupdate all )\S+(\n```\n<!-- END GENERATED FHEM UPDATE URL: one-shot -->)}{$1$ENV{CONTROLS_URL}$2}s; s{(<!-- BEGIN GENERATED FHEM UPDATE URL: persistent -->\n```text\nupdate add )\S+(\n```\n<!-- END GENERATED FHEM UPDATE URL: persistent -->)}{$1$ENV{CONTROLS_URL}$2}s' README.md
66-
- name: Regenerate README module reference
67-
run: perl scripts/update-readme-from-module-docs.pl
68-
- name: Update CHANGED
69-
run: |
70-
log="$(date +'%Y-%m-%d') - $(git log -1 --pretty=%B)"
71-
{
72-
printf '%s\n\n' "$log"
73-
cat CHANGED 2>/dev/null || true
74-
} > CHANGED.new
75-
mv CHANGED.new CHANGED
76-
- name: Commit generated files
77-
id: commit_generated
78-
run: |
79-
git config --global user.email action@github.com
80-
git config --local user.name 'GitHub Action'
81-
git add CHANGED README.md "${CONTROLS_FILENAME}" || true
82-
if ! git diff --cached --quiet; then
83-
git commit -m 'Automatic update of controls and CHANGED'
84-
echo "created=true" >> "$GITHUB_OUTPUT"
85-
else
86-
echo "created=false" >> "$GITHUB_OUTPUT"
87-
fi
88-
- name: Push generated files
89-
if: steps.commit_generated.outputs.created == 'true'
90-
env:
91-
BOT_PUSH_TOKEN: ${{ secrets.BOT_PUSH_TOKEN }}
92-
BRANCH_NAME: ${{ steps.branch.outputs.name }}
93-
run: |
94-
echo "::add-mask::$BOT_PUSH_TOKEN"
95-
git remote set-url origin "https://x-access-token:${BOT_PUSH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
96-
git push origin "HEAD:${BRANCH_NAME}"
9736
test:
9837
runs-on: ubuntu-latest
9938
concurrency:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Update Generated Files
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref_name }}
5+
cancel-in-progress: true
6+
7+
permissions:
8+
contents: read
9+
10+
on:
11+
push:
12+
paths:
13+
- 'FHEM/**'
14+
- 'lib/**'
15+
- 'README.md'
16+
- 'scripts/**'
17+
workflow_dispatch:
18+
19+
jobs:
20+
update_controls:
21+
if: github.event_name != 'push' || github.event.head_commit.message != 'Automatic update of controls and CHANGED'
22+
env:
23+
CONTROLS_FILENAME: controls_${{ github.event.repository.name }}.txt
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Extract branch name
27+
id: branch
28+
run: echo "name=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
29+
- name: Checkout repository
30+
uses: actions/checkout@v6
31+
with:
32+
fetch-depth: 0
33+
persist-credentials: false
34+
- name: Update controls file
35+
uses: fhem/fhem-controls-actions@v3.0.1
36+
with:
37+
filename: ${{ env.CONTROLS_FILENAME }}
38+
- name: Add authentication helper entries to controls file
39+
uses: fhem/fhem-controls-actions@v3.0.1
40+
with:
41+
filename: ${{ env.CONTROLS_FILENAME }}
42+
directory: lib/FHEM/Core/Authentication
43+
extension: .pm
44+
writemode: a
45+
- name: Update README branch-specific update command
46+
env:
47+
CONTROLS_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ steps.branch.outputs.name }}/${{ env.CONTROLS_FILENAME }}
48+
run: |
49+
perl -0pi -e 's{(<!-- BEGIN GENERATED FHEM UPDATE URL: one-shot -->\n```text\nupdate all )\S+(\n```\n<!-- END GENERATED FHEM UPDATE URL: one-shot -->)}{$1$ENV{CONTROLS_URL}$2}s; s{(<!-- BEGIN GENERATED FHEM UPDATE URL: persistent -->\n```text\nupdate add )\S+(\n```\n<!-- END GENERATED FHEM UPDATE URL: persistent -->)}{$1$ENV{CONTROLS_URL}$2}s' README.md
50+
- name: Regenerate README module reference
51+
run: perl scripts/update-readme-from-module-docs.pl
52+
- name: Update CHANGED
53+
run: |
54+
log="$(date +'%Y-%m-%d') - $(git log -1 --pretty=%B)"
55+
{
56+
printf '%s\n\n' "$log"
57+
cat CHANGED 2>/dev/null || true
58+
} > CHANGED.new
59+
mv CHANGED.new CHANGED
60+
- name: Commit generated files
61+
id: commit_generated
62+
run: |
63+
git config --local user.email action@github.com
64+
git config --local user.name 'GitHub Action'
65+
git add CHANGED README.md "${CONTROLS_FILENAME}" || true
66+
if ! git diff --cached --quiet; then
67+
git commit -m 'Automatic update of controls and CHANGED'
68+
echo "created=true" >> "$GITHUB_OUTPUT"
69+
else
70+
echo "created=false" >> "$GITHUB_OUTPUT"
71+
fi
72+
- name: Push generated files
73+
if: steps.commit_generated.outputs.created == 'true'
74+
env:
75+
BOT_PUSH_TOKEN: ${{ secrets.BOT_PUSH_TOKEN }}
76+
BRANCH_NAME: ${{ steps.branch.outputs.name }}
77+
run: |
78+
echo "::add-mask::$BOT_PUSH_TOKEN"
79+
git remote set-url origin "https://x-access-token:${BOT_PUSH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
80+
git push origin "HEAD:${BRANCH_NAME}"

0 commit comments

Comments
 (0)