-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from codex-team/change-stop-workflow-behaviour
Change the way workflow stops
- Loading branch information
Showing
1 changed file
with
14 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,11 @@ on: | |
|
||
jobs: | ||
send-message: | ||
permissions: read-all | ||
permissions: | ||
actions: write | ||
runs-on: ubuntu-22.04 | ||
env: | ||
API_URL: "https://api.github.com/repos/${{ github.repository }}/actions/runs" | ||
steps: | ||
- name: Set commit_sha to pull request head sha | ||
if: ${{ github.event_name == 'pull_request' }} | ||
|
@@ -35,20 +38,23 @@ jobs: | |
# Find results of the actions with the same SHA as this action via github api and set them to env variable | ||
- name: Get actions results | ||
run: | | ||
url="https://api.github.com/repos/${{ github.repository }}/actions/runs" | ||
echo 'ACTIONS_RESULTS<<0x0a' >> $GITHUB_ENV | ||
curl -s -X GET -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"\ | ||
"$url" | jq -r '.workflow_runs[] | select(((.head_sha=="${{ env.COMMIT_SHA }}") and (.id != ${{ github.run_id }})) | ||
"$API_URL" | jq -r '.workflow_runs[] | select(((.head_sha=="${{ env.COMMIT_SHA }}") and (.id != ${{ github.run_id }})) | ||
and ((.conclusion == "success") or (.conclusion == "failure"))) | "\(.conclusion) [\(.name)](\(.html_url))" | | ||
gsub("success"; "✅") | gsub("failure"; "❌")' >> $GITHUB_ENV | ||
echo '0x0a' >> $GITHUB_ENV | ||
# Skip if all checks were skipped/cancelled | ||
- name: Skip this workflow if none of the results have conclusion "success" or "failure" | ||
uses: styfle/[email protected] | ||
# Stop if all checks were skipped/cancelled | ||
- name: Stop this workflow if none of the results have conclusion "success" or "failure" | ||
if: ${{ env.ACTIONS_RESULTS == '' }} | ||
with: | ||
workflow_id: ${{ github.run_id }} | ||
run: | | ||
curl -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
${{ env.API_URL }}/${{ github.run_id }}/cancel | ||
- name: Send a message | ||
uses: codex-team/action-codexbot-notify@v1 | ||
|