Skip to content

Commit

Permalink
Merge pull request #160 from threshold-network/fix-build-and-deploy-t…
Browse files Browse the repository at this point in the history
…o-bucket-action

Specify `bucket-path` when `github.head_ref` is not set

In the workflow we're executing the `thesis/gcp-storage-bucket-action@v3.1.0`
action. One of its inputs is `bucket-path`, which is an optional
input and is used to configure bucket path.

If in the workflow step executing the action we don't use the
`bucket-path` property, the action will set its `bucket-path` input to
the default value which is `.`. This is the value that we want to use
when workflow is triggered manually or by merge to main.
Previously we thought that setting the action to use
`bucket-name: ${{ github.head_ref }}` property would do the trick of
using `.` for `workflow_dispatch` and `push` events and using
`head_ref` for `pull_request` events (because we thougt the default
value will be used when `bucket-name: ` (without a value) is used in
the action. But this turned out to not be truth. When we use
`bucket-name: ` the behavior is different than when we don't provide the
`bucket-name` property at all. In the first case we don't see the
`bucket-name` property in the runner's log, in the second case we see
the property populated with the default `.` value.
Not having `bucket-name` property in the runner results in wrong
behavior of the action (order of the inputs gets messed up and the
address of bucket gets resolved to gs://<BUCKETNAME>/<BUILDFOLDER>".

As a solution we add a `set-bucket-path` step which creates an output
which value is either `.` or `github.head_ref`, depending if the
latter is configured. We then use this output as value of `bucket-path`
parameter of action `thesis/gcp-storage-bucket-action@v3.1.0`.

Read more about how runner handles empty values here:
actions/runner#924.
  • Loading branch information
nkuba committed Aug 18, 2022
2 parents c222b3d + 74f0aa3 commit 1a089e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions .github/actions/build-and-deploy-to-bucket/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ inputs:
description: JSON key for Google Cloud Platform service account.
required: true
gcpBucketName:
description: The name of the bucket where code wil be deployed.
description: The name of the bucket where the code will be deployed.
required: true
gcpBucketPath:
description: >
The path where in the bucket the code will be deployed. When you don't 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: .
preview:
description: True if the code should be pushed to the preview bucket.
required: true
Expand Down Expand Up @@ -106,13 +113,21 @@ runs:
environment: ${{ inputs.environment }}

- name: Build
if: inputs.gcpBucketPath == '.'
shell: bash
run: yarn build
env:
PUBLIC_URL: /
CHAIN_ID: ${{ env.NETWORK_ID }}
ETH_HOSTNAME_HTTP: ${{ inputs.ethUrlHttp }}
ETH_HOSTNAME_WS: ${{ inputs.ethUrlWS }}

- name: Build
if: inputs.gcpBucketPath != '.'
shell: bash
run: yarn build
env:
# `head_ref` variable property is only available when the event that
# triggers a workflow run is either pull_request or pull_request_target.
# For `workflow_dispatch` and `push`, the `PUBLIC_URL` will resolve to `/`.`
PUBLIC_URL: /${{ github.head_ref }}
PUBLIC_URL: /${{ inputs.gcpBucketPath }}
CHAIN_ID: ${{ env.NETWORK_ID }}
ETH_HOSTNAME_HTTP: ${{ inputs.ethUrlHttp }}
ETH_HOSTNAME_WS: ${{ inputs.ethUrlWS }}
Expand All @@ -123,7 +138,7 @@ runs:
service-key: ${{ inputs.gcpServiceKey }}
project: ${{ env.GOOGLE_PROJECT_ID }}
bucket-name: ${{ inputs.gcpBucketName }}
bucket-path: ${{ github.head_ref }}
bucket-path: ${{ inputs.gcpBucketPath }}
build-folder: build
set-website: ${{ inputs.preview == 'false' }}
home-page-path: index.html
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dashboard-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ jobs:
dependentPackagesTag: goerli
gcpServiceKey: ${{ secrets.KEEP_TEST_CI_UPLOAD_DAPP_JSON_KEY_BASE64 }}
gcpBucketName: preview.dashboard.test.threshold.network
gcpBucketPath: ${{ github.head_ref }}
preview: true

# This job will be triggered via the `workflow_dispatch` event, as part of the
Expand Down

0 comments on commit 1a089e3

Please sign in to comment.