Skip to content

Code cleanup

Code cleanup #2

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
# Currently the action only supports `environment` = `goerli`.
environment:
description: >
The environment on which the action should be used. For example `goerli`.
Will be used to deterine 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-goerli`.
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/[email protected]` 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 --frozen-lockfile
- 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
ecdsa-contracts-version = github.com/keep-network/keep-core/ecdsa#version
tbtc-v2-contracts-version = github.com/keep-network/tbtc-v2#version
tbtc-v2-ts-version = github.com/keep-network/tbtc-v2.ts#version
- name: Set packages versions
shell: bash
id: set-packages-versions
run: |
if [ ${{ inputs.useUpstreamBuilds }} = 'false' ]; then
echo "threshold-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "random-beacon-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "ecdsa-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-contracts-version=${{ inputs.dependentPackagesTag }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-ts-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
echo "ecdsa-contracts-version=${{ steps.upstream-builds-query.outputs.ecdsa-contracts-version }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-contracts-version=${{ steps.upstream-builds-query.outputs.tbtc-v2-contracts-version }}" >> $GITHUB_OUTPUT
echo "tbtc-v2-ts-version=${{ steps.upstream-builds-query.outputs.tbtc-v2-ts-version }}" >> $GITHUB_OUTPUT
fi
# Currently we only support `environment` = `goerli`. We provide explicit
# version of the `keep-core` package, because using `goerli` tag results
# in `expected manifest` error - probably caused by bug in Yarn:
# https://github.com/yarnpkg/yarn/issues/4731.
- name: Resolve contracts
shell: bash
run: |
yarn upgrade \
@threshold-network/solidity-contracts@${{ steps.set-packages-versions.outputs.threshold-contracts-version }} \
@keep-network/[email protected] \
@keep-network/keep-ecdsa@${{ inputs.environment }} \
@keep-network/tbtc@${{ inputs.environment }} \
@keep-network/coverage-pools@${{ inputs.environment }} \
@keep-network/ecdsa@${{ steps.set-packages-versions.outputs.ecdsa-contracts-version }} \
@keep-network/random-beacon@${{ steps.set-packages-versions.outputs.random-beacon-contracts-version }} \
@keep-network/tbtc-v2@${{ steps.set-packages-versions.outputs.tbtc-v2-contracts-version }} \
# TODO: Revert this line when SDK 2.0.0 migration is completed.
@keep-network/[email protected]

Check failure on line 156 in .github/workflows/reusable-build-and-publish.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/reusable-build-and-publish.yml

Invalid workflow file

You have an error in your yaml syntax on line 156
- 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 }}
- 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 }}
- name: Deploy to GCP
uses: thesis/[email protected]
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.'
})