Skip to content

Commit a9fcacb

Browse files
Specify bucket-path when github.head_ref is not set
In the workflow we're executing the `thesis/[email protected]` action. One of its inputs is `bucket-path`, wich 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 thouth the default value will be used when `bucket-name: ` (vithout 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 vallue 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/[email protected]`. Read more about how runner handles empty values here: actions/runner#924.
1 parent 6906445 commit a9fcacb

File tree

1 file changed

+17
-1
lines changed
  • .github/actions/build-and-deploy-to-bucket

1 file changed

+17
-1
lines changed

.github/actions/build-and-deploy-to-bucket/action.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,29 @@ runs:
117117
ETH_HOSTNAME_HTTP: ${{ inputs.ethUrlHttp }}
118118
ETH_HOSTNAME_WS: ${{ inputs.ethUrlWS }}
119119

120+
# We need this step to set correct value of `bucket-path` in the
121+
# `cp-storage-bucket-action`. We can't use `${{ github.head_ref }}` directly
122+
# there, because then when `head_ref` is empty, the parameter `bucket-path`
123+
# is not forwarded to the runner and empty value is assigned to the
124+
# `bucket-path` input instead of the default value (`.`). This results in
125+
# incorrect passing of docker arguments and setting wrong bucket address.
126+
- name: Configure `bucket-path`
127+
shell: bash
128+
id: set-bucket-path
129+
run: |
130+
if [ ${{ github.head_ref }} == '' ]; then
131+
echo "::set-output name=bucket-path::."
132+
else
133+
echo "::set-output name=bucket-path::${{ github.head_ref }}"
134+
fi
135+
120136
- name: Deploy to GCP
121137
uses: thesis/[email protected]
122138
with:
123139
service-key: ${{ inputs.gcpServiceKey }}
124140
project: ${{ env.GOOGLE_PROJECT_ID }}
125141
bucket-name: ${{ inputs.gcpBucketName }}
126-
bucket-path: ${{ github.head_ref }}
142+
bucket-path: ${{ steps.set-bucket-path.outputs.bucket-path }}
127143
build-folder: build
128144
set-website: ${{ inputs.preview == 'false' }}
129145
home-page-path: index.html

0 commit comments

Comments
 (0)