aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Meinhold <mxmeinhold@gmail.com>2021-03-21 01:45:45 -0400
committerMax Meinhold <mxmeinhold@gmail.com>2021-03-21 01:45:45 -0400
commitf6d9a1390fc475397b7412d0e8bd64bbfb4e7705 (patch)
tree4f3d92e2446f71510e25ed1e3bf0df1656e772fb
parent096f6309754bf5715c62c0208719700474d0667f (diff)
Automate deployments when new releases are made
-rw-r--r--.github/workflows/deploy.yml78
1 files changed, 78 insertions, 0 deletions
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000..9565b02
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,78 @@
+name: Trigger Builds on Release
+# Trigger builds on okd only on new releases
+# Assumes the branch is "master"
+# Uses secrets.OKD_BUILD_HOOK to know where to send the event to
+# OKD_BUILD_HOOK should be a generic build hook
+
+on:
+ release:
+ types:
+ - released
+
+jobs:
+ trigger_build:
+ name: trigger build
+ runs-on: ubuntu-latest
+ steps:
+ # Grab committer and author information from the commit
+ - name: get commit
+ id: commit
+ run: |
+ commit_url=$(
+ jq -r '.repository.git_commits_url' $GITHUB_EVENT_PATH |
+ sed 's/{.*}/\/${{ github.sha }}/'
+ )
+ curl --request GET \
+ --silent \
+ --show-error \
+ --url "$commit_url" \
+ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
+ --fail > commit-out
+ jq -C '.' commit-out
+ echo "::set-output name=committer::$(jq -c '.committer' commit-out)"
+ echo "::set-output name=author::$(jq -c '.author' commit-out)"
+
+ # Construct the json blob as per okd's webhook requirements
+ - name: format payload
+ run: |
+ cat $GITHUB_EVENT_PATH | \
+ jq '{
+ git: {
+ uri: .repository.html_url,
+ ref: "master",
+ commit: "${{ github.sha }}",
+ author: ${{ steps.commit.outputs.author }},
+ committer: ${{ steps.commit.outputs.committer }}
+ }
+ }' | \
+ tee payload.json | \
+ jq -C '.'
+
+ # send the webhook
+ - name: trigger build
+ id: hook
+ env:
+ OKD_BUILD_HOOK: ${{ secrets.OKD_BUILD_HOOK }}
+ run: |
+ curl \
+ --insecure \
+ --silent \
+ --show-error \
+ --header "Content-Type: application/json" \
+ --request POST \
+ --data @payload.json "$OKD_BUILD_HOOK" > curl-out
+ jq -C '.' curl-out || (cat curl-out; false)
+ echo "::set-output name=kind::$(jq '.kind' curl-out)"
+
+ # Fail if we recieved a Status response and it doesn't look good
+ - name: test http code
+ if: steps.hook.outputs.kind == 'Status'
+ run: "[ `jq '.code' curl-out` -lt 400 ]"
+
+ - name: test status
+ if: steps.hook.outputs.kind == 'Status'
+ run: "[ `jq '.status' curl-out` == 'Success' ]"
+
+ - name: test if skipped
+ if: steps.hook.outputs.kind == 'Status'
+ run: "[[ `jq '.message' curl-out` != *skipping* ]]"