-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
54 lines (48 loc) · 1.97 KB
/
action.yml
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
name: 'Set ENVIRONMENT env var'
description: 'Set ENVIRONMENT and other variables'
author: 'gbh-tech'
branding:
icon: 'info'
color: 'gray-dark'
outputs:
environment:
description: 'Target environment to use'
value: ${{ steps.set-environment.outputs.environment }}
runs:
using: "composite"
steps:
- name: Determine current environment using the current git ref
shell: bash -leo pipefail {0}
id: set-environment
run: |
set_env() { echo "$1" >> $GITHUB_ENV; }
set_output() { echo "$1" >> $GITHUB_OUTPUT; }
echo "Printing current environment variables for debugging purposes..."
env | grep GITHUB_
DEV_EVENTS=(push pull_request workflow_dispatch)
DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
CURRENT_REF=${GITHUB_REF##*/}
echo "Identified default branch : ${DEFAULT_BRANCH}"
echo "Current git reference : ${CURRENT_REF}"
if [[ "$CURRENT_REF" =~ ^v([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})$ ]]; then
set_env "ENVIRONMENT=production"
set_output "environment=production"
echo "ENVIRONMENT set to 'production'."
elif [[ "$CURRENT_REF" =~ ^v([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})(-uat.[0-9]{1,2})$ ]]; then
set_env "ENVIRONMENT=uat"
set_output "environment=uat"
echo "ENVIRONMENT set to 'uat'."
elif [[ "$CURRENT_REF" =~ "$DEFAULT_BRANCH" ]]; then
set_env "ENVIRONMENT=stage"
set_output "environment=stage"
echo "ENVIRONMENT set to 'stage'."
elif [[ "${DEV_EVENTS[*]}" =~ "$GITHUB_EVENT_NAME" ]]; then
set_env "ENVIRONMENT=stage"
set_output "environment=stage"
echo "ENVIRONMENT set to 'stage'."
else
echo "Error:"
echo "The tag created for this deployment does not match defined conventions."
echo "Check the README's 'Releases and deployments' section for more details."
exit 1
fi