-
Notifications
You must be signed in to change notification settings - Fork 17
138 lines (119 loc) · 5.35 KB
/
publish-nightly-build.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
# This workflow builds the project, packages it up, and then copies it to Azure Blob Storage. It also copies the deploy
# template to Azure Blob Storage. It runs on push to main and also can be run manually. This is meant for development
# purposes only and exists due to our GitHub repository being private making our artifacts in-accessible from Azure
# Portal. This should be deleted or replaced with GitHub artifact releases once we make the repository public. We are
# using SAS token (shared access signature) to access to blob storage. The SAS token will expire 2022-12-31. You can
# generate a new one in Azure Portal.
name: Publish Nightly Build
on:
schedule:
# minute 0, hour 23 UTC (which is 3pm PST/4pm 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 23 * * *"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
checkForChanges:
name: Check for new changes
outputs:
hasChanged: ${{ steps.checkChange.outputs.hasChanged }}
runs-on: ubuntu-latest
steps:
# Check-out repo
- uses: actions/checkout@v3
# 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: Publish Nightly Release
needs: checkForChanges
if: needs.checkForChanges.outputs.hasChanged == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Install Node.js v20.17.x
uses: actions/setup-node@v3
with:
node-version: "20.17.x"
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
# Get datetime
- name: Get datetime for nightly release name
id: datetime
run: |
echo "datetime=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
# Retrieve version to tag and publish release with
- name: Retrieve version
id: version
run: |
clientVer=$(jq -r .version client/package.json)
echo currentversion: $clientVer
newVersion=$(echo $clientVer | grep -oP "^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)")-nightly-${{ steps.datetime.outputs.datetime }}.0
echo newversion: $newVersion
echo "newProjectVersion=$newVersion" >> $GITHUB_OUTPUT
# Increment versions in package.json
- name: Increment versions
run: node scripts/increment-version.js ${{ steps.version.outputs.newProjectVersion }}
# Update telemetry version
- name: Synchronize package version reported to telemetry
run: node scripts/sync-telemetry-package-version.js
- name: Update packageUrl in ARM templates
run: node scripts/set-arm-package-url.js Nightly/${{ steps.datetime.outputs.datetime }}
- name: Create source archive
run: zip -r sample-source.zip . -x *.git*
- name: Install client dependencies
working-directory: ./client
run: npm install
- name: Install server dependencies
working-directory: ./server
run: npm install
- name: Package project
working-directory: ./client
run: npm run package
- name: Zip distribution
working-directory: ./dist
run: zip -r sample.zip .
# Push git tags
- name: Create and push git tags
run: |
git tag ${{ steps.version.outputs.newProjectVersion }}
git push --tags
# Upload artifacts
- name: Upload Release
uses: softprops/action-gh-release@v1
with:
name: Nightly ${{ steps.datetime.outputs.datetime }}
tag_name: Nightly/${{ steps.datetime.outputs.datetime }}
files: |
./dist/sample.zip
./deploy/azuredeploy.json
./deploy/editableazuredeploy.json
./deploy/azuredeployexistingresource.json
./sample-source.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}