-
Notifications
You must be signed in to change notification settings - Fork 26
266 lines (226 loc) · 9.84 KB
/
release.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
name: Release
on:
push:
branches:
- master
paths:
- 'apps/**'
env:
THIRD_PARTY_GIT_AUTHOR_EMAIL: opensource+bot@newrelic.com
THIRD_PARTY_GIT_AUTHOR_NAME: nr-opensource-bot
jobs:
checkout-and-build-master:
runs-on: ubuntu-latest
steps:
# Checkout PR branch and all history (not just last commit), so we can perform `git diff` below
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
# Checkout submodules
# Note: Uses 8 jobs for checking out submodules quicker
- name: Checkout submodules
shell: bash
run: |
# If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
#git config --global url."https://github.com/".insteadOf "git@github.com:"
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --depth=1 --recursive --jobs 8
# Get Submodule_name using Git Diff
- name: Get/Set SUBMODULE_NAME
run: |
git diff --submodule=log --diff-filter=AM ${{ github.event.before }} ${{ github.event.after }}
SUB_NAME=$(git diff --submodule=log --diff-filter=AM ${{ github.event.before }} ${{ github.event.after }} | awk '{for (I=1;I<=NF;I++) if ($I == "Submodule") {print $(I+1)};}')
if [ -z "$SUB_NAME" ]; then
echo "Error: Could not determine submodule name"
exit 1
else
echo "SUBMODULE_NAME=$SUB_NAME" >> $GITHUB_ENV
fi
- name: Check SUBMODULE_NAME was set
if: env.SUBMODULE_NAME != ''
run: |
echo SUBMODULE_NAME: ${{ env.SUBMODULE_NAME }}
# Upload SUBMODULE_NAME as artifact to be used in other jobs
- name: Create submodule_name.txt artifact
if: env.SUBMODULE_NAME != ''
run: |
echo ${{ env.SUBMODULE_NAME }} > submodule_name.txt
- name: Upload SUBMODULE_NAME artifact
uses: actions/upload-artifact@v1
with:
name: submodule_name
path: ./submodule_name.txt
- name: Setup node
if: env.SUBMODULE_NAME != ''
uses: actions/setup-node@v1
with:
node-version: 16
- name: Install Dependencies
if: env.SUBMODULE_NAME != ''
working-directory: ./${{ env.SUBMODULE_NAME }}
run: npm install
- name: Install NR1 CLI
if: env.SUBMODULE_NAME != ''
run: curl -s https://cli.nr-ext.net/installer.sh | sudo bash
- name: NR1 Nerdpack Build
if: env.SUBMODULE_NAME != ''
working-directory: ./${{ env.SUBMODULE_NAME }}
run: nr1 nerdpack:build
validate-catalog-uuid-and-publish:
name: validate-catalog-uuid-and-publish
needs: checkout-and-build-master
env:
MESSAGE: ${{ github.event.head_commit.message }}
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
# Checkout submodules
# Note: Uses 8 jobs for checking out submodules quicker
- name: Checkout submodules
shell: bash
run: |
# If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
#git config --global url."https://github.com/".insteadOf "git@github.com:"
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --depth=1 --recursive --jobs 8
- name: Download submodule_name artifact
uses: actions/download-artifact@v1
with:
name: submodule_name
- name: Set SUBMODULE_NAME env var
run: |
SUB_NAME=$(cat submodule_name/submodule_name.txt)
if [ -z "$SUB_NAME" ]; then
echo "Error: Could not determine submodule name from artifact"
exit 1
else
echo "SUBMODULE_NAME=$SUB_NAME" >> $GITHUB_ENV
echo SUBMODULE_NAME: $SUB_NAME
fi
# Install NR1 CLI - The map-global-uuid action needs the nr1 cli executable
- name: Install NR1 CLI
if: env.SUBMODULE_NAME != ''
run: |
curl -s https://cli.nr-ext.net/installer.sh | sudo bash
nr1 profiles:add --name nr1-apps-us --api-key ${{ secrets.NR1_APPS_KEY_US }} --region us
- name: Setup node
if: env.SUBMODULE_NAME != ''
uses: actions/setup-node@v1
with:
node-version: 16
- name: compile map-global-uuid
if: env.SUBMODULE_NAME != ''
run: |
cd ./.github/actions/map-global-uuid
npm install
npm run build && npm run pack
- name: map-global-uuid
if: env.SUBMODULE_NAME != ''
id: uuid
uses: ./.github/actions/map-global-uuid
with:
# Array describing the files
submodule-name: ${{ env.SUBMODULE_NAME }}
# If there's output from the previous Action, commit the globals.json back to master
- name: Check and Commit globals.json
if: steps.uuid.outputs.globals-updated == 'true'
run: |
git config user.email "${{ env.THIRD_PARTY_GIT_AUTHOR_EMAIL }}"
git config user.name "${{ env.THIRD_PARTY_GIT_AUTHOR_NAME }}"
echo "globals.json was changed -- committing"
git commit globals.json -m "chore: Add new UUID for submodule: ${{ env.SUBMODULE_NAME }}"
- name: Update Version File
if: env.SUBMODULE_NAME != ''
id: versions
run: |
NERDPACK=${{ env.SUBMODULE_NAME }} # need to strip off the "apps/" portion of the submodule_name
SUBMODULE_VERSION=$(node -p "require('./${{ env.SUBMODULE_NAME }}/package.json').version")
CURRENT_VERSION=$(node -p "require('./versions.json')['${NERDPACK:5}']")
if [[ $SUBMODULE_VERSION != $CURRENT_VERSION ]]; then
npm install -g json
echo "Updating versions.json"
json -I -f versions.json -e "this['${NERDPACK:5}']='$SUBMODULE_VERSION'"
cat versions.json
echo "Versions.json updated -- committing"
git config user.email "${{ env.THIRD_PARTY_GIT_AUTHOR_EMAIL }}"
git config user.name "${{ env.THIRD_PARTY_GIT_AUTHOR_NAME }}"
git commit versions.json -m "chore: Updated version.json for submodule: ${{ env.SUBMODULE_NAME }}"
echo ::set-output name=versions_updated::true
else
echo "${{ env.SUBMODULE_NAME }} - Version not updated."
fi
- name: Push Commit
if: steps.uuid.outputs.globals-updated == 'true' || steps.versions.outputs.versions_updated == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Nerdpack
if: env.SUBMODULE_NAME != ''
env:
NR1_APPS_KEY_EU: ${{ secrets.NR1_APPS_KEY_EU }}
NR1_APPS_KEY_STAGING: ${{ secrets.NR1_APPS_KEY_STAGING }}
NR1_REGION_EU: eu
NR1_REGION_STAGING: staging
run: |
cd ${{ env.SUBMODULE_NAME }}
npm install
# US region was added previously when we installed the CLI, now add the other 2 profiles
nr1 profiles:add --name nr1-apps-staging --api-key "$NR1_APPS_KEY_STAGING" --region "$NR1_REGION_STAGING"
nr1 profiles:add --name nr1-apps-eu --api-key "$NR1_APPS_KEY_EU" --region "$NR1_REGION_EU"
# Set nr1-apps-us as current profile
nr1 profiles:default --name=nr1-apps-us
nr1 profiles:list
# Don't execute these commands until we're ready to validate they work
# Publish to Prod Artifact Registry
if [[ $MESSAGE != *"[skip publish]"* ]]; then
echo "publishing nerdpack..."
nr1 nerdpack:publish --profile=nr1-apps-us --verbose #(only if necessary)
else
echo "skipping publish"
fi
# submit catalog for US
echo "Submitting catalog to nr1-apps-us..."
nr1 catalog:submit
echo "Catalog submitted [nr1-apps-us]"
# Attempt to update the EU tag - retry logic implemented because sometimes it is not ready yet
# Set the maximum number of attempts
max_attempts=30
# Counter for the attempts
attempt=1
while [ $attempt -le $max_attempts ]; do
# Run the command and capture its output
output=$(nr1 nerdpack:tag --profile=nr1-apps-eu 2>&1 || true)
# Check if the output contains the keyword "Error"
if [[ "$output" == *"Error"* ]]; then
# The command failed
echo "Not ready, retrying in 10s (Attempt $attempt/$max_attempts)"
sleep 10
((attempt++))
else
# The command succeeded, exit the loop
break
fi
done
# Check if all attempts failed
if [ $attempt -gt $max_attempts ]; then
echo "EU tagging failed after $max_attempts attempts"
exit 1
fi
echo "EU tagging succeeded after $attempt attempts"
# submit catalog for EU
nr1 profiles:default --name=nr1-apps-eu
echo "Submitting catalog to nr1-apps-eu..."
nr1 catalog:submit
echo "Catalog submitted [nr1-apps-eu]"
# submit catalog for STAGING
# nr1 profiles:default --name=nr1-apps-staging
# echo "Submitting catalog to nr1-apps-staging..."
# nr1 catalog:submit
# echo "Catalog submitted [nr1-apps-staging]"