Repository navigation
50 lines (44 loc) · 1.88 KB
/
Copy pathclose-pull-request.yml
File metadata and controls
50 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
##
# GitHub Actions workflow to action on Pull Request closure.
#
name: Close Pull Request
on:
pull_request:
types:
- closed
jobs:
remove_lagoon_environment:
#;< VORTEX_DEV
# The template repository has no Lagoon project and no webhook token.
if: ${{ github.repository != 'drevops/vortex' }}
#;> VORTEX_DEV
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Remove environment after a PR is closed
run: |
if [ -z "${LAGOON_WEBHOOK_TOKEN}" ]; then echo "LAGOON_WEBHOOK_TOKEN secret is not set."; exit 1; fi
# Lagoon verifies the signature as GitHub webhooks do, so sign the
# exact bytes sent as the body.
signature_sha256="$(openssl dgst -sha256 -hmac "${LAGOON_WEBHOOK_TOKEN}" "$GITHUB_EVENT_PATH" | sed 's/^.* //')"
signature_sha1="$(openssl dgst -sha1 -hmac "${LAGOON_WEBHOOK_TOKEN}" "$GITHUB_EVENT_PATH" | sed 's/^.* //')"
status=0
response="$(curl \
--silent \
--show-error \
--fail-with-body \
-X POST \
--header "Content-Type: application/json" \
--header "X-GitHub-Delivery: ${RUNNER_TRACKING_ID:7}" \
--header "X-GitHub-Event: pull_request" \
--header "X-Hub-Signature-256: sha256=${signature_sha256}" \
--header "X-Hub-Signature: sha1=${signature_sha1}" \
--data-binary @"$GITHUB_EVENT_PATH" \
"${LAGOON_WEBHOOK_ENDPOINT:-https://webhook.amazeeio.cloud/}")" || status=$?
echo "${response}"
# Lagoon answers a rejected webhook with HTTP 200 and an error body.
if [ "${status}" != "0" ] || echo "${response}" | grep -q '"error"'; then exit 1; fi
env:
LAGOON_WEBHOOK_ENDPOINT: ${{ vars.LAGOON_WEBHOOK_ENDPOINT }}
LAGOON_WEBHOOK_TOKEN: ${{ secrets.LAGOON_WEBHOOK_TOKEN }}