Skip to content

▶️ Trigger scheduled workflows #8

▶️ Trigger scheduled workflows

▶️ Trigger scheduled workflows #8

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: |
workflowName="build-$IMAGE"
repositoryUrl="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
echo "artifact-name=workflow-lock-$IMAGE" >> $GITHUB_OUTPUT
echo "workflow-name=$workflowName" >> $GITHUB_OUTPUT
echo "workflow-url=$repositoryUrl/actions/workflows/$workflowName.yml" >> $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'
env:
WORKFLOW_NAME: ${{ steps.prepare.outputs.workflow-name }}
shell: bash
#language=bash
run: |
echo "Workflow '$WORKFLOW_NAME' is not scheduled to run."
- name: 'Run the workflow'
if: steps.find-artifact.outputs.exists == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE: ${{ matrix.image }}
WORKFLOW_NAME: ${{ steps.prepare.outputs.workflow-name }}
WORKFLOW_URL: ${{ steps.prepare.outputs.workflow-url }}
shell: bash
#language=bash
run: |
gh workflow run --repo "$REPOSITORY" "$WORKFLOW_NAME.yml"
echo "Job '$WORKFLOW_NAME' dispatched."
echo "Successfully triggered scheduled workflow: [\`$WORKFLOW_NAME\`]($WORKFLOW_URL)." >> $GITHUB_STEP_SUMMARY
- name: 'Release the lock'
if: steps.find-artifact.outputs.exists == 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_ID: ${{ steps.find-artifact.outputs.id }}
#language=bash
run: |
gh api --method DELETE "/repos/$GITHUB_REPOSITORY/actions/artifacts/$ARTIFACT_ID"
echo "Lock artifact deleted successfully."
notify-on-failure:
needs:
- trigger
if: always() && contains(needs.*.result, 'failure')
uses: myparcelnl/actions/.github/workflows/notify-on-failure.yml@v4
secrets: inherit