From 5dc6b7cdadae69599688d8a935aace7fa6384020 Mon Sep 17 00:00:00 2001 From: fujr Date: Sun, 15 Jun 2025 16:14:11 +0800 Subject: [PATCH] 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. --- .../workflows/commit_check_supportlist.yaml | 44 +++++++++++ .github/workflows/main.yml | 12 +-- .github/workflows/pr_check_supportlist.yaml | 77 +++++++++++++++++++ 3 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/commit_check_supportlist.yaml create mode 100644 .github/workflows/pr_check_supportlist.yaml diff --git a/.github/workflows/commit_check_supportlist.yaml b/.github/workflows/commit_check_supportlist.yaml new file mode 100644 index 0000000..25e5722 --- /dev/null +++ b/.github/workflows/commit_check_supportlist.yaml @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 09b687d..ccfdb36 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,21 +55,11 @@ jobs: with: path: 'qmodem' - - name: Update Modem_support_list + - name: Generate Release Note id: update_modem_support_list run: | cd qmodem 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 - name: Upload Release Note diff --git a/.github/workflows/pr_check_supportlist.yaml b/.github/workflows/pr_check_supportlist.yaml new file mode 100644 index 0000000..a7a4941 --- /dev/null +++ b/.github/workflows/pr_check_supportlist.yaml @@ -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