servarr-stack – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | name: External Trigger Main |
2 | |||
3 | on: |
||
4 | workflow_dispatch: |
||
5 | |||
6 | jobs: |
||
7 | external-trigger-develop: |
||
8 | runs-on: ubuntu-latest |
||
9 | steps: |
||
10 | - uses: actions/checkout@v4.1.1 |
||
11 | |||
12 | - name: External Trigger |
||
13 | if: github.ref == 'refs/heads/develop' |
||
14 | env: |
||
15 | SKIP_EXTERNAL_TRIGGER: ${{ vars.SKIP_EXTERNAL_TRIGGER }} |
||
16 | run: | |
||
17 | printf "# External trigger for docker-readarr\n\n" >> $GITHUB_STEP_SUMMARY |
||
18 | if grep -q "^readarr_develop_" <<< "${SKIP_EXTERNAL_TRIGGER}"; then |
||
19 | echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY |
||
20 | echo "> Github organizational variable \`SKIP_EXTERNAL_TRIGGER\` contains \`readarr_develop_\`; will skip trigger if version matches." >> $GITHUB_STEP_SUMMARY |
||
21 | elif grep -q "^readarr_develop" <<< "${SKIP_EXTERNAL_TRIGGER}"; then |
||
22 | echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY |
||
23 | echo "> Github organizational variable \`SKIP_EXTERNAL_TRIGGER\` contains \`readarr_develop\`; skipping trigger." >> $GITHUB_STEP_SUMMARY |
||
24 | exit 0 |
||
25 | fi |
||
26 | echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY |
||
27 | echo "> External trigger running off of develop branch. To disable this trigger, add \`readarr_develop\` into the Github organizational variable \`SKIP_EXTERNAL_TRIGGER\`." >> $GITHUB_STEP_SUMMARY |
||
28 | printf "\n## Retrieving external version\n\n" >> $GITHUB_STEP_SUMMARY |
||
29 | EXT_RELEASE=$(curl -sL https://readarr.servarr.com/v1/update/develop/changes?runtime=netcore%26os=linuxmusl | jq -r '.[0].version') |
||
30 | echo "Type is \`custom_version_command\`" >> $GITHUB_STEP_SUMMARY |
||
31 | if grep -q "^readarr_develop_${EXT_RELEASE}" <<< "${SKIP_EXTERNAL_TRIGGER}"; then |
||
32 | echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY |
||
33 | echo "> Github organizational variable \`SKIP_EXTERNAL_TRIGGER\` matches current external release; skipping trigger." >> $GITHUB_STEP_SUMMARY |
||
34 | exit 0 |
||
35 | fi |
||
36 | if [ -z "${EXT_RELEASE}" ] || [ "${EXT_RELEASE}" == "null" ]; then |
||
37 | echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY |
||
38 | echo "> Can't retrieve external version, exiting" >> $GITHUB_STEP_SUMMARY |
||
39 | FAILURE_REASON="Can't retrieve external version for readarr branch develop" |
||
40 | GHA_TRIGGER_URL="https://github.com/linuxserver/docker-readarr/actions/runs/${{ github.run_id }}" |
||
41 | curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 16711680, |
||
42 | "description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n**Trigger URL:** '"${GHA_TRIGGER_URL}"' \n"}], |
||
43 | "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
||
44 | exit 1 |
||
45 | fi |
||
46 | EXT_RELEASE=$(echo ${EXT_RELEASE} | sed 's/[~,%@+;:/]//g') |
||
47 | echo "External version: \`${EXT_RELEASE}\`" >> $GITHUB_STEP_SUMMARY |
||
48 | echo "Retrieving last pushed version" >> $GITHUB_STEP_SUMMARY |
||
49 | image="linuxserver/readarr" |
||
50 | tag="develop" |
||
51 | token=$(curl -sX GET \ |
||
52 | "https://ghcr.io/token?scope=repository%3Alinuxserver%2Freadarr%3Apull" \ |
||
53 | | jq -r '.token') |
||
54 | multidigest=$(curl -s \ |
||
55 | --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ |
||
56 | --header "Accept: application/vnd.oci.image.index.v1+json" \ |
||
57 | --header "Authorization: Bearer ${token}" \ |
||
58 | "https://ghcr.io/v2/${image}/manifests/${tag}") |
||
59 | if jq -e '.layers // empty' <<< "${multidigest}" >/dev/null 2>&1; then |
||
60 | # If there's a layer element it's a single-arch manifest so just get that digest |
||
61 | digest=$(jq -r '.config.digest' <<< "${multidigest}") |
||
62 | else |
||
63 | # Otherwise it's multi-arch or has manifest annotations |
||
64 | if jq -e '.manifests[]?.annotations // empty' <<< "${multidigest}" >/dev/null 2>&1; then |
||
65 | # Check for manifest annotations and delete if found |
||
66 | multidigest=$(jq 'del(.manifests[] | select(.annotations))' <<< "${multidigest}") |
||
67 | fi |
||
68 | if [[ $(jq '.manifests | length' <<< "${multidigest}") -gt 1 ]]; then |
||
69 | # If there's still more than one digest, it's multi-arch |
||
70 | multidigest=$(jq -r ".manifests[] | select(.platform.architecture == \"amd64\").digest?" <<< "${multidigest}") |
||
71 | else |
||
72 | # Otherwise it's single arch |
||
73 | multidigest=$(jq -r ".manifests[].digest?" <<< "${multidigest}") |
||
74 | fi |
||
75 | if digest=$(curl -s \ |
||
76 | --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ |
||
77 | --header "Accept: application/vnd.oci.image.manifest.v1+json" \ |
||
78 | --header "Authorization: Bearer ${token}" \ |
||
79 | "https://ghcr.io/v2/${image}/manifests/${multidigest}"); then |
||
80 | digest=$(jq -r '.config.digest' <<< "${digest}"); |
||
81 | fi |
||
82 | fi |
||
83 | image_info=$(curl -sL \ |
||
84 | --header "Authorization: Bearer ${token}" \ |
||
85 | "https://ghcr.io/v2/${image}/blobs/${digest}") |
||
86 | if [[ $(echo $image_info | jq -r '.container_config') == "null" ]]; then |
||
87 | image_info=$(echo $image_info | jq -r '.config') |
||
88 | else |
||
89 | image_info=$(echo $image_info | jq -r '.container_config') |
||
90 | fi |
||
91 | IMAGE_RELEASE=$(echo ${image_info} | jq -r '.Labels.build_version' | awk '{print $3}') |
||
92 | IMAGE_VERSION=$(echo ${IMAGE_RELEASE} | awk -F'-ls' '{print $1}') |
||
93 | if [ -z "${IMAGE_VERSION}" ]; then |
||
94 | echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY |
||
95 | echo "Can't retrieve last pushed version, exiting" >> $GITHUB_STEP_SUMMARY |
||
96 | FAILURE_REASON="Can't retrieve last pushed version for readarr tag develop" |
||
97 | curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 16711680, |
||
98 | "description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n"}], |
||
99 | "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
||
100 | exit 1 |
||
101 | fi |
||
102 | echo "Last pushed version: \`${IMAGE_VERSION}\`" >> $GITHUB_STEP_SUMMARY |
||
103 | if [ "${EXT_RELEASE}" == "${IMAGE_VERSION}" ]; then |
||
104 | echo "Version \`${EXT_RELEASE}\` already pushed, exiting" >> $GITHUB_STEP_SUMMARY |
||
105 | exit 0 |
||
106 | elif [ $(curl -s https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-readarr/job/develop/lastBuild/api/json | jq -r '.building') == "true" ]; then |
||
107 | echo "New version \`${EXT_RELEASE}\` found; but there already seems to be an active build on Jenkins; exiting" >> $GITHUB_STEP_SUMMARY |
||
108 | exit 0 |
||
109 | else |
||
110 | if [[ "${artifacts_found}" == "false" ]]; then |
||
111 | echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY |
||
112 | echo "> New version detected, but not all artifacts are published yet; skipping trigger" >> $GITHUB_STEP_SUMMARY |
||
113 | FAILURE_REASON="New version ${EXT_RELEASE} for readarr tag develop is detected, however not all artifacts are uploaded to upstream release yet. Will try again later." |
||
114 | curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903, |
||
115 | "description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n"}], |
||
116 | "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
||
117 | else |
||
118 | printf "\n## Trigger new build\n\n" >> $GITHUB_STEP_SUMMARY |
||
119 | echo "New version \`${EXT_RELEASE}\` found; old version was \`${IMAGE_VERSION}\`. Triggering new build" >> $GITHUB_STEP_SUMMARY |
||
120 | if [[ "${artifacts_found}" == "true" ]]; then |
||
121 | echo "All artifacts seem to be uploaded." >> $GITHUB_STEP_SUMMARY |
||
122 | fi |
||
123 | response=$(curl -iX POST \ |
||
124 | https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-readarr/job/develop/buildWithParameters?PACKAGE_CHECK=false \ |
||
125 | --user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|") |
||
126 | echo "Jenkins [job queue url](${response%$'\r'})" >> $GITHUB_STEP_SUMMARY |
||
127 | echo "Sleeping 10 seconds until job starts" >> $GITHUB_STEP_SUMMARY |
||
128 | sleep 10 |
||
129 | buildurl=$(curl -s "${response%$'\r'}api/json" | jq -r '.executable.url') |
||
130 | buildurl="${buildurl%$'\r'}" |
||
131 | echo "Jenkins job [build url](${buildurl})" >> $GITHUB_STEP_SUMMARY |
||
132 | echo "Attempting to change the Jenkins job description" >> $GITHUB_STEP_SUMMARY |
||
133 | curl -iX POST \ |
||
134 | "${buildurl}submitDescription" \ |
||
135 | --user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} \ |
||
136 | --data-urlencode "description=GHA external trigger https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ |
||
137 | --data-urlencode "Submit=Submit" |
||
138 | echo "**** Notifying Discord ****" |
||
139 | TRIGGER_REASON="A version change was detected for readarr tag develop. Old version:${IMAGE_VERSION} New version:${EXT_RELEASE}" |
||
140 | curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903, |
||
141 | "description": "**Build Triggered** \n**Reason:** '"${TRIGGER_REASON}"' \n**Build URL:** '"${buildurl}display/redirect"' \n"}], |
||
142 | "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
||
143 | fi |
||
144 | fi |