-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
93 lines (80 loc) · 3.4 KB
/
Copy pathaction.yml
File metadata and controls
93 lines (80 loc) · 3.4 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: "Shipyrd Deploy Notification"
description: "Notify Shipyrd of deploy lifecycle events from your GitHub Actions workflow."
author: "Shipyrd"
branding:
icon: "send"
color: "blue"
inputs:
api-token:
description: "Your Shipyrd API token (from Application Settings). Store this as a GitHub Actions secret."
required: true
shipyrd-url:
description: "Base URL of your Shipyrd instance. Override if self-hosted."
required: false
default: "https://hooks.shipyrd.io"
status:
description: "Deploy lifecycle status: 'pre-deploy', 'post-deploy', or 'failed'."
required: false
default: "post-deploy"
service:
description: "The service name to include in the service_version field (e.g. my-app). Optional — the application is identified by the API token."
required: false
default: ""
destination:
description: "The deploy destination (e.g. production, staging)."
required: false
default: "production"
performer:
description: "The person or identity performing the deploy."
required: false
default: "${{ github.actor }}"
version:
description: "The git SHA being deployed."
required: false
default: "${{ github.sha }}"
commit-message:
description: "The commit message for this deploy."
required: false
default: "${{ github.event.head_commit.message }}"
runs:
using: "composite"
steps:
- name: Notify Shipyrd
shell: bash
env:
SHIPYRD_TOKEN: ${{ inputs.api-token }}
SHIPYRD_URL: ${{ inputs.shipyrd-url }}
DEPLOY_STATUS: ${{ inputs.status }}
DEPLOY_SERVICE: ${{ inputs.service }}
DEPLOY_DESTINATION: ${{ inputs.destination }}
DEPLOY_PERFORMER: ${{ inputs.performer }}
DEPLOY_VERSION: ${{ inputs.version }}
DEPLOY_COMMIT_MESSAGE: ${{ inputs.commit-message || env.COMMIT_MESSAGE }}
run: |
RECORDED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
SERVICE_VERSION="${DEPLOY_SERVICE:+${DEPLOY_SERVICE}@}${DEPLOY_VERSION}"
PAYLOAD=$(jq -n \
--arg status "$DEPLOY_STATUS" \
--arg performer "$DEPLOY_PERFORMER" \
--arg version "$DEPLOY_VERSION" \
--arg commit_message "$DEPLOY_COMMIT_MESSAGE" \
--arg service_version "$SERVICE_VERSION" \
--arg destination "$DEPLOY_DESTINATION" \
--arg recorded_at "$RECORDED_AT" \
'{deploy: {status: $status, performer: $performer, version: $version, commit_message: $commit_message, service_version: $service_version, destination: $destination, command: "deploy", recorded_at: $recorded_at}}')
HTTP_STATUS=$(curl -s -o /tmp/shipyrd_response.json -w "%{http_code}" \
-X POST "${SHIPYRD_URL}/deploys.json" \
-H "Authorization: Bearer ${SHIPYRD_TOKEN}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
if [ "$HTTP_STATUS" -eq 201 ]; then
echo "Shipyrd notified (${DEPLOY_STATUS} for ${SERVICE_VERSION} → ${DEPLOY_DESTINATION})"
elif [ "$HTTP_STATUS" -eq 401 ]; then
echo "::error::Shipyrd authentication failed. Check that your api-token secret is set correctly."
exit 1
elif [ "$HTTP_STATUS" -eq 422 ]; then
echo "::error::Shipyrd rejected the notification: $(cat /tmp/shipyrd_response.json)"
exit 1
else
echo "::warning::Shipyrd returned unexpected status ${HTTP_STATUS}: $(cat /tmp/shipyrd_response.json)"
fi