forked from buildkite/trigger-pipeline-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update entrypoint.sh error messages and entrypoint.bats test names to…
… reference to input params
- Loading branch information
Showing
4 changed files
with
51 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env | ||
#!/usr/bin/env bats | ||
|
||
# load "${BATS_PLUGIN_PATH}/load.bash" | ||
load "${BATS_PLUGIN_PATH}/load.bash" | ||
|
||
# Uncomment to enable stub debugging | ||
# export CURL_STUB_DEBUG=/dev/tty | ||
|
@@ -15,27 +15,27 @@ setup() { | |
} | ||
|
||
teardown() { | ||
unset BUILDKITE_API_ACCESS_TOKEN | ||
unset INPUT_BUILDKITE_API_ACCESS_TOKEN | ||
unset INPUT_PIPELINE | ||
if [[ -f "$HOME/push.json" ]]; then rm "$HOME/push.json"; fi | ||
} | ||
|
||
@test "Prints error and fails if \$BUILDKITE_API_ACCESS_TOKEN isn't set" { | ||
@test "Prints error and fails if \${{ inputs.buildkite_api_access_token }} isn't set" { | ||
run "${PWD}"/entrypoint.sh | ||
assert_output --partial "You must set the BUILDKITE_API_ACCESS_TOKEN environment variable" | ||
assert_output --partial "You must set the buildkite_api_access_token input parameter" | ||
assert_failure | ||
} | ||
|
||
@test "Prints error and fails if \${{ inputs.pipeline }} isn't set" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
|
||
run "${PWD}"/entrypoint.sh | ||
assert_output --partial "You must set the INPUT_PIPELINE environment variable" | ||
assert_output --partial "You must set the pipeline input parameter" | ||
assert_failure | ||
} | ||
|
||
@test "Creates a build with defaults" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -56,8 +56,8 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Creates a build with commit from \$COMMIT" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Creates a build with commit from \${{ inputs.commit }}" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export INPUT_COMMIT="custom-commit" | ||
export GITHUB_EVENT_NAME="create" | ||
|
@@ -79,10 +79,10 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Creates a build with branch from \$BRANCH" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Creates a build with branch from \${{ inputs.branch }}" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export INPUT_BRANCH="custom-branch" | ||
export INPUT_BRANCH="custom-branch" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
EXPECTED_JSON='{"commit":"a-sha","branch":"custom-branch","message":"","author":{"name":"The Pusher","email":"[email protected]"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' | ||
|
@@ -103,7 +103,7 @@ teardown() { | |
} | ||
|
||
@test "Creates a build from pull request" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_EVENT_PATH="tests/pullrequest.json" | ||
export GITHUB_EVENT_NAME="create" | ||
|
@@ -125,8 +125,8 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Creates a build with branch from \$INPUT_MESSAGE" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Creates a build with branch from \${{ inputs.message }}" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export INPUT_MESSAGE="A custom message" | ||
export GITHUB_EVENT_NAME="create" | ||
|
@@ -148,10 +148,10 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Creates a build with build env vars from \$BUILD_ENV_VARS" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Creates a build with build env vars from \${{ inputs.build_env_vars }}" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
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"}}' | ||
|
@@ -171,8 +171,8 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Creates a build with build meta-data vars from \$BUILD_META_DATA" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Creates a build with build meta-data vars from \${{ inputs.build_meta_data }}" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_META_DATA="{\"FOO\": \"bar\"}" | ||
export GITHUB_EVENT_NAME="create" | ||
|
@@ -194,10 +194,10 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Creates a build with ignore_pipeline_branch_filters set to true from \$IGNORE_PIPELINE_BRANCH_FILTER" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Creates a build with ignore_pipeline_branch_filters set to true from \${{ inputs.ignore_pipeline_branch_filter }}" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export IGNORE_PIPELINE_BRANCH_FILTER="true" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -221,9 +221,9 @@ teardown() { | |
@test "Writes outputs to \$GITHUB_OUTPUT file if defined" { | ||
TEST_TEMP_DIR="$(temp_make)" | ||
|
||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export GITHUB_OUTPUT=$TEST_TEMP_DIR/github_output_file | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -252,7 +252,7 @@ teardown() { | |
} | ||
|
||
@test "Prints curl error on HTTP error" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -271,7 +271,7 @@ teardown() { | |
} | ||
|
||
@test "Prints curl error and ignores non-JSON response on HTTP error" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -292,7 +292,7 @@ teardown() { | |
} | ||
|
||
@test "Prints curl error but not null JSON response message on HTTP error" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -312,7 +312,7 @@ teardown() { | |
} | ||
|
||
@test "Prints curl error and JSON response message on HTTP error" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
|
@@ -331,34 +331,34 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Prints error and fails if \$BUILD_ENV_VARS is not valid JSON" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Prints error and fails if \${{ inputs.build_env_vars }} is not valid JSON" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_ENV_VARS="broken" | ||
export INPUT_BUILD_ENV_VARS="broken" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
run "${PWD}"/entrypoint.sh | ||
|
||
assert_output --partial "Error: BUILD_ENV_VARS provided invalid JSON: broken" | ||
assert_output --partial "Error: build_env_vars provided invalid JSON: broken" | ||
|
||
assert_failure | ||
} | ||
|
||
@test "Prints error and fails if \$BUILD_META_DATA is not valid JSON" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Prints error and fails if \${{ inputs.build_meta_data }} is not valid JSON" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_META_DATA="broken" | ||
export GITHUB_EVENT_NAME="create" | ||
|
||
run $PWD/entrypoint.sh | ||
|
||
assert_output --partial "Error: BUILD_META_DATA provided invalid JSON: broken" | ||
assert_output --partial "Error: build_meta_data provided invalid JSON: broken" | ||
|
||
assert_failure | ||
} | ||
|
||
@test "Sets DELETED_EVENT_REF on delete event" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export GITHUB_ACTION="delete" | ||
export GITHUB_EVENT_NAME="delete" | ||
|
@@ -378,10 +378,10 @@ teardown() { | |
unstub curl | ||
} | ||
|
||
@test "Combines DELETED_EVENT_REF and BUILD_ENV_VARS correctly" { | ||
export BUILDKITE_API_ACCESS_TOKEN="123" | ||
@test "Combines DELETED_EVENT_REF and build_env_vars correctly" { | ||
export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" | ||
export INPUT_PIPELINE="my-org/my-pipeline" | ||
export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" | ||
export GITHUB_ACTION="delete" | ||
export GITHUB_EVENT_NAME="delete" | ||
|
||
|