Skip to content

▶️ Trigger scheduled workflows #3

▶️ Trigger scheduled workflows

▶️ Trigger scheduled workflows #3

name: '▶️ Trigger scheduled workflows'
on:
# Run every day at 18:00 UTC
schedule:
- cron: '0 18 * * *'
# Or trigger manually
workflow_dispatch:
jobs:
trigger:
runs-on: ubuntu-22.04
strategy:
matrix:
image:
- elasticsearch
- node
- php-xd
- prestashop
- shopware
- wordpress
steps:
- name: 'Prepare'
id: prepare
env:
IMAGE: ${{ matrix.image }}
shell: bash
#language=bash
run: |
echo "filename=.lock-$IMAGE.txt" >> $GITHUB_OUTPUT
echo "artifact-name=workflow-lock-$IMAGE" >> $GITHUB_OUTPUT
- 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
env:
IMAGE: ${{ matrix.image }}
#language=bash
run: |
echo "Workflow 'build-$IMAGE' is not scheduled to run." >> $GITHUB_STEP_SUMMARY
- name: 'Run the workflow'
if: steps.find-artifact.outputs.exists == 'true'
env:
IMAGE: ${{ matrix.image }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
shell: bash
#language=bash
run: |
gh workflow run --repo "$REPOSITORY" "build-$IMAGE.yml"
echo "Job 'build-$IMAGE' dispatched."
- name: 'Release the lock'
if: steps.find-artifact.outputs.exists == 'true'
shell: bash
env:
ARTIFACT_NAME: ${{ steps.prepare.outputs.artifact-name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
#language=bash
run: |
artifactId=$(gh api "/repos/$REPO/actions/artifacts" --jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\") | .id")
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
fi
notify-on-failure:
needs:
- trigger
if: always() && contains(needs.*.result, 'failure')
uses: myparcelnl/actions/.github/workflows/notify-on-failure.yml@v4
secrets: inherit