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

Allow specifying tag parameter for setting a custom tag in BSR #36

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ jobs:
env:
WANT_BUF_TOKEN: fake-buf-token
WANT_ARGS: push path/to/input --draft ${{ github.ref_name }}
- name: run action with custom tag
uses: ./
with:
buf_token: fake-buf-token
input: path/to/input
tag: custom-tag
env:
WANT_BUF_TOKEN: fake-buf-token
WANT_ARGS: push path/to/input --tag custom-tag
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ We recommend using [`buf-setup-action`][buf-setup] to install it (as in the exam
## Configuration

| Parameter | Description | Required | Default |
| :------------------ | :----------------------------------------------------------------------------- | :------- | :---------------------------------- |
| :------------------ |:-------------------------------------------------------------------------------| :------- | :---------------------------------- |
| `buf_token` | The [Buf authentication token][buf-token] used for private [Buf inputs][input] | ✅ | [`${{github.token}}`][github-token] |
| `input` | The path of the [input] you want to push to BSR as a module | | `.` |
| `draft` | Indicates if the workflows should push to the BSR as a [draft][buf-draft] | | |
| `create_visibility` | The visibility to create the BSR repository with, if it does not already exist | | |
| `tag` | The custom tag to push to the BSR | | |
Copy link
Member

Choose a reason for hiding this comment

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

Currently, we don't support "moving"/"re-writing" the same tag to a different commit. So if a user tries to set a single, static tag, their subsequent pushes will fail. This should be called out here.

Suggestion on this documentation:

" A custom tag to push with each commit. The BSR does not currently support moving or duplicated tags, so use this with care."


> These parameters are derived from [`action.yml`](./action.yml).

Expand Down Expand Up @@ -129,6 +130,26 @@ is not supported by `buf-push-action` on its own - you'll need to stitch this fu
your workflow on your own. For more details, see [this](https://github.com/bufbuild/buf/issues/838)
discussion.

### Push with a custom tag
Copy link
Member

Choose a reason for hiding this comment

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

Currently, you cannot buf push with both a --draft and a --tag. This should be clearly called out in the documentation.

Suggestion: at the end of this section, I would add the following warning:

Important note: you cannot set both `--tag` and `--draft`. You can only use one or the other.


If you want to push a module with a tag other than the Git commit SHA (e.g. for using semantic
versioning), you can set the `tag` property to the desired tag:

```yaml
steps:
# Run `git checkout`
- uses: actions/checkout@v2
# Install the `buf` CLI
- uses: bufbuild/buf-setup-action@v1
# Push only the Input in `proto` to the BSR
- uses: bufbuild/buf-push-action@v1
with:
input: proto
buf_token: ${{ secrets.BUF_TOKEN }}
# if triggered by a release tag, push with the tag
tag: ${{ github.ref_name }}
```

### Validate before push

`buf-push-action` is typically used alongside other `buf` Actions, such as
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
create_visibility:
description: The visibility of the BSR repository to be created with, if one needs to be created.
required: false
tag:
description: The tag to push the module as.
required: false
runs:
using: composite
steps:
Expand All @@ -27,4 +30,5 @@ runs:
BUF_TOKEN: ${{ inputs.buf_token }}
DRAFT: ${{ inputs.draft }}
CREATE_VISIBILITY: ${{ inputs.create_visibility }}
TAG: ${{ inputs.tag }}
run: $GITHUB_ACTION_PATH/push.bash ${{ inputs.input }}
7 changes: 6 additions & 1 deletion push.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ if [ -z "$BUF_COMMAND" ]; then
fail "$NOT_INSTALLED_MESSAGE"
fi

BUF_ARGS=("--tag" "${GITHUB_SHA}")
VERSION=${GITHUB_SHA}
if [ -n "${TAG}" ]; then
VERSION="${TAG}"
fi
Comment on lines +40 to +43
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should have a default behaviour if no tag is set. It should either be "no tag" or "tag with configured value".


BUF_ARGS=("--tag" "$VERSION")
if [ "${DRAFT}" == "true" ]; then
Comment on lines +45 to 46
Copy link
Member

Choose a reason for hiding this comment

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

We should have a check that does not set both DRAFT and TAG.

# Check that --draft is supported by running "buf push --draft example --help"
# and checking for "unknown flag: --draft" in the output.
Expand Down
17 changes: 16 additions & 1 deletion test/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ chmod +x tmp/test/bin/buf
unset GITHUB_SHA GITHUB_REF_NAME

test_push() {
export GITHUB_SHA GITHUB_REF_NAME BUF_TOKEN DRAFT WANT_BUF_TOKEN WANT_ARGS WANT_STDOUT WANT_STDERR WANT_EXIT_CODE CREATE_VISIBILITY
export GITHUB_SHA GITHUB_REF_NAME TAG BUF_TOKEN DRAFT WANT_BUF_TOKEN WANT_ARGS WANT_STDOUT WANT_STDERR WANT_EXIT_CODE CREATE_VISIBILITY
set +e
./push.bash "$@" > tmp/test/stdout 2> tmp/test/stderr
GOT_EXIT_CODE="${?}"
Expand Down Expand Up @@ -122,3 +122,18 @@ WANT_STDERR=""
WANT_EXIT_CODE=1
test_push some/input/path
echo "ok"

echo "testing happy path create with tag"
GITHUB_SHA=fake-sha
TAG=fake-tag
GITHUB_REF_NAME=main
BUF_TOKEN=fake-token
CREATE_VISIBILITY=private
WANT_BUF_TOKEN=fake-token
WANT_ARGS="push some/input/path --tag fake-tag --create --create-visibility private"
WANT_STDOUT="::add-mask::fake-token"
WANT_STDERR=""
WANT_EXIT_CODE=0
echo "TAG is ${TAG}"
test_push some/input/path
echo "ok"