-
Notifications
You must be signed in to change notification settings - Fork 3
150 lines (127 loc) · 6.14 KB
/
deployment.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Build and Deploy to Netlify
on:
release:
types: [published]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
environment:
name: Production
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Read old BUILD_VERSION from config.json
run: |
OLD_VERSION=$(jq -r '.BUILD_VERSION' src/config/config.json)
echo "Github ref: $GITHUB_REF"
echo "Old BUILD_VERSION: $OLD_VERSION"
- name: Update IS_PROD, IS_CANARY, and IS_LOCAL based on tag reference
run: |
CONFIG_PATH="src/config/config.json"
# Read the config.json file
CONFIG=$(<"$CONFIG_PATH")
# Set initial values for flags
IS_PROD=$(jq -r '.IS_PROD' <<< "$CONFIG")
IS_LOCAL=$(jq -r '.IS_LOCAL' <<< "$CONFIG")
IS_CANARY=$(jq -r '.IS_CANARY' <<< "$CONFIG")
echo "Current IS_PROD: $IS_PROD"
echo "Current IS_LOCAL: $IS_LOCAL"
echo "Current IS_CANARY: $IS_CANARY"
git config --global user.email "[email protected]"
git config --global user.name "Version Update Bot"
# Check if the tag contains 'master', 'main', or 'production'
if [[ "$GITHUB_REF" == *"master"* || "$GITHUB_REF" == *"main"* || "$GITHUB_REF" == *"production"* ]]; then
echo "Setting IS_PROD to true"
UPDATED_CONFIG=$(echo "$CONFIG" | jq '.IS_PROD = true')
# Check if the tag contains 'canary'
elif [[ "$GITHUB_REF" == *"canary"* ]]; then
echo "Setting IS_CANARY to true"
UPDATED_CONFIG=$(echo "$CONFIG" | jq '.IS_CANARY = true')
# Check if the tag contains 'dev' or 'development'
elif [[ "$GITHUB_REF" == *"dev"* || "$GITHUB_REF" == *"development"* ]]; then
echo "Setting IS_PROD, IS_LOCAL, and IS_CANARY to false"
UPDATED_CONFIG=$(echo "$CONFIG" | jq '.IS_PROD = false | .IS_LOCAL = false | .IS_CANARY = false')
else
echo "No matching tag found, keeping flags unchanged"
UPDATED_CONFIG="$CONFIG"
fi
# Save the updated config.json file
echo "$UPDATED_CONFIG" > "$CONFIG_PATH"
# Check if there are any changes before committing
if [[ $(git status --porcelain) ]]; then
git add "$CONFIG_PATH"
git commit -m "Update environment flags based on tag reference"
git push --force origin HEAD:$GITHUB_REF
else
echo "No changes to commit"
fi
- name: Set Prod/Canary Environment Variables 🚀
if: startsWith(github.ref, 'refs/tags/master') || startsWith(github.ref, 'refs/tags/canary')
# if: contains(github.ref, 'master') || contains(github.ref, 'prod') || contains(github.ref, 'production') || contains(github.ref, 'canary')
run: |
echo "Setting prod branch secrets..."
echo "REACT_APP_TINY_MCE_KEY=${{ secrets.REACT_APP_TINY_MCE_KEY }}" >> $GITHUB_ENV
echo "REACT_APP_PROD_FIREBASE_API_KEY=${{ secrets.REACT_APP_PROD_FIREBASE_API_KEY }}" >> $GITHUB_ENV
- name: Set Dev Environment Variables 🚀
# if: startsWith(github.ref, 'refs/tags/development')
if: contains(github.ref, 'dev') || contains(github.ref, 'development')
run: |
echo "Setting Development branch secrets..."
echo "Using repository secrets for $BRANCH branch..."
echo "REACT_APP_TINY_MCE_KEY=${{ secrets.REACT_APP_TINY_MCE_KEY }}" >> $GITHUB_ENV
echo "REACT_APP_LOCAL_FIREBASE_API_KEY=${{ secrets.REACT_APP_LOCAL_FIREBASE_API_KEY }}" >> $GITHUB_ENV
- name: Install dependencies
run: |
npm i --legacy-peer-deps
- name: Build App 🏗
run: |
make build
- name: Deploying to Prod 🚀
if: contains(github.ref, 'master') || contains(github.ref, 'prod') || contains(github.ref, 'production')
uses: data-intuitive/netlify-deploy-site@v1
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: 'build'
site: ${{ secrets.NETLIFY_PROD_SITE_ID }}
prod: true
message: 'Deploying ${{ github.ref }}'
- name: Deploying to Canary 🚀
if: contains(github.ref, 'canary')
uses: data-intuitive/netlify-deploy-site@v1
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: 'build'
site: ${{ secrets.NETLIFY_CANARY_SITE_ID }}
prod: true
message: 'Deploying ${{ github.ref }}'
- name: Deploying to Dev 🚀
if: contains(github.ref, 'dev') || contains(github.ref, 'development')
uses: data-intuitive/netlify-deploy-site@v1
with:
auth: ${{ secrets.NETLIFY_AUTH_TOKEN }}
dir: 'build'
site: ${{ secrets.NETLIFY_DEV_SITE_ID }}
prod: true
message: 'Deploying ${{ github.ref }}'
- name: Report status to Slack
if: always()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
BRANCH_NAME=$(echo $GITHUB_REF | awk -F'/' '{print $3}')
BUILD_VERSION=$(jq -r '.BUILD_VERSION' < src/config/config.json)
MESSAGE="Workflow in $BRANCH_NAME with build version : $BUILD_VERSION has completed with status: *${{ job.status }}*"
STATUS_EMOJI=":white_check_mark:" # Use appropriate emoji for success status
if [[ "${{ job.status }}" != "success" ]]; then
STATUS_EMOJI=":x:" # Use appropriate emoji for failure status
fi
MESSAGE="User Portal deployment workflow in $BRANCH_NAME with build number $BUILD_VERSION has completed with status: $STATUS_EMOJI ${{ job.status }}"
PAYLOAD="{\"text\": \"$MESSAGE\"}"
curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL