2020-11-18 15:31:21 +01:00
|
|
|
name: Package Trigger Scheduler
|
|
|
|
|
|
|
|
on:
|
|
|
|
schedule:
|
2023-04-02 14:28:31 +02:00
|
|
|
- cron: '0 20 * * 6'
|
2020-11-18 15:31:21 +01:00
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
package-trigger-scheduler:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2024-02-24 21:16:35 +01:00
|
|
|
- uses: actions/checkout@v4.1.1
|
2020-11-18 15:31:21 +01:00
|
|
|
with:
|
|
|
|
fetch-depth: '0'
|
2020-12-18 22:52:41 +01:00
|
|
|
|
2020-11-18 15:31:21 +01:00
|
|
|
- name: Package Trigger Scheduler
|
2024-09-28 22:22:03 +02:00
|
|
|
env:
|
|
|
|
SKIP_PACKAGE_TRIGGER: ${{ vars.SKIP_PACKAGE_TRIGGER }}
|
2020-11-18 15:31:21 +01:00
|
|
|
run: |
|
2024-08-17 22:20:10 +02:00
|
|
|
printf "# Package trigger scheduler for docker-code-server\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-11-18 15:31:21 +01:00
|
|
|
do
|
2024-08-17 22:20:10 +02: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-28 22:22:03 +02:00
|
|
|
JENKINS_VARS=$(curl -sX GET https://raw.githubusercontent.com/linuxserver/docker-code-server/${br}/jenkins-vars.yml)
|
2024-12-19 00:41:39 +01:00
|
|
|
if ! curl -sfX GET https://raw.githubusercontent.com/linuxserver/docker-code-server/${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
|
2024-08-17 22:20:10 +02:00
|
|
|
echo "Branch appears to be live; checking workflow." >> $GITHUB_STEP_SUMMARY
|
2024-12-19 00:41:39 +01:00
|
|
|
README_VARS=$(curl -sX GET https://raw.githubusercontent.com/linuxserver/docker-code-server/${br}/readme-vars.yml)
|
|
|
|
if [[ $(yq -r '.project_deprecation_status' <<< "${README_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
|
2024-09-28 22:22:03 +02:00
|
|
|
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 "^code-server_${br}" <<< "${SKIP_PACKAGE_TRIGGER}"; then
|
|
|
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> Github organizational variable \`SKIP_PACKAGE_TRIGGER\` contains \`code-server_${br}\`; skipping trigger." >> $GITHUB_STEP_SUMMARY
|
|
|
|
skipped_branches="${skipped_branches}${br} "
|
2024-12-19 00:41:39 +01:00
|
|
|
elif [ $(curl -s https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-code-server/job/${br}/lastBuild/api/json | jq -r '.building' 2>/dev/null) == "true" ]; then
|
2024-09-28 22:22:03 +02:00
|
|
|
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 \`code-server_%s\` into the Github organizational variable \`SKIP_PACKAGE_TRIGGER\`.\n\n" "${br}" >> $GITHUB_STEP_SUMMARY
|
2020-11-25 04:39:40 +01:00
|
|
|
triggered_branches="${triggered_branches}${br} "
|
2024-09-28 22:22:03 +02:00
|
|
|
response=$(curl -iX POST \
|
|
|
|
https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-code-server/job/${br}/buildWithParameters?PACKAGE_CHECK=true \
|
|
|
|
--user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|")
|
2024-12-19 00:41:39 +01:00
|
|
|
if [[ -z "${response}" ]]; then
|
|
|
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> Jenkins build could not be triggered. Skipping branch."
|
|
|
|
continue
|
|
|
|
fi
|
2024-09-28 22:22:03 +02:00
|
|
|
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
|
2024-12-19 00:41:39 +01:00
|
|
|
if ! curl -ifX POST \
|
2024-09-28 22:22:03 +02: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 }}" \
|
2024-12-19 00:41:39 +01:00
|
|
|
--data-urlencode "Submit=Submit"; then
|
|
|
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "> Unable to change the Jenkins job description."
|
|
|
|
fi
|
2024-09-28 22:22:03 +02:00
|
|
|
sleep 20
|
2020-11-18 15:31:21 +01:00
|
|
|
fi
|
|
|
|
else
|
2023-04-29 22:17:11 +02:00
|
|
|
echo "Skipping branch ${br} due to being detected as dev branch." >> $GITHUB_STEP_SUMMARY
|
2020-11-18 15:31:21 +01:00
|
|
|
fi
|
|
|
|
done
|
2024-09-28 22:22:03 +02:00
|
|
|
if [[ -n "${triggered_branches}" ]] || [[ -n "${skipped_branches}" ]]; then
|
|
|
|
if [[ -n "${triggered_branches}" ]]; then
|
|
|
|
NOTIFY_BRANCHES="**Triggered:** ${triggered_branches} \n"
|
2024-11-09 21:19:55 +01:00
|
|
|
NOTIFY_BUILD_URL="**Build URL:** https://ci.linuxserver.io/blue/organizations/jenkins/Docker-Pipeline-Builders%2Fdocker-code-server/activity/ \n"
|
|
|
|
echo "**** Package check build(s) triggered for branch(es): ${triggered_branches} ****"
|
2024-09-28 22:22:03 +02: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-09 21:19:55 +01:00
|
|
|
"description": "**Package Check Build(s) for code-server** \n'"${NOTIFY_BRANCHES}"''"${NOTIFY_BUILD_URL}"'"}],
|
2024-09-28 22:22:03 +02:00
|
|
|
"username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }}
|
|
|
|
fi
|