-
Notifications
You must be signed in to change notification settings - Fork 8
231 lines (202 loc) · 7.61 KB
/
build_and_release.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
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
name: Build CLI command, run tests and release packages
on:
push:
branches:
- main
- "prerelease/**"
paths-ignore:
- "cmds/proxy/**"
- ".github/workflows/on_push_proxy.yaml"
# pull_request:
# paths-ignore:
# - "cmds/proxy/**"
# - ".github/workflows/on_push_proxy.yaml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
npm:
name: Build npm package
runs-on: ubuntu-latest
if: github.repository == 'empiricaly/empirica'
# && github.event.pull_request.draft == false
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js 20.10.0
uses: actions/setup-node@v3
with:
node-version: 20.10.0
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.4
- name: "Build core package: install dependencies"
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/prerelease/')
run: npm ci
- name: "Build packages: Create Release Pull Request or Publish to npm"
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/prerelease/')
id: changesets
uses: changesets/action@v1
with:
publish: npm run release:core
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get @empirica/core package version
id: version
working-directory: ./lib/@empirica/core
run: echo "VERSION=v$(node -e "console.log(require('./package.json').version)")" >> $GITHUB_OUTPUT
outputs:
version: ${{ steps.version.outputs.VERSION }}
published: ${{ steps.changesets.outputs.published }}
go:
name: Build Go binary
runs-on: ubuntu-latest
needs: [npm]
if: github.repository == 'empiricaly/empirica' && github.event.pull_request.draft == false
steps:
- name: Checkout Repo
uses: actions/checkout@v3
# We will use the result to determine if we need to create a release or not
- name: "Build core package: Create release tag"
if: needs.npm.outputs.published == 'true'
id: create_tag
uses: jaywcjlove/create-tag-action@v1.2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ needs.npm.outputs.version }}
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.4
- name: Set GITHUB_ENV
run: |
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
echo "BUILD_SHA=$(git rev-list -1 HEAD)" >> $GITHUB_ENV
echo "BUILD_SHA_SHORT=$(git rev-parse --short=7 ${{ github.sha }})" >> $GITHUB_ENV
echo "BUILD_NUM=${{ github.run_number }}" >> $GITHUB_ENV
# If tag has been created, we assume we need to release a version
- name: Check if tag has been created
if: steps.create_tag.outputs.successful
run: |
echo "BUILD_BRANCH=`echo "main" | sed -r 's,/,-,g'`" >> $GITHUB_ENV
echo "BUILD_TAG=${{ needs.npm.outputs.version }}" >> $GITHUB_ENV
# If tag hasn't been created, create a CalVer version
- name: Use actual branch name.
if: steps.create_tag.outputs.successful != 'true'
working-directory: ./build
run: |
echo "BUILD_TAG=$(sh generate_calver.sh)" >> $GITHUB_ENV
# Otherwise use the actual branch name
- name: Use actual branch name.
if: steps.create_tag.outputs.successful != 'true'
run: |
echo "BUILD_BRANCH=`echo "${{ steps.branch-name.outputs.current_branch }}" | sed -r 's,/,-,g'`" >> $GITHUB_ENV
- name: Log build variables
run: |
echo BUILD_DATE=${{ env.BUILD_DATE }}
echo BUILD_SHA=${{ env.BUILD_SHA_SHORT }}
echo BUILD_BRANCH=${{ env.BUILD_BRANCH }}
echo BUILD_TAG=${{ env.BUILD_TAG }}
echo EMPIRICA_CORE_VERSION=${{ needs.npm.outputs.version }}
echo BUILD_NUM=${{ env.BUILD_NUM }}
- name: Cache Go build
uses: actions/cache@v3
id: build-cache
with:
path: |
/home/runner/gocache
/home/runner/gomodcache
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Create cache dirs
run: |
mkdir -p /home/runner/gocache
mkdir -p /home/runner/gomodcache
mkdir -p /home/runner/out
- name: Build Empirica server
uses: redhat-actions/buildah-build@v2
with:
image: empirica-tmp
containerfiles: ./build/Containerfile
extra-args: |
--volume /home/runner/out:/out
--volume /home/runner/gocache:/opt/app-root/src/.cache/go-build
--volume /home/runner/gomodcache:/opt/app-root/src/go/pkg/mod
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_SHA=${{ env.BUILD_SHA_SHORT }}
BUILD_BRANCH=${{ env.BUILD_BRANCH }}
BUILD_TAG=${{ env.BUILD_TAG }}
BUILD_NUM=${{ env.BUILD_NUM }}
- name: Smoke test
run: /home/runner/out/empirica-linux-amd64 --help
- name: Upload binaries to S3
uses: ./.github/actions/upload-empirica-cli
with:
bucket: empirica
root: empirica
path: /home/runner/out
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
awsEndpoint: https://f120117e0fd797d29319953881b7634c.r2.cloudflarestorage.com
awsSignatureVersion: v4
- name: Log in to the Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: redhat-actions/buildah-build@v2
id: build-image
with:
containerfiles: ./build/Containerfile.empirica
# context: /home/runner/out
context: ../../../out
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
latest
sha-${{ env.BUILD_SHA_SHORT }}
build-${{ env.BUILD_TAG }}
branch-${{ env.BUILD_BRANCH }}
# We push, even if later tests do not pass, so that we can debug
- name: Push to quay.io
id: push-to-registry
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.REGISTRY }}
docs:
name: Publish api docs
runs-on: ubuntu-latest
needs: [npm, go]
if: needs.npm.outputs.published == 'true'
steps:
- name: Checkout empirica repo
uses: actions/checkout@v3
with:
path: empirica
- name: Checkout empirica docs v2 repo
uses: actions/checkout@v3
with:
repository: empiricaly/docsv2
token: ${{ secrets.EMPIRICA_DOCS_PAT }}
path: docsv2
- name: Publish API docs
run: |
cd empirica/lib/@empirica/core
npm i
./docs.sh
cp -r docs ../../../../docsv2/api
cp README.md ../../../../docsv2/api/
cd ../../../../docsv2
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "update api docs ${{ needs.npm.outputs.version }}"
git push