|
| 1 | +name: Trigger Builds on Release |
| 2 | +# Trigger builds on okd only on new releases |
| 3 | +# Assumes the branch is "master" |
| 4 | +# Uses secrets.OKD_BUILD_HOOK to know where to send the event to |
| 5 | +# OKD_BUILD_HOOK should be a generic build hook |
| 6 | + |
| 7 | +on: |
| 8 | + release: |
| 9 | + types: |
| 10 | + - released |
| 11 | + |
| 12 | +jobs: |
| 13 | + trigger_build: |
| 14 | + name: trigger build |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + # Grab committer and author information from the commit |
| 18 | + - name: get commit |
| 19 | + id: commit |
| 20 | + run: | |
| 21 | + commit_url=$( |
| 22 | + jq -r '.repository.git_commits_url' $GITHUB_EVENT_PATH | |
| 23 | + sed 's/{.*}/\/${{ github.sha }}/' |
| 24 | + ) |
| 25 | + curl --request GET \ |
| 26 | + --silent \ |
| 27 | + --show-error \ |
| 28 | + --url "$commit_url" \ |
| 29 | + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ |
| 30 | + --fail > commit-out |
| 31 | + jq -C '.' commit-out |
| 32 | + echo "::set-output name=committer::$(jq -c '.committer' commit-out)" |
| 33 | + echo "::set-output name=author::$(jq -c '.author' commit-out)" |
| 34 | +
|
| 35 | + # Construct the json blob as per okd's webhook requirements |
| 36 | + - name: format payload |
| 37 | + run: | |
| 38 | + cat $GITHUB_EVENT_PATH | \ |
| 39 | + jq '{ |
| 40 | + git: { |
| 41 | + uri: .repository.html_url, |
| 42 | + ref: "master", |
| 43 | + commit: "${{ github.sha }}", |
| 44 | + author: ${{ steps.commit.outputs.author }}, |
| 45 | + committer: ${{ steps.commit.outputs.committer }} |
| 46 | + } |
| 47 | + }' | \ |
| 48 | + tee payload.json | \ |
| 49 | + jq -C '.' |
| 50 | +
|
| 51 | + # send the webhook |
| 52 | + - name: trigger build |
| 53 | + id: hook |
| 54 | + env: |
| 55 | + OKD_BUILD_HOOK: ${{ secrets.OKD_BUILD_HOOK }} |
| 56 | + run: | |
| 57 | + curl \ |
| 58 | + --insecure \ |
| 59 | + --silent \ |
| 60 | + --show-error \ |
| 61 | + --header "Content-Type: application/json" \ |
| 62 | + --request POST \ |
| 63 | + --data @payload.json "$OKD_BUILD_HOOK" > curl-out |
| 64 | + jq -C '.' curl-out || (cat curl-out; false) |
| 65 | + echo "::set-output name=kind::$(jq '.kind' curl-out)" |
| 66 | +
|
| 67 | + # Fail if we recieved a Status response and it doesn't look good |
| 68 | + - name: test http code |
| 69 | + if: steps.hook.outputs.kind == 'Status' |
| 70 | + run: "[ `jq '.code' curl-out` -lt 400 ]" |
| 71 | + |
| 72 | + - name: test status |
| 73 | + if: steps.hook.outputs.kind == 'Status' |
| 74 | + run: "[ `jq '.status' curl-out` == 'Success' ]" |
| 75 | + |
| 76 | + - name: test if skipped |
| 77 | + if: steps.hook.outputs.kind == 'Status' |
| 78 | + run: "[[ `jq '.message' curl-out` != *skipping* ]]" |
0 commit comments