Skip to content

Commit

Permalink
half-baked DYI solution for separate action to check for duplicated b…
Browse files Browse the repository at this point in the history
…uilds
  • Loading branch information
basti1302 committed Feb 1, 2025
1 parent a00ab4b commit 3857330
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/actions/check-previous-builds/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: check for successful workflow runs for the same commit
description: uses the GitHub REST API to check whether a successful workflow run for the same commit already exists

inputs:
githubToken:
description: "github token"
required: true
# TODO this also needs the id/name of the actual workflow

runs:
using: "composite"
steps:
- name: list successful builds
id: list_successful_builds
uses: octokit/[email protected]
with:
# https://docs.github.com/en/rest/actions/workflow-runs
route: GET /repos/${{ github.repository }}/actions/runs?head_sha=${{ github.sha }}&status=success
env:
GITHUB_TOKEN: ${{ inputs.githubToken }}

# TODO remove this debug output
- run: "echo successful builds: '${{ steps.list_successful_builds.outputs.data }}'"

- name: process Github API response
id: successful_builds_for_same_commit_exist
run: |
export number_of_successful_builds=${{ fromJson(steps.list_successful_builds.outputs.data).total_count }}
if [[ $number_of_successful_builds -gt 0 ]]; then
echo "result=true" >> $GITHUB_OUTPUT
else
echo "result=false" >> $GITHUB_OUTPUT
fi
# TODO remove this debug output
- run: "echo has successful builds: '${{ steps.successful_builds_for_same_commit_exist.outputs.result }}'"

# TODO write to output

outputs:
successful-build-exists:
description: "whether a successful workflow run exists for the same commit"
value: ${{ steps.successful_builds_for_same_commit_exist.outputs.result }}

2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- run: "echo has successful builds: '${{ steps.successful_builds_for_same_commit_exist.outputs.result }}'"


separate_step:
separate_job:
runs-on: ubuntu-latest
steps:
- run: "echo separate step, has successful builds: '${{ steps.successful_builds_for_same_commit_exist.outputs.result }}'"
Expand Down

0 comments on commit 3857330

Please sign in to comment.