1414 fetch-depth : ' 0'
1515
1616 - name : Package Trigger Scheduler
17+ env :
18+ SKIP_PACKAGE_TRIGGER : ${{ vars.SKIP_PACKAGE_TRIGGER }}
1719 run : |
1820 printf "# Package trigger scheduler for docker-ci\n\n" >> $GITHUB_STEP_SUMMARY
1921 printf "Found the branches:\n\n%s\n" "$(git for-each-ref --format='- %(refname:lstrip=3)' refs/remotes)" >> $GITHUB_STEP_SUMMARY
@@ -24,27 +26,57 @@ jobs:
2426 continue
2527 fi
2628 printf "\n## Evaluating \`%s\`\n\n" ${br} >> $GITHUB_STEP_SUMMARY
27- ls_branch =$(curl -sX GET https://raw.githubusercontent.com/linuxserver/docker-ci/${br}/jenkins-vars.yml | yq -r '.ls_branch' )
28- if [ "${br}" == "${ls_branch}" ]; then
29+ JENKINS_VARS =$(curl -sX GET https://raw.githubusercontent.com/linuxserver/docker-ci/${br}/jenkins-vars.yml)
30+ if [[ "${br}" == $(yq -r '.ls_branch' <<< "${JENKINS_VARS}") ] ]; then
2931 echo "Branch appears to be live; checking workflow." >> $GITHUB_STEP_SUMMARY
30- if curl -sfX GET https://raw.githubusercontent.com/linuxserver/docker-ci/${br}/.github/workflows/package_trigger.yml > /dev/null 2>&1; then
31- echo "Triggering package trigger workflow for branch ${br}" >> $GITHUB_STEP_SUMMARY
32+ if [[ $(yq -r '.skip_package_check' <<< "${JENKINS_VARS}") == "true" ]]; then
33+ echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
34+ echo "> Skipping branch ${br} due to \`skip_package_check\` being set in \`jenkins-vars.yml\`." >> $GITHUB_STEP_SUMMARY
35+ skipped_branches="${skipped_branches}${br} "
36+ elif grep -q "^ci_${br}" <<< "${SKIP_PACKAGE_TRIGGER}"; then
37+ echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
38+ echo "> Github organizational variable \`SKIP_PACKAGE_TRIGGER\` contains \`ci_${br}\`; skipping trigger." >> $GITHUB_STEP_SUMMARY
39+ skipped_branches="${skipped_branches}${br} "
40+ elif [ $(curl -s https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-ci/job/${br}/lastBuild/api/json | jq -r '.building') == "true" ]; then
41+ echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
42+ echo "> There already seems to be an active build on Jenkins; skipping package trigger for ${br}" >> $GITHUB_STEP_SUMMARY
43+ skipped_branches="${skipped_branches}${br} "
44+ else
45+ echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY
46+ echo "> Triggering package trigger for branch ${br}" >> $GITHUB_STEP_SUMMARY
47+ printf "> To disable, add \`ci_%s\` into the Github organizational variable \`SKIP_PACKAGE_TRIGGER\`.\n\n" "${br}" >> $GITHUB_STEP_SUMMARY
3248 triggered_branches="${triggered_branches}${br} "
49+ response=$(curl -iX POST \
50+ https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-ci/job/${br}/buildWithParameters?PACKAGE_CHECK=true \
51+ --user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|")
52+ echo "Jenkins [job queue url](${response%$'\r'})" >> $GITHUB_STEP_SUMMARY
53+ echo "Sleeping 10 seconds until job starts" >> $GITHUB_STEP_SUMMARY
54+ sleep 10
55+ buildurl=$(curl -s "${response%$'\r'}api/json" | jq -r '.executable.url')
56+ buildurl="${buildurl%$'\r'}"
57+ echo "Jenkins job [build url](${buildurl})" >> $GITHUB_STEP_SUMMARY
58+ echo "Attempting to change the Jenkins job description" >> $GITHUB_STEP_SUMMARY
3359 curl -iX POST \
34- -H "Authorization: token ${{ secrets.CR_PAT }}" \
35- -H "Accept: application/vnd.github.v3+json" \
36- -d "{\"ref\":\"refs/heads/${br}\"}" \
37- https://api.github.com/repos/linuxserver/docker-ci/actions/workflows/package_trigger.yml/dispatches
38- sleep 30
39- else
40- echo "Skipping branch ${br} due to no package trigger workflow present." >> $GITHUB_STEP_SUMMARY
60+ "${buildurl}submitDescription" \
61+ --user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} \
62+ --data-urlencode "description=GHA package trigger https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
63+ --data-urlencode "Submit=Submit"
64+ sleep 20
4165 fi
4266 else
4367 echo "Skipping branch ${br} due to being detected as dev branch." >> $GITHUB_STEP_SUMMARY
4468 fi
4569 done
46- echo "**** Package check build(s) triggered for branch(es): ${triggered_branches} ****"
47- echo "**** Notifying Discord ****"
48- curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903,
49- "description": "**Package Check Build(s) Triggered for ci** \n**Branch(es):** '"${triggered_branches}"' \n**Build URL:** '"https://ci.linuxserver.io/blue/organizations/jenkins/Docker-Pipeline-Builders%2Fdocker-ci/activity/"' \n"}],
50- "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
70+ if [[ -n "${triggered_branches}" ]] || [[ -n "${skipped_branches}" ]]; then
71+ if [[ -n "${triggered_branches}" ]]; then
72+ NOTIFY_BRANCHES="**Triggered:** ${triggered_branches} \n"
73+ fi
74+ if [[ -n "${skipped_branches}" ]]; then
75+ NOTIFY_BRANCHES="${NOTIFY_BRANCHES}**Skipped:** ${skipped_branches} \n"
76+ fi
77+ echo "**** Package check build(s) triggered for branch(es): ${triggered_branches} ****"
78+ echo "**** Notifying Discord ****"
79+ curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903,
80+ "description": "**Package Check Build(s) Triggered for ci** \n'"${NOTIFY_BRANCHES}"'**Build URL:** '"https://ci.linuxserver.io/blue/organizations/jenkins/Docker-Pipeline-Builders%2Fdocker-ci/activity/"' \n"}],
81+ "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
82+ fi
0 commit comments