2020-12-09 11:39:01 -05:00
|
|
|
name: Package Trigger Scheduler
|
|
|
|
|
|
|
|
on:
|
|
|
|
schedule:
|
2023-04-04 12:58:17 -04:00
|
|
|
- cron: '1 3 * * 6'
|
2020-12-09 11:39:01 -05:00
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
package-trigger-scheduler:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2024-02-23 22:21:49 -05:00
|
|
|
- uses: actions/checkout@v4.1.1
|
2020-12-09 11:39:01 -05:00
|
|
|
with:
|
|
|
|
fetch-depth: '0'
|
2020-12-18 09:01:54 -05:00
|
|
|
|
2020-12-09 11:39:01 -05:00
|
|
|
- name: Package Trigger Scheduler
|
2024-09-27 23:26:43 -04:00
|
|
|
env:
|
|
|
|
SKIP_PACKAGE_TRIGGER: ${{ vars.SKIP_PACKAGE_TRIGGER }}
|
2020-12-09 11:39:01 -05:00
|
|
|
run: |
|
2024-08-23 23:22:15 -04:00
|
|
|
printf "# Package trigger scheduler for docker-swag\n\n" >> $GITHUB_STEP_SUMMARY
|
|
|
|
printf "Found the branches:\n\n%s\n" "$(git for-each-ref --format='- %(refname:lstrip=3)' refs/remotes)" >> $GITHUB_STEP_SUMMARY
|
|
|
|
for br in $(git for-each-ref --format='%(refname:lstrip=3)' refs/remotes)
|
2020-12-09 11:39:01 -05:00
|
|
|
do
|
2024-08-23 23:22:15 -04:00
|
|
|
if [[ "${br}" == "HEAD" ]]; then
|
|
|
|
printf "\nSkipping %s.\n" ${br} >> $GITHUB_STEP_SUMMARY
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
printf "\n## Evaluating \`%s\`\n\n" ${br} >> $GITHUB_STEP_SUMMARY
|
2024-09-27 23:26:43 -04:00
|
|
|
JENKINS_VARS=$(curl -sX GET https://raw.githubusercontent.com/linuxserver/docker-swag/${br}/jenkins-vars.yml)
|
|
|
|
if [[ "${br}" == $(yq -r '.ls_branch' <<< "${JENKINS_VARS}") ]]; then
|
2024-08-23 23:22:15 -04:00
|
|
|
echo "Branch appears to be live; checking workflow." >> $GITHUB_STEP_SUMMARY
|
2024-09-27 23:26:43 -04:00
|
|
|
if [[ $(yq -r '.skip_package_check' <<< "${JENKINS_VARS}") == "true" ]]; then
|
|
|
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> Skipping branch ${br} due to \`skip_package_check\` being set in \`jenkins-vars.yml\`." >> $GITHUB_STEP_SUMMARY
|
|
|
|
skipped_branches="${skipped_branches}${br} "
|
2024-10-04 23:23:29 -04:00
|
|
|
elif grep -q "^swag_${br}" <<< "${SKIP_PACKAGE_TRIGGER}"; then
|
2024-09-27 23:26:43 -04:00
|
|
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> Github organizational variable \`SKIP_PACKAGE_TRIGGER\` contains \`swag_${br}\`; skipping trigger." >> $GITHUB_STEP_SUMMARY
|
|
|
|
skipped_branches="${skipped_branches}${br} "
|
|
|
|
elif [ $(curl -s https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-swag/job/${br}/lastBuild/api/json | jq -r '.building') == "true" ]; then
|
|
|
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> There already seems to be an active build on Jenkins; skipping package trigger for ${br}" >> $GITHUB_STEP_SUMMARY
|
|
|
|
skipped_branches="${skipped_branches}${br} "
|
|
|
|
else
|
|
|
|
echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> Triggering package trigger for branch ${br}" >> $GITHUB_STEP_SUMMARY
|
|
|
|
printf "> To disable, add \`swag_%s\` into the Github organizational variable \`SKIP_PACKAGE_TRIGGER\`.\n\n" "${br}" >> $GITHUB_STEP_SUMMARY
|
2020-12-09 11:39:01 -05:00
|
|
|
triggered_branches="${triggered_branches}${br} "
|
2024-09-27 23:26:43 -04:00
|
|
|
response=$(curl -iX POST \
|
|
|
|
https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-swag/job/${br}/buildWithParameters?PACKAGE_CHECK=true \
|
|
|
|
--user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|")
|
|
|
|
echo "Jenkins [job queue url](${response%$'\r'})" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "Sleeping 10 seconds until job starts" >> $GITHUB_STEP_SUMMARY
|
|
|
|
sleep 10
|
|
|
|
buildurl=$(curl -s "${response%$'\r'}api/json" | jq -r '.executable.url')
|
|
|
|
buildurl="${buildurl%$'\r'}"
|
|
|
|
echo "Jenkins job [build url](${buildurl})" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "Attempting to change the Jenkins job description" >> $GITHUB_STEP_SUMMARY
|
2020-12-09 11:39:01 -05:00
|
|
|
curl -iX POST \
|
2024-09-27 23:26:43 -04:00
|
|
|
"${buildurl}submitDescription" \
|
|
|
|
--user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} \
|
|
|
|
--data-urlencode "description=GHA package trigger https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
|
|
|
|
--data-urlencode "Submit=Submit"
|
|
|
|
sleep 20
|
2020-12-09 11:39:01 -05:00
|
|
|
fi
|
|
|
|
else
|
2023-04-28 23:17:04 -04:00
|
|
|
echo "Skipping branch ${br} due to being detected as dev branch." >> $GITHUB_STEP_SUMMARY
|
2020-12-09 11:39:01 -05:00
|
|
|
fi
|
|
|
|
done
|
2024-09-27 23:26:43 -04:00
|
|
|
if [[ -n "${triggered_branches}" ]] || [[ -n "${skipped_branches}" ]]; then
|
|
|
|
if [[ -n "${triggered_branches}" ]]; then
|
|
|
|
NOTIFY_BRANCHES="**Triggered:** ${triggered_branches} \n"
|
2024-11-14 14:16:52 -05:00
|
|
|
NOTIFY_BUILD_URL="**Build URL:** https://ci.linuxserver.io/blue/organizations/jenkins/Docker-Pipeline-Builders%2Fdocker-swag/activity/ \n"
|
|
|
|
echo "**** Package check build(s) triggered for branch(es): ${triggered_branches} ****"
|
2024-09-27 23:26:43 -04:00
|
|
|
fi
|
|
|
|
if [[ -n "${skipped_branches}" ]]; then
|
|
|
|
NOTIFY_BRANCHES="${NOTIFY_BRANCHES}**Skipped:** ${skipped_branches} \n"
|
|
|
|
fi
|
|
|
|
echo "**** Notifying Discord ****"
|
|
|
|
curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903,
|
2024-11-14 14:16:52 -05:00
|
|
|
"description": "**Package Check Build(s) for swag** \n'"${NOTIFY_BRANCHES}"''"${NOTIFY_BUILD_URL}"'"}],
|
2024-09-27 23:26:43 -04:00
|
|
|
"username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
|
|
|
|
fi
|