-
Notifications
You must be signed in to change notification settings - Fork 26
216 lines (202 loc) · 8.55 KB
/
reusable-build-and-publish.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
name: Build the dashboard and deploy to a GCP Bucket
on:
workflow_call:
inputs:
requireApproval:
description: True if the job requires a manual approval before execution.
required: false
default: false
type: boolean
environment:
description: >
The environment on which the action should be used. For example `sepolia`.
Will be used to determine environment variables and decide which legacy
packages should be used for building.
required: true
type: string
useUpstreamBuilds:
description: True if the upstream builds should be used.
required: true
default: false
type: boolean
upstreamBuilds:
description: Upstream builds (required if `useUpstreamBuilds==true`).
required: false
type: string
dependentPackagesTag:
description: >
Tag which should be used to pull latest non-legacy `threshold-network` and
`keep-network` packages with contracts (required if
`useUpstreamBuilds==false`). For example `dapp-dev-sepolia`.
required: false
type: string
gcpBucketName:
description: The name of the bucket where the code will be deployed.
required: true
type: string
gcpBucketPath:
description: >
The path where in the bucket the code will be deployed. When you don't
want to put the code in the bucket's subfolder, set `.`. Otherwise
provide the path, without leading `./` (for example
`subfolder_1/subfolder_2`).
required: false
default: .
type: string
preview:
description: True if the code should be pushed to the preview bucket.
required: true
default: false
type: boolean
secrets:
ethUrlHttp:
description: The HTTP ETH API URL.
required: true
ethUrlWS:
description: The WebSocket ETH API URL.
required: true
gcpServiceKey:
description: JSON key for Google Cloud Platform service account.
required: true
electrumProtocol:
description: Protocol used by the Electrum server.
required: true
electrumHost:
description: Host pointing to the Electrum server.
required: true
electrumPort:
description: Port the Electrum server listens on.
required: true
sentryDsn:
description: Sentry DSN endpoint
required: true
walletConnectProjectId:
description: >
Project Id gathered from WalletConnect cloud. Required for
WalletConnect v2.
required: true
jobs:
build-and-publish:
# Use a fake ternary expression as a workaround for the issue
# https://github.com/actions/runner/issues/409.
environment: ${{ inputs.requireApproval && 'protected' || '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"
# We need this step because the `@keep-network/tbtc` which we update in
# next step has a dependency to `@summa-tx/relay-sol@2.0.2` package, which
# downloads one of its sub-dependencies via unathenticated `git://`
# protocol. That protocol is no longer supported. Thanks to this step
# `https://` is used instead of `git://`.
- name: Configure git to don't use unauthenticated protocol
shell: bash
run: git config --global url."https://".insteadOf git://
- name: Install dependencies
shell: bash
run: yarn install --ignore-scripts --frozen-lockfile
- name: Run token-dashboard post-install script
shell: bash
run: yarn run postinstall
- name: Get upstream packages versions
if: inputs.useUpstreamBuilds == true
uses: keep-network/ci/actions/upstream-builds-query@v2
id: upstream-builds-query
with:
upstream-builds: ${{ inputs.upstreamBuilds }}
query: |
threshold-contracts-version = github.com/threshold-network/solidity-contracts#version
random-beacon-contracts-version = github.com/keep-network/keep-core/random-beacon#version
# Currently we only support `environment` = `sepolia`. We provide explicit
# version of the `solidity-contracts` package, because using `sepolia` tag
# results in `expected manifest` error - probably caused by bug in Yarn:
# https://github.com/yarnpkg/yarn/issues/4731.
- name: Set packages versions
shell: bash
id: set-packages-versions
env:
TC_VERSION_MAPPING: '{"sepolia": "1.3.0-sepolia.0", "dapp-development-sepolia": "1.3.0-dapp-dev-sepolia.0"}'
run: |
if [ ${{ inputs.useUpstreamBuilds }} = 'false' ]; then
echo "threshold-contracts-version=${{ fromJson(env.TC_VERSION_MAPPING)[inputs.dependentPackagesTag] || inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "random-beacon-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
else
echo "threshold-contracts-version=${{ steps.upstream-builds-query.outputs.threshold-contracts-version }}" >> $GITHUB_OUTPUT
echo "random-beacon-contracts-version=${{ steps.upstream-builds-query.outputs.random-beacon-contracts-version }}" >> $GITHUB_OUTPUT
fi
- name: Resolve contracts
shell: bash
run: |
yarn upgrade --ignore-scripts \
@threshold-network/solidity-contracts@${{ steps.set-packages-versions.outputs.threshold-contracts-version }} \
@keep-network/keep-core@${{ inputs.environment }} \
@keep-network/keep-ecdsa@${{ inputs.environment }} \
@keep-network/tbtc@${{ inputs.environment }} \
@keep-network/random-beacon@${{ steps.set-packages-versions.outputs.random-beacon-contracts-version }}
- name: Run postinstall script
shell: bash
# `yarn upgrade` doesn't trigger the `postinstall` script.
run: yarn run postinstall
- name: Load environment variables
uses: keep-network/ci/actions/load-env-variables@v2
with:
environment: ${{ inputs.environment }}
- name: Build
if: inputs.gcpBucketPath == '.'
shell: bash
run: yarn build
env:
PUBLIC_URL: /
CHAIN_ID: ${{ env.NETWORK_ID }}
ETH_HOSTNAME_HTTP: ${{ secrets.ethUrlHttp }}
ETH_HOSTNAME_WS: ${{ secrets.ethUrlWS }}
NODE_OPTIONS: --max_old_space_size=4096
ELECTRUM_PROTOCOL: ${{ secrets.electrumProtocol }}
ELECTRUM_HOST: ${{ secrets.electrumHost }}
ELECTRUM_PORT: ${{ secrets.electrumPort }}
SENTRY_SUPPORT: true
SENTRY_DSN: ${{ secrets.sentryDsn }}
WALLET_CONNECT_PROJECT_ID: ${{ secrets.walletConnectProjectId }}
DAPP_DEVELOPMENT_TESTNET_CONTRACTS: ${{ inputs.preview == true }}
- name: Build
if: inputs.gcpBucketPath != '.'
shell: bash
run: yarn build
env:
PUBLIC_URL: /${{ inputs.gcpBucketPath }}
CHAIN_ID: ${{ env.NETWORK_ID }}
ETH_HOSTNAME_HTTP: ${{ secrets.ethUrlHttp }}
ETH_HOSTNAME_WS: ${{ secrets.ethUrlWS }}
NODE_OPTIONS: --max_old_space_size=4096
ELECTRUM_PROTOCOL: ${{ secrets.electrumProtocol }}
ELECTRUM_HOST: ${{ secrets.electrumHost }}
ELECTRUM_PORT: ${{ secrets.electrumPort }}
SENTRY_SUPPORT: true
SENTRY_DSN: ${{ secrets.sentryDsn }}
WALLET_CONNECT_PROJECT_ID: ${{ secrets.walletConnectProjectId }}
DAPP_DEVELOPMENT_TESTNET_CONTRACTS: ${{ inputs.preview == true }}
- name: Deploy to GCP
uses: thesis/gcp-storage-bucket-action@v3.1.0
with:
service-key: ${{ secrets.gcpServiceKey }}
project: ${{ env.GOOGLE_PROJECT_ID }}
bucket-name: ${{ inputs.gcpBucketName }}
bucket-path: ${{ inputs.gcpBucketPath }}
build-folder: build
set-website: ${{ inputs.preview == false }}
home-page-path: index.html
error-page-path: index.html
- name: Post preview URL to PR
if: inputs.preview == true
uses: actions/github-script@v5
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Preview uploaded to https://${{ inputs.gcpBucketName }}/${{ github.head_ref }}/index.html.'
})