From 9954c5158377e633c3a08641c0bcb76fea5e8762 Mon Sep 17 00:00:00 2001 From: "K.Matsuzawa" <49175372+k-matsuzawa@users.noreply.github.com> Date: Tue, 6 Apr 2021 17:13:31 +0900 Subject: [PATCH] hotfix: support cmake 3.20, add workflow modify checker. (#16) --- .../workflows/create_release-and-upload.yml | 3 +- .github/workflows/workflow_modify_checker.yml | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/workflow_modify_checker.yml diff --git a/.github/workflows/create_release-and-upload.yml b/.github/workflows/create_release-and-upload.yml index cbe1029..c8cd964 100644 --- a/.github/workflows/create_release-and-upload.yml +++ b/.github/workflows/create_release-and-upload.yml @@ -77,8 +77,7 @@ jobs: - name: cmake-build run: | cd cfd-sys/cfd-cmake - cmake -S . -B build - cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=${{ matrix.shared }} -DENABLE_CAPI=on -DENABLE_TESTS=off -DENABLE_JS_WRAPPER=off --build build + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_SHARED=${{ matrix.shared }} -DENABLE_CAPI=on -DENABLE_TESTS=off -DENABLE_JS_WRAPPER=off cmake --build build --parallel 2 --config Release cd ../.. timeout-minutes: 20 diff --git a/.github/workflows/workflow_modify_checker.yml b/.github/workflows/workflow_modify_checker.yml new file mode 100644 index 0000000..8c49f8e --- /dev/null +++ b/.github/workflows/workflow_modify_checker.yml @@ -0,0 +1,72 @@ +name: workflow modify checker + +# This file is is check the workflow modification on the pull request. +# If this workflow is set to work, it will forcibly cancel all workflows when any workflow changes are made. +# To get this workflow working, configure the following settings: +# 1. Push this file to the default branch. +# 2. Add issue label 'update CI'. +# 3. Set github secrets 'CANCEL_WORKFLOW_TOKEN'. (Token can cancel the repository workflow.) +# +# If you want to modify any of the workflow files, set the Pull Request label to 'update CI'. +# Then re-run the canceled workflow. + +on: + pull_request_target: + types: [opened, reopened, synchronize, labeled] + paths: + '.github/workflows/**' + +jobs: + check-actions: + name: check actions + runs-on: ubuntu-20.04 + + steps: + - name: check secret + id: check_secret + run: | + if [[ -n '${{secrets.CANCEL_WORKFLOW_TOKEN}}' ]]; then + echo "::set-output name=exist_secret::true" + else + echo "::set-output name=exist_secret::false" + fi + - if: contains(github.event.pull_request.labels.*.name, 'update CI') != true && steps.check_secret.outputs.exist_secret == 'true' + name: wait 20 sec + run: sleep 20 + - if: contains(github.event.pull_request.labels.*.name, 'update CI') != true && steps.check_secret.outputs.exist_secret == 'true' + name: cancel workflows + id: cancel_workflow + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.CANCEL_WORKFLOW_TOKEN }} + script: | + const creator = context.payload.sender.login + const opts1 = github.actions.listWorkflowRunsForRepo.endpoint.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + event: 'pull_request', + status: 'queued' + }) + const queuedWorkflows = await github.paginate(opts1) + const opts2 = github.actions.listWorkflowRunsForRepo.endpoint.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + event: 'pull_request', + status: 'in_progress' + }) + const inProgressWorkflows = await github.paginate(opts2) + const workflows = queuedWorkflows.concat(inProgressWorkflows) + //console.log(workflows); + for (const workflow of workflows) { + if (workflow.run_number == context.runNumber) continue + await github.actions.cancelWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: workflow.id + }) + console.log(`cancel: ${workflow.name} (${workflow.id}),`, + `path:${workflow.head_repository.full_name}/tree/${workflow.head_branch}`); + } + throw new Error('Change workflow file. please set label "update CI".') + - if: success() + run: echo "enabled editing workflow."