Skip to content

Commit

Permalink
consolidate package triggers into scheduler on the default branch
Browse files Browse the repository at this point in the history
  • Loading branch information
aptalca committed Sep 4, 2024
1 parent a17d5be commit a542184
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 56 deletions.
1 change: 0 additions & 1 deletion roles/generate-jenkins/templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ templated_files:
- { src: 'LICENSE.j2', dest: 'LICENSE' }
- { src: 'lite.j2', dest: '.jenkins-external/README.lite' , readme: 'true' }
- { src: 'PACKAGE_TRIGGER_SCHEDULER.j2', dest: '.github/workflows/package_trigger_scheduler.yml' }
- { src: 'PACKAGE_TRIGGER.j2', dest: '.github/workflows/package_trigger.yml', package_trigger: 'true' }
- { src: 'PULL_REQUEST_TEMPLATE.j2', dest: '.github/PULL_REQUEST_TEMPLATE.md' }
- { src: 'README.j2', dest: 'README.md' , readme: 'true' }
- { src: 'UNRAID_TEMPLATE.j2', dest: '.jenkins-external/{{ project_name | lower }}.xml' , unraid_template: 'true' }
Expand Down
4 changes: 2 additions & 2 deletions roles/generate-jenkins/templates/Jenkinsfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ pipeline {
echo "Jenkinsfile is up to date."
fi
echo "Starting Stage 2 - Delete old templates"
OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/issue.bug.md .github/ISSUE_TEMPLATE/issue.feature.md .github/workflows/call_invalid_helper.yml .github/workflows/stale.yml"
OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/issue.bug.md .github/ISSUE_TEMPLATE/issue.feature.md .github/workflows/call_invalid_helper.yml .github/workflows/stale.yml .github/workflows/package_trigger"
{% if project_deprecation_status %}
OLD_TEMPLATES="${OLD_TEMPLATES} $(echo .github/workflows/{external_trigger,external_trigger_scheduler,package_trigger,package_trigger_scheduler,call_issue_pr_tracker,call_issues_cron}.yml)"
OLD_TEMPLATES="${OLD_TEMPLATES} $(echo .github/workflows/{external_trigger,external_trigger_scheduler,package_trigger_scheduler,call_issue_pr_tracker,call_issues_cron}.yml)"
{% endif %}
for i in ${OLD_TEMPLATES}; do
if [[ -f "${i}" ]]; then
Expand Down
42 changes: 0 additions & 42 deletions roles/generate-jenkins/templates/PACKAGE_TRIGGER.j2

This file was deleted.

43 changes: 32 additions & 11 deletions roles/generate-jenkins/templates/PACKAGE_TRIGGER_SCHEDULER.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
fetch-depth: '0'

- name: Package Trigger Scheduler
env:
SKIP_PACKAGE_TRIGGER: ${{ '{{' }} vars.SKIP_PACKAGE_TRIGGER {{ '}}' }}
run: |
printf "# Package trigger scheduler for {{ project_repo_name }}\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
Expand All @@ -24,20 +26,39 @@ jobs:
continue
fi
printf "\n## Evaluating \`%s\`\n\n" ${br} >> $GITHUB_STEP_SUMMARY
ls_branch=$(curl -sX GET https://raw.githubusercontent.com/linuxserver/{{ project_repo_name }}/${br}/jenkins-vars.yml | yq -r '.ls_branch')
if [ "${br}" == "${ls_branch}" ]; then
JENKINS_VARS=$(curl -sX GET https://raw.githubusercontent.com/linuxserver/{{ project_repo_name }}/${br}/jenkins-vars.yml)
if [[ "${br}" == $(yq -r '.ls_branch' <<< "${JENKINS_VARS}") ]]; then
echo "Branch appears to be live; checking workflow." >> $GITHUB_STEP_SUMMARY
if curl -sfX GET https://raw.githubusercontent.com/linuxserver/{{ project_repo_name }}/${br}/.github/workflows/package_trigger.yml > /dev/null 2>&1; then
echo "Triggering package trigger workflow for branch ${br}" >> $GITHUB_STEP_SUMMARY
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
elif grep -wq "^{{ project_name }}_${br}$" <<< "${SKIP_PACKAGE_TRIGGER}"; then
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
echo "> Github organizational variable \`SKIP_PACKAGE_TRIGGER\` contains \`{{ project_name }}_${br}\`; skipping trigger." >> $GITHUB_STEP_SUMMARY
elif [ $(curl -s {{ lsio_ci_url }}/job/Docker-Pipeline-Builders/job/{{ project_repo_name }}/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
else
echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY
echo "> Triggering package trigger for branch ${br}" >> $GITHUB_STEP_SUMMARY
echo "> To disable, add \`{{ project_name }}_${br}\` into the Github organizational variable \`SKIP_PACKAGE_TRIGGER\`." >> $GITHUB_STEP_SUMMARY
triggered_branches="${triggered_branches}${br} "
response=$(curl -iX POST \
{{ lsio_ci_url }}/job/Docker-Pipeline-Builders/job/{{ project_repo_name }}/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
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/linuxserver/{{ project_repo_name }}/actions/workflows/package_trigger.yml/dispatches
sleep 30
else
echo "Skipping branch ${br} due to no package trigger workflow present." >> $GITHUB_STEP_SUMMARY
"${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
fi
else
echo "Skipping branch ${br} due to being detected as dev branch." >> $GITHUB_STEP_SUMMARY
Expand Down

0 comments on commit a542184

Please sign in to comment.