workflow: Split the original workflow and separate the support list update.

No longer check the support list in the main workflow.
Enable automatic updates to the support list only for the main branch.
Check the support list information in PRs:
Automatically close the PR if there are errors.
If there are no errors, comment on the changes made.
This commit is contained in:
fujr 2025-06-15 16:14:11 +08:00
parent 06ce7101ce
commit 5dc6b7cdad
3 changed files with 122 additions and 11 deletions

View File

@ -0,0 +1,44 @@
name: "Update Support List"
on:
push:
branches:
- 'main'
# only run when "luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json" is changed
paths:
- 'luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json'
env:
TZ: Asia/Shanghai
jobs:
update_support_list:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
env:
GH_TOKEN: ${{ github.token }}
branch_name: ${{ github.ref_name }}
with:
path: 'qmodem'
- name: Update Modem_support_list
id: update_modem_support_list
run: |
cd qmodem
is_json_invalid=0
is_diff=0
python3 ./scripts/update_support_list.py temp_support_list ./luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json || is_json_invalid=1
diff ./temp_support_list.md ./docs/support_list.md -u > /tmp/file_diff.txt || is_diff=1
if [ "$is_json_invalid" == "1" ];then
exit 1
fi
if [ "$is_diff" == "1" ];then
mv temp_support_list.md ./docs/support_list.md
git config --global user.name "GitHub Action"
git config --global user.email "github-action@users.noreply.github.com"
git add ./docs/support_list.md
git commit -m "Update support list"
git push origin ${{ env.branch_name }}
fi

View File

@ -55,21 +55,11 @@ jobs:
with: with:
path: 'qmodem' path: 'qmodem'
- name: Update Modem_support_list - name: Generate Release Note
id: update_modem_support_list id: update_modem_support_list
run: | run: |
cd qmodem cd qmodem
python3 ./scripts/update_support_list.py temp_support_list ./luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json python3 ./scripts/update_support_list.py temp_support_list ./luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json
is_diff=$(diff ./temp_support_list.md ./docs/support_list.md > /dev/null 2>&1 && echo 0 || echo 1)
echo "is_diff=${is_diff}" >> $GITHUB_ENV
if [[ ${is_pr} == 0 ]] && [[ ${is_diff} == 1 ]]; then
mv temp_support_list.md ./docs/support_list.md
git config --global user.name "GitHub Action"
git config --global user.email "github-action@users.noreply.github.com"
git add ./docs/support_list.md
git commit -m "Update support list"
git push origin ${{ env.branch_name }}
fi
mv temp_support_list_release_notes.md ./release_note.md mv temp_support_list_release_notes.md ./release_note.md
- name: Upload Release Note - name: Upload Release Note

View File

@ -0,0 +1,77 @@
name: "PR Update Support List"
on:
pull_request:
# only run when "luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json" is changed
paths:
- 'luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json'
env:
TZ: Asia/Shanghai
jobs:
update_support_list:
runs-on: ubuntu-latest
steps:
- name: Checkout PR Branch
uses: actions/checkout@v2
with:
path: 'pr_branch'
- name: Checkout Base Branch
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.base.ref }}
path: 'base_branch'
- name: Update Support List and Check
id: update_modem_support_list
env:
GH_TOKEN: ${{ github.token }}
run: |
cd pr_branch
is_json_invalid=0
python3 ./scripts/update_support_list.py temp_support_list ./luci/luci-app-qmodem/root/usr/share/qmodem/modem_support.json || is_json_invalid=1
if [ "$is_json_invalid" = "1" ]; then
echo "pr_close=1" >> $GITHUB_OUTPUT
echo "The JSON file is invalid, please check" >> pr_comment.txt
exit 0
fi
# Compare with base branch support_list.md
is_diff=0
if ! diff ./temp_support_list.md ../base_branch/docs/support_list.md > /dev/null 2>&1; then
is_diff=1
fi
# Generate pr_comment.txt for comment
echo '```' > ./pr_comment.txt
diff -u ./temp_support_list.md ../base_branch/docs/support_list.md >> ./pr_comment.txt || true
echo '```' >> ./pr_comment.txt
if [ "$is_diff" = "1" ]; then
echo "The support list has been updated, please check the changes" >> ./pr_comment.txt
echo "pr_close=0" >> $GITHUB_OUTPUT
echo "has_diff=1" >> $GITHUB_OUTPUT
else
echo "No changes in the support list" >> ./pr_comment.txt
echo "pr_close=0" >> $GITHUB_OUTPUT
echo "has_diff=0" >> $GITHUB_OUTPUT
fi
- name: Close PR if JSON Invalid
if: steps.update_modem_support_list.outputs.pr_close == '1'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd base_branch
gh pr comment ${{ github.event.pull_request.number }} -F ../pr_branch/pr_comment.txt
gh pr close ${{ github.event.pull_request.number }}
- name: Comment on PR if JSON Valid
if: steps.update_modem_support_list.outputs.pr_close == '0'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd base_branch
gh pr comment ${{ github.event.pull_request.number }} -F ../pr_branch/pr_comment.txt