Package Trigger Scheduler #215
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Package Trigger Scheduler | |
on: | |
schedule: | |
- cron: '58 18 * * 3' | |
workflow_dispatch: | |
jobs: | |
package-trigger-scheduler: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
with: | |
fetch-depth: '0' | |
- name: Package Trigger Scheduler | |
env: | |
SKIP_PACKAGE_TRIGGER: ${{ vars.SKIP_PACKAGE_TRIGGER }} | |
run: | | |
printf "# Package trigger scheduler for docker-jackett\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) | |
do | |
if [[ "${br}" == "HEAD" ]]; then | |
printf "\nSkipping %s.\n" ${br} >> $GITHUB_STEP_SUMMARY | |
continue | |
fi | |
printf "\n## Evaluating \`%s\`\n\n" ${br} >> $GITHUB_STEP_SUMMARY | |
JENKINS_VARS=$(curl -sX GET https://raw.githubusercontent.com/linuxserver/docker-jackett/${br}/jenkins-vars.yml) | |
if ! curl -sfX GET https://raw.githubusercontent.com/linuxserver/docker-jackett/${br}/Jenkinsfile >/dev/null 2>&1; then | |
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY | |
echo "> No Jenkinsfile found. Branch is either deprecated or is an early dev branch." >> $GITHUB_STEP_SUMMARY | |
skipped_branches="${skipped_branches}${br} " | |
elif [[ "${br}" == $(yq -r '.ls_branch' <<< "${JENKINS_VARS}") ]]; then | |
echo "Branch appears to be live; checking workflow." >> $GITHUB_STEP_SUMMARY | |
if [[ $(yq -r '.project_deprecation_status' <<< "${JENKINS_VARS}") == "true" ]]; then | |
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY | |
echo "> Branch appears to be deprecated; skipping trigger." >> $GITHUB_STEP_SUMMARY | |
skipped_branches="${skipped_branches}${br} " | |
elif [[ $(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} " | |
elif grep -q "^jackett_${br}" <<< "${SKIP_PACKAGE_TRIGGER}"; then | |
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY | |
echo "> Github organizational variable \`SKIP_PACKAGE_TRIGGER\` contains \`jackett_${br}\`; skipping trigger." >> $GITHUB_STEP_SUMMARY | |
skipped_branches="${skipped_branches}${br} " | |
elif [ $(curl -s https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-jackett/job/${br}/lastBuild/api/json | jq -r '.building' 2>/dev/null) == "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 \`jackett_%s\` into the Github organizational variable \`SKIP_PACKAGE_TRIGGER\`.\n\n" "${br}" >> $GITHUB_STEP_SUMMARY | |
triggered_branches="${triggered_branches}${br} " | |
response=$(curl -iX POST \ | |
https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-jackett/job/${br}/buildWithParameters?PACKAGE_CHECK=true \ | |
--user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|") | |
if [[ -z "${response}" ]]; then | |
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY" | |
echo "> Jenkins build could not be triggered. Skipping branch." | |
continue | |
fi | |
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 | |
if curl -ifX POST \ | |
"${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"; then | |
else | |
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY" | |
echo "> Unable to change the Jenkins job description." | |
fi | |
sleep 20 | |
fi | |
else | |
echo "Skipping branch ${br} due to being detected as dev branch." >> $GITHUB_STEP_SUMMARY | |
fi | |
done | |
if [[ -n "${triggered_branches}" ]] || [[ -n "${skipped_branches}" ]]; then | |
if [[ -n "${triggered_branches}" ]]; then | |
NOTIFY_BRANCHES="**Triggered:** ${triggered_branches} \n" | |
NOTIFY_BUILD_URL="**Build URL:** https://ci.linuxserver.io/blue/organizations/jenkins/Docker-Pipeline-Builders%2Fdocker-jackett/activity/ \n" | |
echo "**** Package check build(s) triggered for branch(es): ${triggered_branches} ****" | |
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, | |
"description": "**Package Check Build(s) for jackett** \n'"${NOTIFY_BRANCHES}"''"${NOTIFY_BUILD_URL}"'"}], | |
"username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} | |
fi |