-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaction.yaml
120 lines (105 loc) · 4.43 KB
/
action.yaml
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: "coopTilleuls/action-deploy-set-env"
description: "provides all variables for other steps"
inputs:
SITE_NAME:
description: "short site name for namspace/db suffix"
required: true
SECRETS_JSON:
description: "secrets as a json file"
required: true
outputs:
CLUSTER:
description: "Kubernetes cluster"
value: ${{ steps.main.outputs.CLUSTER }}
IMAGE_TAG:
description: "Docker image tag"
value: ${{ steps.main.outputs.IMAGE_TAG }}
NAMESPACE:
description: "Kubernetes namespace"
value: ${{ steps.main.outputs.NAMESPACE }}
PREFIX_NAME:
description: "release/db prefix"
value: ${{ steps.main.outputs.PREFIX_NAME }}
HELM_VALUES_ARG:
description: "helm values argument to pass to helm command"
value: ${{ steps.main.outputs.HELM_VALUES_ARG }}
DB_USER:
description: "database username"
value: ${{ steps.main.outputs.DB_USER }}
DB_NAME:
description: "database name"
value: ${{ steps.main.outputs.DB_NAME }}
PULL_REQUEST_MESSAGE:
description: "message to post in pull request after deployment"
value: ${{ steps.main.outputs.PULL_REQUEST_MESSAGE }}
VERCEL_ARGS:
description: "arguments for vercel deployment"
value: ${{ steps.main.outputs.VERCEL_ARGS }}
DUMP_SUBSTITUTIONS:
description: "json array of search/replacement to apply before inserting dump (or inverted during dump)"
value: ${{ steps.main.outputs.DUMP_SUBSTITUTIONS }}
runs:
using: "composite"
steps:
- shell: bash
id: main
run: |
set -ex
function get_input() {
local key=$1
jq -r ".$key // empty" <<EOF
${{ inputs.SECRETS_JSON }}
EOF
}
# set prefix name
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
PREFIX_NAME=pr-$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
PREFIX_NAME_UC=PR_$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH" | tr a-z A-Z)
VERCEL_PREFIX_NAME="$GITHUB_HEAD_REF"
else
PREFIX_NAME=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/_/-/g')
PREFIX_NAME_UC=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/-/_/g' | tr a-z A-Z)
VERCEL_PREFIX_NAME="$PREFIX_NAME"
fi
echo "PREFIX_NAME=$PREFIX_NAME" >> $GITHUB_OUTPUT
# set image tag
IMAGE_TAG=$(echo sha-${GITHUB_SHA::7})
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
# get cluster credentials
if [ "$PREFIX_NAME" == "main" -o "$PREFIX_NAME" == "prod" -o "$PREFIX_NAME" == "master" ]; then
CLUSTER=prod
else
CLUSTER=nonprod
fi
echo "CLUSTER=$CLUSTER" >> $GITHUB_OUTPUT
CLUSTER_UC=$(echo $CLUSTER | tr a-z A-Z)
# short site name
SITE_NAME=${{ inputs.SITE_NAME }}
# set namespace
NAMESPACE=$(echo "$CLUSTER-$SITE_NAME" | sed -e 's|/$||' -e 's|/|-|g' | tr A-Z a-z)
echo "NAMESPACE=$NAMESPACE" >> $GITHUB_OUTPUT
# set db_user and db_name
DB_USER=$(echo "$PREFIX_NAME-$SITE_NAME" | sed -e 's|/$||' -e 's|[/-]|_|g' | tr A-Z a-z)
echo "DB_USER=$DB_USER" >> $GITHUB_OUTPUT
DB_NAME=$(echo "$PREFIX_NAME-$SITE_NAME" | sed -e 's|/$||' -e 's|[/-]|_|g' | tr A-Z a-z)
echo "DB_NAME=$DB_NAME" >> $GITHUB_OUTPUT
# Set image repo/tag
# image registry
IMAGE_REPOSITORY=$(get_input IMAGE_REPOSITORY)
MAILER_DSN=$(get_input MAILER_DSN)
MAILGUN_API_KEY=$(get_input MAILGUN_API_KEY)
MAILGUN_DOMAIN=$(get_input MAILGUN_DOMAIN)
sed -i -e "s#IMAGE_TAG#$IMAGE_TAG#g" helm/chart/values*.yaml
sed -i -e "s#IMAGE_REPOSITORY#$IMAGE_REPOSITORY#g" helm/chart/values*.yaml
sed -i -e "s#PREFIX_NAME#$PREFIX_NAME#g" helm/chart/values*.yaml
sed -i -e "s#DB_USER#$DB_USER#g" helm/chart/values*.yaml
sed -i -e "s#DB_NAME#$DB_NAME#g" helm/chart/values*.yaml
sed -i -e "s#MAILER_DSN#$MAILER_DSN#g" helm/chart/values*.yaml
sed -i -e "s#MAILGUN_API_KEY#$MAILGUN_API_KEY#g" helm/chart/values*.yaml
sed -i -e "s#MAILGUN_DOMAIN#$MAILGUN_DOMAIN#g" helm/chart/values*.yaml
cat helm/chart/values*.yaml
# End of helm values
echo "HELM_VALUES_ARG=$HELM_VALUES_ARG" >> $GITHUB_OUTPUT
# Pull request message
PULL_REQUEST_MESSAGE="To access site: FIXME"
echo "PULL_REQUEST_MESSAGE=$PULL_REQUEST_MESSAGE" >> $GITHUB_OUTPUT