Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify bucket-path when github.head_ref is not set #160

Merged
merged 2 commits into from
Aug 18, 2022

Conversation

michalinacienciala
Copy link
Contributor

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:///".

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.

@github-actions
Copy link

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.
@michalinacienciala michalinacienciala force-pushed the fix-build-and-deploy-to-bucket-action branch from 976032f to 47fa501 Compare August 18, 2022 08:49
@github-actions
Copy link

- name: Deploy to GCP
uses: thesis/gcp-storage-bucket-action@v3.1.0
with:
service-key: ${{ inputs.gcpServiceKey }}
project: ${{ env.GOOGLE_PROJECT_ID }}
bucket-name: ${{ inputs.gcpBucketName }}
bucket-path: ${{ github.head_ref }}
bucket-path: ${{ steps.set-bucket-path.outputs.bucket-path }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another solution would be to define gcpBucketPath with the default: . and expect the value to be provided in the caller.

Suggested change
bucket-path: ${{ steps.set-bucket-path.outputs.bucket-path }}
bucket-path: ${{ inputs.gcpBucketPath }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that could work, as long as we make sure that the gcpBucketPath will not have the empty value. In our current use case (using action to build dashboard) it's not problematic. I'll prepare the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See fdcd76f. Unfortunately I had to split the Build step to two steps, depending on condition. Couldn't think of a cleaner solution.

@github-actions
Copy link

Input is introduced as a dfferent approach to the problem tackled in commit
47fa501. We needed to ensure that
`gcp-storage-bucket-action@v3.1.0` action does not get empty inputs.
@github-actions
Copy link

@nkuba nkuba merged commit 77cdfd1 into main Aug 18, 2022
@nkuba nkuba deleted the fix-build-and-deploy-to-bucket-action branch August 18, 2022 10:21
georgeweiler pushed a commit that referenced this pull request Sep 8, 2022
…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.
@r-czajkowski r-czajkowski added this to the v1.3.0 milestone Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants