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

remove github ref type checking on push #27

Merged
merged 2 commits into from Dec 15, 2022
Merged
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
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -11,7 +11,7 @@ Pushed modules are created with the Git commit SHA as the module tag.
Here's an example usage of `buf-push-action`:

```yaml
on: pull_request # Apply to all pull requests
on: push # Apply to all push
jobs:
push-module:
# Run `git checkout`
Expand All @@ -25,7 +25,7 @@ jobs:
draft: ${{ github.ref_name != 'main'}}
```

With this configuration, upon a pull request [opened, synchronize, or reopened][github-workflow]
With this configuration, upon a push [branches, tags][github-workflow]
the `buf` CLI pushes the [configured module][buf-yaml] to the BSR using the provided to
authenticate the request. When the triggering branch is not `main`, the commit will be pushed
as a [draft][buf-draft].
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
[buf-yaml]: https://docs.buf.build/configuration/v1/buf-yaml
[github-secret]: https://docs.github.com/en/actions/reference/encrypted-secrets
[github-token]: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
[github-workflow]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
[github-workflow]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
[input]: https://docs.buf.build/reference/inputs
[lint]: https://docs.buf.build/lint
[modules]: https://docs.buf.build/bsr/overview#module
9 changes: 0 additions & 9 deletions push.bash
Expand Up @@ -25,10 +25,6 @@ if [ -z "${GITHUB_REF_NAME}" ]; then
fail "the commit ref was not provided"
fi

if [ -z "${GITHUB_REF_TYPE}" ]; then
fail "the commit ref type was not provided"
fi

if [ -z "${BUF_TOKEN}" ]; then
fail "a buf authentication token was not provided"
fi
Expand All @@ -41,11 +37,6 @@ if [ -z "$BUF_COMMAND" ]; then
fail "$NOT_INSTALLED_MESSAGE"
fi

if [ "${GITHUB_REF_TYPE}" != "branch" ]; then
echo "reference type is not branch, skipping" >&2
exit 0
fi

BUF_ARGS=("--tag" "${GITHUB_SHA}")
if [ "${DRAFT}" == "true" ]; then
# Check that --draft is supported by running "buf push --draft example --help"
Expand Down
13 changes: 4 additions & 9 deletions test/test.bash
Expand Up @@ -13,11 +13,11 @@ PATH="${DIR}/tmp/test/bin:$PATH"
cp test/buf.bash tmp/test/bin/buf
chmod +x tmp/test/bin/buf

# prevent the GITHUB_SHA, GITHUB_REF_NAME and GITHUB_REF_TYPE set by actions from being used in test
unset GITHUB_SHA GITHUB_REF_NAME GITHUB_REF_TYPE
# prevent the GITHUB_SHA and GITHUB_REF_NAME set by actions from being used in test
unset GITHUB_SHA GITHUB_REF_NAME

test_push() {
export GITHUB_SHA GITHUB_REF_NAME GITHUB_REF_TYPE BUF_TOKEN DRAFT WANT_BUF_TOKEN WANT_ARGS
export GITHUB_SHA GITHUB_REF_NAME BUF_TOKEN DRAFT WANT_BUF_TOKEN WANT_ARGS
set +e
./push.bash "$@" > tmp/test/stdout 2> tmp/test/stderr
GOT_EXIT_CODE="${?}"
Expand All @@ -39,13 +39,12 @@ test_push() {
fi
fi
rm -f tmp/test/stdout tmp/test/stderr
unset GITHUB_SHA GITHUB_REF_NAME GITHUB_REF_TYPE BUF_TOKEN WANT_BUF_TOKEN WANT_ARGS
unset GITHUB_SHA GITHUB_REF_NAME BUF_TOKEN WANT_BUF_TOKEN WANT_ARGS
}

echo "testing happy path"
GITHUB_SHA=fake-sha
GITHUB_REF_NAME=main
GITHUB_REF_TYPE=branch
BUF_TOKEN=fake-token
WANT_BUF_TOKEN=fake-token
WANT_ARGS="push some/input/path --tag fake-sha"
Expand All @@ -58,7 +57,6 @@ echo "ok"
echo "testing happy path draft"
GITHUB_SHA=fake-sha
GITHUB_REF_NAME=fake-ref
GITHUB_REF_TYPE=branch
BUF_TOKEN=fake-token
DRAFT=true
WANT_BUF_TOKEN=fake-token
Expand All @@ -72,7 +70,6 @@ echo "ok"
echo "testing happy path draft on main branch"
GITHUB_SHA=fake-sha
GITHUB_REF_NAME=main
GITHUB_REF_TYPE=branch
BUF_TOKEN=fake-token
DRAFT=true
WANT_BUF_TOKEN=fake-token
Expand All @@ -86,7 +83,6 @@ echo "ok"
echo "testing no input"
GITHUB_SHA=fake-sha
GITHUB_REF_NAME=main
GITHUB_REF_TYPE=branch
BUF_TOKEN=fake-token
WANT_STDOUT=""
WANT_STDERR="Usage: ./push.bash <input>"
Expand All @@ -106,7 +102,6 @@ echo "ok"
echo "testing no BUF_TOKEN"
GITHUB_SHA=fake-sha
GITHUB_REF_NAME=main
GITHUB_REF_TYPE=branch
WANT_STDOUT='::add-mask::
::error::a buf authentication token was not provided'
WANT_STDERR=""
Expand Down