Skip to content

Commit

Permalink
ci: update schedule workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 20, 2024
1 parent 2e4bfdb commit dd59ab5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/schedule-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,22 @@ jobs:
echo "filename=.lock-$IMAGE.txt" >> $GITHUB_OUTPUT
echo "artifact-name=workflow-lock-$IMAGE" >> $GITHUB_OUTPUT
- name: 'Check if workflow is already pending'
id: check-lock
env:
ARTIFACT_NAME: ${{ steps.prepare.outputs.artifact-name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
- name: 'Check if workflow is scheduled to run'
id: find-artifact
uses: myparcelnl/actions/find-artifact@v4
with:
artifact-name: ${{ steps.prepare.outputs.artifact-name }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: 'Report status'
if: steps.find-artifact.outputs.exists == 'false'
shell: bash
#language=bash
run: |
file=$(gh api "repos/$REPO/actions/artifacts" | jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\")")
echo "Workflow 'build-$IMAGE' is not scheduled to run." >> $GITHUB_STEP_SUMMARY
if [ -n "$file" ]; then
echo "has-lock=true" >> $GITHUB_OUTPUT
else
echo "has-lock=false" >> $GITHUB_OUTPUT
fi
- name: Run actual job
if: steps.check-lock.outputs.has-lock == 'true'
- name: 'Run the workflow'
if: steps.find-artifact.outputs.exists == 'true'
env:
IMAGE: ${{ matrix.image }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -61,7 +58,7 @@ jobs:
echo "Job 'build-$IMAGE' dispatched."
- name: 'Release the lock'
if: steps.check-lock.outputs.has-lock == 'true'
if: steps.find-artifact.outputs.exists == 'true'
shell: bash
env:
ARTIFACT_NAME: ${{ steps.prepare.outputs.artifact-name }}
Expand All @@ -74,6 +71,8 @@ jobs:
if [ -n "$artifactId" ]; then
gh api --method DELETE "/repos/$REPO/actions/artifacts/$artifactId"
echo "Lock artifact deleted successfully."
echo "Successfully triggered scheduled workflow 'build-$IMAGE'." >> $GITHUB_STEP_SUMMARY
else
echo "No lock artifact found."
exit 1
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ jobs:
- name: 'Check if lock file exists'
if: steps.prepare.outputs.run == 'true'
uses: ./.github/actions/check-artifact
id: check-lock
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: find-artifact
uses: myparcelnl/actions/find-artifact@v4
with:
name: ${{ steps.prepare.outputs.artifact-name }}
artifact-name: ${{ steps.prepare.outputs.artifact-name }}
token: ${{ secrets.GITHUB_TOKEN }}

- if: steps.prepare.outputs.run == 'true' && steps.check-lock.outputs.exists == 'true'
- if: steps.prepare.outputs.run == 'true' && steps.find-artifact.outputs.exists == 'true'
env:
IMAGE: ${{ matrix.image }}
shell: bash
Expand All @@ -72,7 +71,7 @@ jobs:
echo "⏱️ There was already a run scheduled for \`$IMAGE\`." >> $GITHUB_STEP_SUMMARY
- name: 'Create lock file'
if: steps.prepare.outputs.run == 'true' && steps.check-lock.outputs.exists == 'false'
if: steps.prepare.outputs.run == 'true' && steps.find-artifact.outputs.exists == 'false'
env:
FILENAME: ${{ steps.prepare.outputs.filename }}
shell: bash
Expand All @@ -82,14 +81,15 @@ jobs:
- name: 'Upload lock artifact'
uses: actions/upload-artifact@v4
if: steps.prepare.outputs.run == 'true' && steps.check-lock.outputs.exists == 'false'
if: steps.prepare.outputs.run == 'true' && steps.find-artifact.outputs.exists == 'false'
with:
if-no-files-found: error
include-hidden-files: true
name: ${{ steps.prepare.outputs.artifact-name}}
path: ${{ steps.prepare.outputs.filename }}

- if: steps.prepare.outputs.run == 'true' && steps.check-lock.outputs.exists == 'false'
- name: 'Report'
if: steps.prepare.outputs.run == 'true' && steps.find-artifact.outputs.exists == 'false'
env:
IMAGE: ${{ matrix.image }}
shell: bash
Expand Down

0 comments on commit dd59ab5

Please sign in to comment.