Skip to content

External Trigger Scheduler #16598

External Trigger Scheduler

External Trigger Scheduler #16598

name: External Trigger Scheduler
on:
schedule:
- cron: '43 * * * *'
workflow_dispatch:
jobs:
external-trigger-scheduler:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.1
with:
fetch-depth: '0'
- name: External Trigger Scheduler
run: |
echo "**** Branches found: ****"
git for-each-ref --format='%(refname:short)' refs/remotes
for br in $(git for-each-ref --format='%(refname:short)' refs/remotes)
do
br=$(echo "$br" | sed 's|origin/||g')
echo "**** Evaluating branch ${br} ****"
ig_jenkins_vars=$(curl -u ${{ secrets.CR_USER }}:${{ secrets.CR_PAT }} -sX GET https://raw.githubusercontent.com/imagegenius/docker-duplicati/${br}/jenkins-vars.yml)
ig_branch=$(echo "${ig_jenkins_vars}" | yq -r '.ig_branch')
ig_trigger=$(echo "${ig_jenkins_vars}" | yq -r '.external_type')
if [[ "${br}" == "${ig_branch}" ]] && [[ "${ig_trigger}" != "os" ]]; then
echo "**** Branch ${br} appears to be live and trigger is not os; checking workflow. ****"
if curl -u ${{ secrets.CR_USER }}:${{ secrets.CR_PAT }} -sfX GET https://raw.githubusercontent.com/imagegenius/docker-duplicati/${br}/.github/workflows/external_trigger.yml > /dev/null 2>&1; then
echo "**** Workflow exists. Triggering external trigger workflow for branch ${br} ****."
echo "Triggering external trigger workflow for branch ${br}" >> $GITHUB_STEP_SUMMARY
curl -iX POST \
-H "Authorization: token ${{ secrets.CR_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"ref\":\"refs/heads/${br}\"}" \
https://api.github.com/repos/imagegenius/docker-duplicati/actions/workflows/external_trigger.yml/dispatches
else
echo "**** Workflow doesn't exist; skipping trigger. ****"
echo "Skipping branch ${br} due to no external trigger workflow present." >> $GITHUB_STEP_SUMMARY
fi
else
echo "**** ${br} is either a dev branch, or has no external version; skipping trigger. ****"
echo "Skipping branch ${br} due to being detected as dev branch or having no external version." >> $GITHUB_STEP_SUMMARY
fi
done