-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (92 loc) · 4.11 KB
/
Copy pathsignal-deploy.yml
File metadata and controls
103 lines (92 loc) · 4.11 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
94
95
96
97
98
99
100
101
102
103
###############################
## Signal Auto Deploy ##
## Reusable Workflow ##
###############################
# Outputs the signal for automated deployment, as a Boolean
# Outputs the Environment Name that should be used for deployment, as a String
name: 'Signal Automated Deployment'
on:
workflow_call:
inputs:
# Required Inputs
# Optional Inputs
main_branch:
description: 'The name of the main branch, associated with the production environment'
required: true
default: 'main'
type: string
release_branch:
description: 'The name of the release branch, associated with the test/staging environment'
required: true
default: 'release'
type: string
outputs:
AUTOMATED_DEPLOY:
description: "Boolean value to signal if the automated deployment should happen"
value: ${{ jobs.check_which_git_branch_we_are_on.outputs.AUTOMATED_DEPLOY }}
ENVIRONMENT_NAME:
description: "Github Environment Name that should be used for deployment"
value: ${{ jobs.check_which_git_branch_we_are_on.outputs.ENVIRONMENT_NAME }}
jobs:
## JOB: Signal for Automated PyPI Upload ##
check_which_git_branch_we_are_on:
runs-on: ubuntu-latest
# logic below assumes github.ref is a tag, so we allow to run only on tag push
# PROD if: startsWith(github.ref, 'refs/tags/')
env:
RELEASE_BR: ${{ inputs.release_branch }}
MAIN_BR: ${{ inputs.main_branch }}
outputs:
AUTOMATED_DEPLOY: ${{ steps.set_environment_name.outputs.AUTOMATED_DEPLOY }}
ENVIRONMENT_NAME: ${{ steps.set_environment_name.outputs.ENVIRONMENT_NAME }}
steps:
# Fetch 'main' and 'release' branches
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git branch -a
- name: 'git branch --track "${{ env.RELEASE_BR }}" "origin/${{ env.RELEASE_BR }}"'
id: track_release_br
run: |
exit_code=0
git branch --track "${{ env.RELEASE_BR }}" "origin/${{ env.RELEASE_BR }}" || exit_code=$?
if [[ $exit_code -ne 0 ]]; then
echo "[WARN] Could not track '${{ env.RELEASE_BR }}' branch. Possibly origin/${{ env.RELEASE_BR }} has been already deleted"
fi
echo "TRACK_RELEASE_CODE=${exit_code}" >> $GITHUB_OUTPUT
- name: 'git branch --track "${{ env.MAIN_BR }}" "origin/${{ env.MAIN_BR }}"'
id: track_main_br
run: |
exit_code=0
git branch --track "${{ env.MAIN_BR }}" "origin/${{ env.MAIN_BR }}" || exit_code=$?
if [[ $exit_code -ne 0 ]]; then
echo "[WARN] Could not track '${{ env.MAIN_BR }}' branch!"
fi
echo "TRACK_MAIN_CODE=${exit_code}" >> $GITHUB_OUTPUT
- name: "Check if '${{ github.ref }}' tag is on '${{ env.MAIN_BR }}' branch"
if: steps.track_main_br.outputs.TRACK_MAIN_CODE == 0
uses: rickstaa/action-contains-tag@a9ff27d505ba2bf074a2ebb48b208e76d35ff308
id: main_contains_tag
with:
reference: ${{ env.MAIN_BR }}
tag: "${{ github.ref }}"
- name: "Check if '${{ github.ref }}' tag is on '${{ env.RELEASE_BR }}' branch"
if: steps.track_release_br.outputs.TRACK_RELEASE_CODE == 0
uses: rickstaa/action-contains-tag@a9ff27d505ba2bf074a2ebb48b208e76d35ff308
id: release_contains_tag
with:
reference: ${{ env.RELEASE_BR }}
tag: "${{ github.ref }}"
- name: Pick Production or Test Environment, if tag on MAIN_BR or release branch respectively
id: set_environment_name
run: |
DEPLOY=true
if [[ "${{ steps.main_contains_tag.outputs.retval }}" == "true" ]]; then
echo "ENVIRONMENT_NAME=PROD_DEPLOYMENT" >> $GITHUB_OUTPUT
elif [[ "${{ steps.release_contains_tag.outputs.retval }}" == "true" ]]; then
echo "ENVIRONMENT_NAME=TEST_DEPLOYMENT" >> $GITHUB_OUTPUT
else
echo "A tag was pushed but not on ${MAIN_BR} or ${RELEASE_BR} branch. No deployment will be done."
DEPLOY=false
fi
echo "AUTOMATED_DEPLOY=$DEPLOY" >> $GITHUB_OUTPUT