|
4 | 4 | workflow_dispatch: |
5 | 5 |
|
6 | 6 | jobs: |
7 | | - external-trigger-master: |
| 7 | + external-trigger-chinese: |
8 | 8 | runs-on: ubuntu-latest |
9 | 9 | steps: |
10 | 10 | |
11 | 11 |
|
12 | 12 | - name: External Trigger |
13 | | - if: github.ref == 'refs/heads/master' |
| 13 | + if: github.ref == 'refs/heads/chinese' |
14 | 14 | run: | |
15 | | - echo "**** No external release, exiting ****" |
16 | | - echo "No external release, exiting" >> $GITHUB_STEP_SUMMARY |
17 | | - exit 0 |
| 15 | + if [ -n "${{ secrets.PAUSE_EXTERNAL_TRIGGER_WPS_OFFICE_CHINESE }}" ]; then |
| 16 | + echo "**** Github secret PAUSE_EXTERNAL_TRIGGER_WPS_OFFICE_CHINESE is set; skipping trigger. ****" |
| 17 | + echo "Github secret \`PAUSE_EXTERNAL_TRIGGER_WPS_OFFICE_CHINESE\` is set; skipping trigger." >> $GITHUB_STEP_SUMMARY |
| 18 | + exit 0 |
| 19 | + fi |
| 20 | + echo "**** External trigger running off of chinese branch. To disable this trigger, set a Github secret named \"PAUSE_EXTERNAL_TRIGGER_WPS_OFFICE_CHINESE\". ****" |
| 21 | + echo "External trigger running off of chinese branch. To disable this trigger, set a Github secret named \`PAUSE_EXTERNAL_TRIGGER_WPS_OFFICE_CHINESE\`" >> $GITHUB_STEP_SUMMARY |
| 22 | + echo "**** Retrieving external version ****" |
| 23 | + EXT_RELEASE=$(curl -u ${{ secrets.CR_USER }}:${{ secrets.CR_PAT }} -sX GET https://api.github.com/repos/linuxserver/docker-baseimage-kasmvnc/releases | jq -r 'first(.[] | select(.tag_name | startswith("arch-"))) | .tag_name' | sed 's|arch-||' | sed 's|-ls.*||') |
| 24 | + if [ -z "${EXT_RELEASE}" ] || [ "${EXT_RELEASE}" == "null" ]; then |
| 25 | + echo "**** Can't retrieve external version, exiting ****" |
| 26 | + FAILURE_REASON="Can't retrieve external version for wps-office branch chinese" |
| 27 | + GHA_TRIGGER_URL="https://github.com/linuxserver/docker-wps-office/actions/runs/${{ github.run_id }}" |
| 28 | + curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 16711680, |
| 29 | + "description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n**Trigger URL:** '"${GHA_TRIGGER_URL}"' \n"}], |
| 30 | + "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + EXT_RELEASE=$(echo ${EXT_RELEASE} | sed 's/[~,%@+;:/]//g') |
| 34 | + echo "**** External version: ${EXT_RELEASE} ****" |
| 35 | + echo "External version: ${EXT_RELEASE}" >> $GITHUB_STEP_SUMMARY |
| 36 | + echo "**** Retrieving last pushed version ****" |
| 37 | + image="linuxserver/wps-office" |
| 38 | + tag="chinese" |
| 39 | + token=$(curl -sX GET \ |
| 40 | + "https://ghcr.io/token?scope=repository%3Alinuxserver%2Fwps-office%3Apull" \ |
| 41 | + | jq -r '.token') |
| 42 | + multidigest=$(curl -s \ |
| 43 | + --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ |
| 44 | + --header "Authorization: Bearer ${token}" \ |
| 45 | + "https://ghcr.io/v2/${image}/manifests/${tag}" \ |
| 46 | + | jq -r 'first(.manifests[].digest)') |
| 47 | + digest=$(curl -s \ |
| 48 | + --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ |
| 49 | + --header "Authorization: Bearer ${token}" \ |
| 50 | + "https://ghcr.io/v2/${image}/manifests/${multidigest}" \ |
| 51 | + | jq -r '.config.digest') |
| 52 | + image_info=$(curl -sL \ |
| 53 | + --header "Authorization: Bearer ${token}" \ |
| 54 | + "https://ghcr.io/v2/${image}/blobs/${digest}") |
| 55 | + if [[ $(echo $image_info | jq -r '.container_config') == "null" ]]; then |
| 56 | + image_info=$(echo $image_info | jq -r '.config') |
| 57 | + else |
| 58 | + image_info=$(echo $image_info | jq -r '.container_config') |
| 59 | + fi |
| 60 | + IMAGE_RELEASE=$(echo ${image_info} | jq -r '.Labels.build_version' | awk '{print $3}') |
| 61 | + IMAGE_VERSION=$(echo ${IMAGE_RELEASE} | awk -F'-ls' '{print $1}') |
| 62 | + if [ -z "${IMAGE_VERSION}" ]; then |
| 63 | + echo "**** Can't retrieve last pushed version, exiting ****" |
| 64 | + FAILURE_REASON="Can't retrieve last pushed version for wps-office tag chinese" |
| 65 | + curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 16711680, |
| 66 | + "description": "**Trigger Failed** \n**Reason:** '"${FAILURE_REASON}"' \n"}], |
| 67 | + "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + echo "**** Last pushed version: ${IMAGE_VERSION} ****" |
| 71 | + echo "Last pushed version: ${IMAGE_VERSION}" >> $GITHUB_STEP_SUMMARY |
| 72 | + if [ "${EXT_RELEASE}" == "${IMAGE_VERSION}" ]; then |
| 73 | + echo "**** Version ${EXT_RELEASE} already pushed, exiting ****" |
| 74 | + echo "Version ${EXT_RELEASE} already pushed, exiting" >> $GITHUB_STEP_SUMMARY |
| 75 | + exit 0 |
| 76 | + elif [ $(curl -s https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-wps-office/job/chinese/lastBuild/api/json | jq -r '.building') == "true" ]; then |
| 77 | + echo "**** New version ${EXT_RELEASE} found; but there already seems to be an active build on Jenkins; exiting ****" |
| 78 | + echo "New version ${EXT_RELEASE} found; but there already seems to be an active build on Jenkins; exiting" >> $GITHUB_STEP_SUMMARY |
| 79 | + exit 0 |
| 80 | + else |
| 81 | + echo "**** New version ${EXT_RELEASE} found; old version was ${IMAGE_VERSION}. Triggering new build ****" |
| 82 | + echo "New version ${EXT_RELEASE} found; old version was ${IMAGE_VERSION}. Triggering new build" >> $GITHUB_STEP_SUMMARY |
| 83 | + response=$(curl -iX POST \ |
| 84 | + https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-wps-office/job/chinese/buildWithParameters?PACKAGE_CHECK=false \ |
| 85 | + --user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} | grep -i location | sed "s|^[L|l]ocation: \(.*\)|\1|") |
| 86 | + echo "**** Jenkins job queue url: ${response%$'\r'} ****" |
| 87 | + echo "**** Sleeping 10 seconds until job starts ****" |
| 88 | + sleep 10 |
| 89 | + buildurl=$(curl -s "${response%$'\r'}api/json" | jq -r '.executable.url') |
| 90 | + buildurl="${buildurl%$'\r'}" |
| 91 | + echo "**** Jenkins job build url: ${buildurl} ****" |
| 92 | + echo "Jenkins job build url: ${buildurl}" >> $GITHUB_STEP_SUMMARY |
| 93 | + echo "**** Attempting to change the Jenkins job description ****" |
| 94 | + curl -iX POST \ |
| 95 | + "${buildurl}submitDescription" \ |
| 96 | + --user ${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_TOKEN }} \ |
| 97 | + --data-urlencode "description=GHA external trigger https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ |
| 98 | + --data-urlencode "Submit=Submit" |
| 99 | + echo "**** Notifying Discord ****" |
| 100 | + TRIGGER_REASON="A version change was detected for wps-office tag chinese. Old version:${IMAGE_VERSION} New version:${EXT_RELEASE}" |
| 101 | + curl -X POST -H "Content-Type: application/json" --data '{"avatar_url": "https://cdn.discordapp.com/avatars/354986384542662657/df91181b3f1cf0ef1592fbe18e0962d7.png","embeds": [{"color": 9802903, |
| 102 | + "description": "**Build Triggered** \n**Reason:** '"${TRIGGER_REASON}"' \n**Build URL:** '"${buildurl}display/redirect"' \n"}], |
| 103 | + "username": "Github Actions"}' ${{ secrets.DISCORD_WEBHOOK }} |
| 104 | + fi |
0 commit comments