Skip to content

Commit

Permalink
Merge pull request #56 from benchling/master
Browse files Browse the repository at this point in the history
add option to not send PULL_REQUEST_ID
  • Loading branch information
lizrabuya authored Apr 29, 2024
2 parents ad8b8ea + a885cbc commit 9a17201
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ steps:
build_env_vars: '{"TRIGGERED_FROM_GHA": "true"}'
build_meta_data: '{"FOO": "bar"}'
ignore_pipeline_branch_filter: true
send_pull_request: true
```

## Outputs
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ inputs:
message:
description: 'The message for the build'
required: false
send_pull_request:
description: 'Whether to set PULL_REQUEST_ID, which sets BUILDKITE_PULL_REQUEST on the build. Does not work for cross-repo builds. Defaults to true'
required: false
build_env_vars:
description: 'Additional environment variables to set on the build, in JSON format'
required: false
Expand All @@ -33,4 +36,4 @@ runs:
image: 'Dockerfile'
branding:
icon: 'send'
color: 'green'
color: 'green'
7 changes: 5 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ MESSAGE="${INPUT_MESSAGE:-}"

NAME=$(jq -r ".pusher.name" "$GITHUB_EVENT_PATH")
EMAIL=$(jq -r ".pusher.email" "$GITHUB_EVENT_PATH")
PULL_REQUEST_ID=$(jq -r '.pull_request.number // ""' "$GITHUB_EVENT_PATH")
PULL_REQUEST_ID=""
if [[ "${INPUT_SEND_PULL_REQUEST:-true}" == 'true' ]]; then
PULL_REQUEST_ID=$(jq -r '.pull_request.number // ""' "$GITHUB_EVENT_PATH")
fi

INPUT_BUILD_ENV_VARS="${INPUT_BUILD_ENV_VARS:-}"

Expand Down Expand Up @@ -178,4 +181,4 @@ if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
else
echo "::set-output name=json::$RESPONSE"
echo "::set-output name=url::$URL"
fi
fi
25 changes: 25 additions & 0 deletions tests/entrypoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ teardown() {
unstub curl
}

@test "Creates a build with send_pull_request set to false from \${{ inputs.send_pull_request }}" {
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123"
export INPUT_PIPELINE="my-org/my-pipeline"
export INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}"
export INPUT_SEND_PULL_REQUEST="false"
export GITHUB_EVENT_NAME="create"
export GITHUB_EVENT_PATH="tests/pullrequest.json"

EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"[email protected]"},"env":{"FOO":"bar","GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}'
RESPONSE_JSON='{"web_url": "https://buildkite.com/build-url"}'

stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'"

run $PWD/entrypoint.sh

assert_output --partial "Build created:"
assert_output --partial "https://buildkite.com/build-url"
assert_output --partial "::set-output name=json::$RESPONSE_JSON"
assert_output --partial "::set-output name=url::https://buildkite.com/build-url"

assert_success

unstub curl
}

@test "Writes outputs to \$GITHUB_OUTPUT file if defined" {
TEST_TEMP_DIR="$(temp_make)"

Expand Down

0 comments on commit 9a17201

Please sign in to comment.