-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hotfix: support cmake 3.20, add workflow modify checker. (#16)
- Loading branch information
1 parent
721d2fe
commit 9954c51
Showing
2 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." |