-
Notifications
You must be signed in to change notification settings - Fork 73
211 lines (176 loc) · 8.5 KB
/
nightly-cd.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
name: Nightly alpha package release
on:
schedule:
# minute 0, hour 0 UTC (which is 6pm PST/5pm PDT), any day of month, any month, any day of the week
# if we want to support only Mon - Fri we need to change the check how we look for new changes. Currently we
# check for any new changes in the last 24 hours regardless of day)
- cron: '0 0 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# cancel workflow when a newer version of the workflow is triggered on the same github ref
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
checkForChanges:
name: Check for new changes
outputs:
hasChanged: ${{ steps.checkChange.outputs.hasChanged }}
runs-on: ${{ vars.RUNS_ON }}
permissions: read-all
steps:
# Check-out repo
- uses: actions/checkout@v4
# Check if any changes have been pushed to main since last release
- name: Check latest commit age
id: checkChange
# Here we query the github rest api for the commits, use jq (json parser) to grab the first commit and put contents into $HOME/commit.json
# Note: we ignore commits made by the bot account that commits the auto version bump changes.
# Then get the timestamp date for the first commit and check if it was over a day old.
run: |
curl -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -sL https://api.github.com/repos/${{ github.repository }}/commits | jq -r '[.[] | select(.author.login != "github-action-bot")][0]' > $HOME/commit.json
commitdate=$(jq -r '.commit.author.date' $HOME/commit.json)
commiturl=$(jq -r '.url' $HOME/commit.json)
echo Last commit: $commiturl
echo Last commit date \(UTC\): $commitdate
timestamp=$(date --utc -d "$commitdate" +%s)
echo Commit timestamp: $timestamp
currentTimestamp=$(date --utc +%s)
echo Current timestamp: $currentTimestamp
days=$(( ($currentTimestamp - $timestamp ) / 86400 ))
echo Days since last commit: $days
if [ $days = "0" ]; then
echo "hasChanged=true" >> $GITHUB_OUTPUT
else
echo "hasChanged=false" >> $GITHUB_OUTPUT
fi
release:
name: Create alpha releases
needs: checkForChanges
environment:
name: npm-alpha
if: needs.checkForChanges.outputs.hasChanged == 'true'
runs-on: ${{ vars.RUNS_ON }}
permissions:
contents: write
id-token: write
steps:
# Check-out repo
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Ensure node version is great enough
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
# Try get node_modules from cache
- name: Restore node_modules from cache
uses: actions/cache@v4
with:
path: common/temp/pnpm-store
key: ${{ runner.os }}-${{ hashFiles('common/config/rush/pnpm-lock.yaml') }}
# Install dependencies
- name: Install rush
run: npm install -g @microsoft/rush@$(jq -r '.rushVersion' "rush.json")
- name: Install dependencies
run: rush install --max-install-attempts 3
# Get datetime
- name: Get datetime for alpha release name
id: datetime
run: |
echo "datetime=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
# Bump alpha package versions
- name: Bump alpha package versions
run: node common/scripts/bump-alpha-versions.js ${{ steps.datetime.outputs.datetime }}
- name: Synchronize package version reported to telemetry
run: node common/scripts/sync-telemetry-package-version
# Important to check version consistency again after bumping versions.
- name: Ensure all package versions are consistent
run: rush ensure-consistent-versions
# Alpha version run latest
- name: Force build flavor to `beta`
run: node ./common/scripts/force-build-flavor.mjs beta
# Build packages
- name: Build @azure/communication-react package
run: rush build -t @azure/communication-react
# Test Packages
- name: Test @azure/communication-react package
run: rush test -t @azure/communication-react
# Retrieve new version to tag and publish release with
- name: Retrieve new version from package.json
id: version
run: |
ver=$(jq -r .version packages/communication-react/package.json)
echo version: $ver
echo "version=$ver" >> $GITHUB_OUTPUT
# Clean package.json
- name: Remove devDependencies and beachball from package.json
run: node ../../common/scripts/prepare-package-json.js
working-directory: ./packages/communication-react
# Publish package
- name: Package alpha packages for release
run: npm pack
working-directory: ./packages/communication-react
# Login via OIDC to permit uploading to azure blob store
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.NPM_DEPLOY_AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.NPM_DEPLOY_AZURE_TENANT_ID }}
subscription-id: ${{ secrets.NPM_DEPLOY_AZURE_SUBSCRIPTION_ID }}
# Deploy npm package - this is done by uploading to Azure's SDK blob storage then triggering their partner release pipeline.
# More info: https://dev.azure.com/azure-sdk/internal/_wiki/wikis/internal.wiki/1/Partner-Release-Pipeline
- name: Upload tarball to blob storage
run: az storage blob upload -f "packages/communication-react/release/azure-communication-react-${{ steps.version.outputs.version }}.tgz" -c "drops/azure-communication-services/react/npm/${{ steps.version.outputs.version }}" --account-name azuresdkpartnerdrops --auth-mode login
- name: Trigger alpha package release pipeline
run: az pipelines run --name 'js - partner-release' --org 'https://dev.azure.com/azure-sdk' --project 'internal' --parameters BlobPath=azure-communication-services/react/npm/${{ steps.version.outputs.version }} Tag=dev
# Push git tags
- name: Create and push git tags
run: |
git tag ${{ steps.version.outputs.version }}
git push --tags
- name: Check if npm package published successfully
run: |
POLL_INTERVAL_SEC=60 # 60 seconds
TIMEOUT_TIME_SEC=3600 # 60 minutes
GET_REQUEST_TIMEOUT_SEC=5
PACKAGE_NAME="@azure/communication-react"
VERSION="${{ steps.version.outputs.version }}"
start_time=$(date +%s)
while (( $(date +%s) - $start_time < $TIMEOUT_TIME_SEC )); do
response=$(curl --max-time $GET_REQUEST_TIMEOUT_SEC -s -o /dev/null -w "%{http_code}" https://registry.npmjs.org/$PACKAGE_NAME/$VERSION)
echo "Pinging: https://registry.npmjs.org/$PACKAGE_NAME/$VERSION"
echo "responseCode: $response"
if [ $response -eq 200 ]; then
echo "Successfully found npm package"
exit 0
fi
echo "Sleeping for a bit..."
sleep $POLL_INTERVAL_SEC
done
echo "Failed to find package on the npm registry"
exit 1
check_failure:
runs-on: ${{ vars.RUNS_ON }}
permissions:
issues: write
needs: release
if: failure()
name: Create GitHub issue on failure
steps:
# Failure of this action indicates a problem with our infrastructure.
# Always file a GitHub issue to alert the OCE of the problem.
- name: Create GitHub issue
id: create-issue
run: |
# check for an issue that is already open
curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/search/issues?q=org:Azure+repo:communication-ui-library+label:NIGHTLY_CD_FAILURE+state:open > $HOME/open_issues.json
issue_count=$(jq -r '.total_count' $HOME/open_issues.json)
if [ $issue_count -gt 0 ]; then
echo "No need to create new issue, one already exists"
else
curl -X POST -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/Azure/communication-ui-library/issues -d '{"title":"Nightly workflow to release alpha package failed", "body": "Please investigate: https://github.com/Azure/communication-ui-library/actions/runs/${{ github.run_id }}", "labels":["NIGHTLY_CD_FAILURE", "status:triage"]}'
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}