generated from toitware/web-gatsby-template
-
Notifications
You must be signed in to change notification settings - Fork 1
198 lines (166 loc) · 5.22 KB
/
ci.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
name: CI
on:
push:
release:
types: [published]
workflow_dispatch:
inputs:
deploy:
description: 'Deploy the website'
required: false
default: false
type: boolean
env:
TOIT_VERSION: v2.0.0-alpha.148
BUCKET: toit-web
BUCKET_PATH: docsv2.toit.io
BUILD_DIR: public
HAS_PROTOBUF: false
RUN_TESTS: true
ARTIFACT_EXTENSION: tgz
jobs:
snippets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Toit
id: setup-toit
uses: toitlang/action-setup@v1
with:
toit-version: ${{ env.TOIT_VERSION }}
- name: Check snippets
shell: bash
run: |
export TOIT_SDK=${{ steps.setup-toit.outputs.toit-install-dir }}/toit
cd tools
$TOIT_SDK/bin/toit.pkg install
./run_all.sh
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install
env:
GITHUB_NPM_TOKEN: ${{ secrets.LEON_GITHUB_NPM_PAT }}
run: |
npm config set //npm.pkg.github.com/:_authToken=$GITHUB_NPM_TOKEN
yarn install
- name: Protobuf
if: env.HAS_PROTOBUF == 'true'
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
make protobuf
- name: Lint
run: |
yarn lint
- name: Test
if: env.RUN_TESTS == 'true'
run: |
yarn test:ci
- name: Build
run: |
yarn build
- name: Generate version
id: version
shell: bash
run: |
GIT_VERSION=$(tools/gitversion)
echo $GIT_VERSION
# Replace any '/' with '-'.
VERSION=${GIT_VERSION//\//-}
echo $VERSION
echo $VERSION > VERSION
echo VERSION=$VERSION >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Prepare artifacts
run: |
tar c -zf $VERSION.$ARTIFACT_EXTENSION -C $BUILD_DIR/ .
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build
retention-days: 2
if-no-files-found: error
path: |
${{ env.VERSION }}.${{ env.ARTIFACT_EXTENSION }}
VERSION
upload:
runs-on: ubuntu-latest
needs: [ ci ]
if: |
github.event_name == 'release' ||
github.event_name == 'push' && github.ref_name == 'master' ||
github.event_name == 'push' && startsWith(github.ref_name, 'release-v')
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: build
- name: Set up env
run: |
# Just for debugging and better understanding list all files we have now.
find .
VERSION=$(cat VERSION)
ARTIFACT=$VERSION.$ARTIFACT_EXTENSION
echo BUILD_VERSION=$VERSION >> $GITHUB_ENV
echo ARTIFACT=$ARTIFACT >> $GITHUB_ENV
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.INFRASTRUCTURE_SERVICE_ACCOUNT_JSON_KEY }}
service_account: [email protected]
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
project_id: infrastructure-220307
- name: Upload to Google Cloud
run: |
echo -n $BUILD_VERSION > LATEST.tmp
gsutil cp $ARTIFACT gs://$BUCKET/$BUCKET_PATH/$BUILD_VERSION.$ARTIFACT_EXTENSION
gsutil cp LATEST.tmp gs://$BUCKET/$BUCKET_PATH/LATEST
- name: Update RELEASED in Google Cloud
if: |
github.event_name == 'release' && !github.event.release.prerelease
run: |
echo -n $BUILD_VERSION > LATEST.tmp
gsutil cp LATEST.tmp gs://$BUCKET/$BUCKET_PATH/RELEASED
gsutil cp LATEST.tmp gs://$BUCKET/$BUCKET_PATH/RELEASED.$BUILD_VERSION
deploy:
if: |
github.event.inputs.deploy == 'true' ||
github.event_name == 'release' ||
github.event_name == 'push' && github.ref_name == 'master' ||
github.event_name == 'push' && startsWith(github.ref_name, 'release-v')
# Only deploy if all tests passed.
needs: [ci]
runs-on: ubuntu-latest
steps:
# No need to checkout the project, since all we need is to download the
# build artifact from the build step.
- uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Disable Jekyll
run: |
touch build/.nojekyll
- name: Untar
run: |
cd build
tar x -zf $BUILD_VERSION.$ARTIFACT_EXTENSION
rm $BUILD_VERSION.$ARTIFACT_EXTENSION
# This seems to be the simplest way to publish to a separate branch.
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./build
# Optional. This will create a CNAME file so GitHub Pages serves it
# under this domain.
# cname: docs.toit.io