diff --git a/.github/main.workflow b/.github/main.workflow deleted file mode 100644 index 8d69eee..0000000 --- a/.github/main.workflow +++ /dev/null @@ -1,21 +0,0 @@ -# Actions for trigger-pipeline - -workflow "Test" { - on = "push" - resolves = "bats" -} - -workflow "Lint" { - on = "push" - resolves = "shellcheck" -} - -action "shellcheck" { - uses = "actions/bin/shellcheck@master" - args = "*.sh" -} - -action "bats" { - uses = "docker://buildkite/plugin-tester" - runs = ["sh", "-e", "-c", "apk --no-cache add jq && bats tests/"] -} \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..a454d35 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,23 @@ +name: Unit Test + +on: push + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + + - name: Check out code + uses: actions/checkout@v3 + + - name: Verify that the Docker image for the action builds + run: docker build . --file Dockerfile + + tests: + name: unit-test + runs-on: ubuntu-latest + steps: + - name: Run unit test for the action + run: docker run --rm -v "$PWD":/plugin buildkite/plugin-tester:v4.0.0 + \ No newline at end of file diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..359c59b --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,38 @@ +name: Verify + +on: push + +jobs: + tests: + name: Integration tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Verify that the Docker image for the action builds + run: docker build . --file Dockerfile + + - name: Run action with minimal parameters + uses: ./ + with: + buildkite_api_access_token: ${{ secrets.BUILDKITE_API_ACCESS_TOKEN }} + pipeline: "lzrinc/experimental-pipeline" + message: Triggered from GHA using minimal parameters + branch: master + commit: HEAD + + - name: Run action with all parameters + uses: ./ + id: tests + with: + buildkite_api_access_token: ${{ secrets.BUILDKITE_API_ACCESS_TOKEN }} + pipeline: "lzrinc/experimental-pipeline" + branch: dev + commit: HEAD + message: ":buildkite::github: 🚀🚀🚀 Triggered from GHA using commit message: ${{ github.event.head_commit.message }}" + build_env_vars: '{"TRIGGERED_FROM_GHA": "true"}' + build_meta_data: '{"FOO": "bar"}' + ignore_pipeline_branch_filter: true + + - name: Verify output + run: echo ${{join(steps.tests.outputs.*, '\n')}} diff --git a/README.md b/README.md index 8e8abbd..b939755 100644 --- a/README.md +++ b/README.md @@ -14,41 +14,9 @@ Create a [Buildkite API Access Token](https://buildkite.com/docs/apis/rest-api#a ## Configuration Options -### Configuration as Environment Variables - -For example, the following workflow creates a new Buildkite build on every commit by setting environment variables: - -``` -on: [push] - -steps: - - name: Trigger a Buildkite Build - uses: "buildkite/trigger-pipeline-action@v1.6.0" - env: - BUILDKITE_API_ACCESS_TOKEN: ${{ secrets.TRIGGER_BK_BUILD_TOKEN }} - PIPELINE: "my-org/my-deploy-pipeline" - BRANCH: "master" - COMMIT: "HEAD" - MESSAGE: ":github: Triggered from a GitHub Action" -``` - - - -The following environment variable options can be configured: - -|Env var|Description|Default| -|-|-|-| -|PIPELINE|The pipeline to create a build on, in the format `/`|| -|COMMIT|The commit SHA of the build. Optional.|`$GITHUB_SHA`| -|BRANCH|The branch of the build. Optional.|`$GITHUB_REF`| -|MESSAGE|The message for the build. Optional.|| -|BUILD_ENV_VARS|Additional environment variables to set on the build, in JSON format. e.g. `{"FOO": "bar"}`. Optional. || -|BUILD_META_DATA|Meta data to set on the build, in JSON format. e.g. `{"FOO": "bar"}`. Optional. || -|IGNORE_PIPELINE_BRANCH_FILTER | Ignore pipeline branch filtering when creating a new build. true or false. Optional. || - ### Configuration as Input Parameters -From v1.6.0, optional input parameters can now be used to pass in the configuration options. However, configuration defined as environment variables take precedence over the input parameters. +The following workflow creates a new Buildkite build to the target `pipeline` on every commit. ``` on: [push] @@ -57,14 +25,14 @@ steps: - name: Trigger a Buildkite Build uses: "buildkite/trigger-pipeline-action@v1.6.0" with: - buildkite-token: ${{ secrets.TRIGGER_BK_BUILD_TOKEN }} + buildkite_api_access_token: ${{ secrets.TRIGGER_BK_BUILD_TOKEN }} pipeline: "my-org/my-deploy-pipeline" branch: "master" commit: "HEAD" message: ":github: Triggered from a GitHub Action" - build-env-vars: '{"TRIGGERED_FROM_GHA": "true"}' - build-meta-data: '{"FOO": "bar"}' - ignore-pipeline-branch-filter: true + build_env_vars: '{"TRIGGERED_FROM_GHA": "true"}' + build_meta_data: '{"FOO": "bar"}' + ignore_pipeline_branch_filter: true ``` ## Outputs @@ -82,7 +50,7 @@ The following outputs are provided by the action: To run the test workflow, you use [act](https://github.com/nektos/act) which will run it just as it does on GitHub: ```bash -act +act -n ``` ## Testing diff --git a/action.yml b/action.yml index c03fa75..f659f0d 100644 --- a/action.yml +++ b/action.yml @@ -2,40 +2,32 @@ name: 'Trigger Buildkite Pipeline' author: 'Buildkite' description: 'A GitHub Action for triggering a build on a Buildkite pipeline.' inputs: - buildkite-token: + buildkite_api_access_token: description: 'Buildkite API Access Token' - required: false + required: true pipeline: description: 'The pipline to create a build on, in the format /' - required: false + required: true commit: description: 'The commit SHA of the build' required: false + default: HEAD branch: description: 'The branch of the build' required: false message: description: 'The message for the build' required: false - build-env-vars: + build_env_vars: description: 'Additional environment variables to set on the build, in JSON format' required: false - build-meta-data: + build_meta_data: description: 'Meta-data to set on the build, in JSON format' required: false - ignore-pipeline-branch-filter: + ignore_pipeline_branch_filter: description: 'Ignore pipeline branch filtering when creating a new build. true or false' required: false runs: using: 'docker' - image: 'Dockerfile' - env: - BUILDKITE_API_ACCESS_TOKEN: ${{ inputs.buildkite-token }} - PIPELINE: ${{ inputs.pipeline }} - BRANCH: ${{ inputs.branch }} - COMMIT: ${{ inputs.commit }} - MESSAGE: ${{ inputs.message }} - BUILD_ENV_VARS: ${{ inputs.build-env-vars }} - BUILD_META_DATA: ${{ inputs.build-meta-data }} - IGNORE_PIPELINE_BRANCH_FILTER: ${{ inputs.ignore-pipeline-branch-filter }} \ No newline at end of file + image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index ebbaa6b..7bcbaea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -42,63 +42,64 @@ function get_github_env_json() { echo "$GITHUB_EVENT_JSON" } -function get_build_env_vars_json() { - BUILD_ENV_VARS=$( - jq -c -s 'add' \ - <(echo "$1") \ - <(echo "$2") \ - <(echo "$3") - ) - echo "$BUILD_ENV_VARS" +function get_INPUT_BUILD_ENV_VARS_json() { + INPUT_BUILD_ENV_VARS=$( + jq -c -s 'add' \ + <(echo "$1") \ + <(echo "$2") \ + <(echo "$3") + ) + + echo "$INPUT_BUILD_ENV_VARS" } -if [[ -z "${BUILDKITE_API_ACCESS_TOKEN:-}" ]]; then - echo "You must set the BUILDKITE_API_ACCESS_TOKEN environment variable (e.g. BUILDKITE_API_ACCESS_TOKEN = \"xyz\")" +if [[ -z "${INPUT_BUILDKITE_API_ACCESS_TOKEN:-}" ]]; then + echo "You must set the buildkite_api_access_token input parameter (e.g. buildkite_api_access_token: \"1234567890\")" exit 1 fi -if [[ -z "${PIPELINE:-}" ]]; then - echo "You must set the PIPELINE environment variable (e.g. PIPELINE = \"my-org/my-pipeline\")" +if [[ -z "${INPUT_PIPELINE:-}" ]]; then + echo "You must set the pipeline input parameter (e.g. pipeline: \"my-org/my-pipeline\")" exit 1 fi -ORG_SLUG=$(echo "${PIPELINE}" | cut -d'/' -f1) -PIPELINE_SLUG=$(echo "${PIPELINE}" | cut -d'/' -f2) +ORG_SLUG=$(echo "${INPUT_PIPELINE}" | cut -d'/' -f1) +PIPELINE_SLUG=$(echo "${INPUT_PIPELINE}" | cut -d'/' -f2) -COMMIT="${COMMIT:-${GITHUB_SHA}}" -BRANCH="${BRANCH:-${GITHUB_REF#"refs/heads/"}}" -MESSAGE="${MESSAGE:-}" +COMMIT="${INPUT_COMMIT:-${GITHUB_SHA}}" +BRANCH="${INPUT_BRANCH:-${GITHUB_REF#"refs/heads/"}}" +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") -BUILD_ENV_VARS="${BUILD_ENV_VARS:-}" +INPUT_BUILD_ENV_VARS="${INPUT_BUILD_ENV_VARS:-}" DELETE_EVENT_JSON="" if is_delete_event; then - DELETE_EVENT_JSON="$(get_delete_event_json)" + DELETE_EVENT_JSON="$(get_delete_event_json)" fi -if [[ "$BUILD_ENV_VARS" ]]; then - if ! echo "$BUILD_ENV_VARS" | jq empty; then - echo "" - echo "Error: BUILD_ENV_VARS provided invalid JSON: $BUILD_ENV_VARS" - exit 1 +if [[ "$INPUT_BUILD_ENV_VARS" ]]; then + if ! echo "$INPUT_BUILD_ENV_VARS" | jq empty; then + echo "" + echo "Error: build_env_vars provided invalid JSON: $INPUT_BUILD_ENV_VARS" + exit 1 fi fi -BUILD_ENV_VARS_JSON="$(get_build_env_vars_json "$DELETE_EVENT_JSON" "$BUILD_ENV_VARS" "$(get_github_env_json)")" - +INPUT_BUILD_ENV_VARS_JSON="$(get_INPUT_BUILD_ENV_VARS_json "$DELETE_EVENT_JSON" "$INPUT_BUILD_ENV_VARS" "$(get_github_env_json)")" + # Use jq’s --arg properly escapes string values for us JSON=$( jq -c -n \ - --arg COMMIT "$COMMIT" \ - --arg BRANCH "$BRANCH" \ + --arg COMMIT "$COMMIT" \ + --arg BRANCH "$BRANCH" \ --arg MESSAGE "$MESSAGE" \ - --arg NAME "$NAME" \ - --arg EMAIL "$EMAIL" \ + --arg NAME "$NAME" \ + --arg EMAIL "$EMAIL" \ '{ "commit": $COMMIT, "branch": $BRANCH, @@ -111,22 +112,22 @@ JSON=$( ) # Link pull request if pull request id is specified -if [[ ! -z "$PULL_REQUEST_ID" ]]; then +if [[ -n "$PULL_REQUEST_ID" ]]; then JSON=$(echo "$JSON" | jq -c --arg PULL_REQUEST_ID "$PULL_REQUEST_ID" '. + {pull_request_id: $PULL_REQUEST_ID}') fi # Set build meta data, if specified -if [[ "${BUILD_META_DATA:-}" ]]; then - if ! JSON=$(echo "$JSON" | jq -c --argjson BUILD_META_DATA "$BUILD_META_DATA" '. + {meta_data: $BUILD_META_DATA}'); then +if [[ "${INPUT_BUILD_META_DATA:-}" ]]; then + if ! JSON=$(echo "$JSON" | jq -c --argjson INPUT_BUILD_META_DATA "$INPUT_BUILD_META_DATA" '. + {meta_data: $INPUT_BUILD_META_DATA}'); then echo "" - echo "Error: BUILD_META_DATA provided invalid JSON: $BUILD_META_DATA" + echo "Error: build_meta_data provided invalid JSON: $INPUT_BUILD_META_DATA" exit 1 fi fi # Merge in ignore_pipeline_branch_filters, if they specified a value -if [[ "${IGNORE_PIPELINE_BRANCH_FILTER:-}" ]]; then - if ! JSON=$(echo "$JSON" | jq -c --argjson IGNORE_PIPELINE_BRANCH_FILTER "$IGNORE_PIPELINE_BRANCH_FILTER" '. + {ignore_pipeline_branch_filters: $IGNORE_PIPELINE_BRANCH_FILTER}'); then +if [[ "${INPUT_IGNORE_PIPELINE_BRANCH_FILTER:-}" ]]; then + if ! JSON=$(echo "$JSON" | jq -c --argjson INPUT_IGNORE_PIPELINE_BRANCH_FILTER "$INPUT_IGNORE_PIPELINE_BRANCH_FILTER" '. + {ignore_pipeline_branch_filters: $INPUT_IGNORE_PIPELINE_BRANCH_FILTER}'); then echo "" echo "Error: Could not set ignore_pipeline_branch_filters" exit 1 @@ -135,10 +136,10 @@ fi # Add additional env vars as a nested object FINAL_JSON="" -if [[ "$BUILD_ENV_VARS_JSON" ]]; then - FINAL_JSON=$( - echo "$JSON" | jq -c --argjson env "$BUILD_ENV_VARS_JSON" '. + {env: $env}' - ) +if [[ "$INPUT_BUILD_ENV_VARS_JSON" ]]; then + FINAL_JSON=$( + echo "$JSON" | jq -c --argjson env "$INPUT_BUILD_ENV_VARS_JSON" '. + {env: $env}' + ) else FINAL_JSON=$JSON fi @@ -150,13 +151,13 @@ RESPONSE=$( --silent \ --show-error \ -X POST \ - -H "Authorization: Bearer ${BUILDKITE_API_ACCESS_TOKEN}" \ + -H "Authorization: Bearer ${INPUT_BUILDKITE_API_ACCESS_TOKEN}" \ "https://api.buildkite.com/v2/organizations/${ORG_SLUG}/pipelines/${PIPELINE_SLUG}/builds" \ -d "$FINAL_JSON" | tr -d '\n' ) || CODE=$? if [ $CODE -ne 0 ]; then - MESSAGE=$(echo "$RESPONSE" | jq .message 2> /dev/null || true) + MESSAGE=$(echo "$RESPONSE" | jq .message 2>/dev/null || true) if [[ -n "$MESSAGE" ]] && [[ "$MESSAGE" != 'null' ]]; then echo -n "Buildkite API call failed: $MESSAGE" fi @@ -166,17 +167,15 @@ fi echo "" echo "Build created:" URL=$(echo "$RESPONSE" | jq --raw-output ".web_url") -echo $URL +echo "$URL" # Provide JSON and Web URL as outputs for downstream actions # use environment variable $GITHUB_OUTPUT, or fall back to deprecated set-output command # https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ -if [[ -n "${GITHUB_OUTPUT:-}" ]] -then - echo "json=$RESPONSE" >> ${GITHUB_OUTPUT} - echo "url=$URL" >> ${GITHUB_OUTPUT} +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "json=$RESPONSE" >>"${GITHUB_OUTPUT}" + echo "url=$URL" >>"${GITHUB_OUTPUT}" else echo "::set-output name=json::$RESPONSE" echo "::set-output name=url::$URL" -fi - +fi \ No newline at end of file diff --git a/tests/entrypoint.bats b/tests/entrypoint.bats index d9ddf5c..db621de 100644 --- a/tests/entrypoint.bats +++ b/tests/entrypoint.bats @@ -15,30 +15,31 @@ setup() { } teardown() { - unset BUILDKITE_API_ACCESS_TOKEN - unset PIPELINE + 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 \$PIPELINE isn't set" { - export BUILDKITE_API_ACCESS_TOKEN="123" - - run "${PWD}"/entrypoint.sh +@test "Prints error and fails if \${{ inputs.pipeline }} isn't set" { + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" - assert_output --partial "You must set the PIPELINE environment variable" + run "${PWD}"/entrypoint.sh + 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 PIPELINE="my-org/my-pipeline" + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -58,10 +59,11 @@ teardown() { unstub curl } -@test "Creates a build with commit from \$COMMIT" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export COMMIT="custom-commit" +@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" EXPECTED_JSON='{"commit":"custom-commit","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -81,10 +83,11 @@ teardown() { unstub curl } -@test "Creates a build with branch from \$BRANCH" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export BRANCH="custom-branch" +@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 GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"custom-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -105,8 +108,9 @@ teardown() { } @test "Creates a build from pull request" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" + + 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" @@ -127,10 +131,11 @@ teardown() { unstub curl } -@test "Creates a build with branch from \$MESSAGE" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export MESSAGE="A custom message" +@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" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"A custom message","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -150,10 +155,11 @@ teardown() { unstub curl } -@test "Creates a build with build env vars from \$BUILD_ENV_VARS" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" +@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 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":"pusher@pusher.com"},"env":{"FOO":"bar","GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -173,10 +179,10 @@ teardown() { unstub curl } -@test "Creates a build with build meta-data vars from \$BUILD_META_DATA" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export BUILD_META_DATA="{\"FOO\": \"bar\"}" +@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 INPUT_BUILD_META_DATA="{\"FOO\": \"bar\"}" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"meta_data":{"FOO":"bar"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -196,11 +202,11 @@ 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" - export PIPELINE="my-org/my-pipeline" - export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" - export IGNORE_PIPELINE_BRANCH_FILTER="true" +@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 INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" + export INPUT_IGNORE_PIPELINE_BRANCH_FILTER="true" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"ignore_pipeline_branch_filters":true,"env":{"FOO":"bar","GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -220,12 +226,12 @@ teardown() { unstub curl } -@test "Writes outputs to \$GITHUB_OUTPUT file if defined" { +@test "Writes outputs to \$GITHUB_OUTPUT file if defined" { TEST_TEMP_DIR="$(temp_make)" - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" + export INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" export GITHUB_OUTPUT=$TEST_TEMP_DIR/github_output_file export GITHUB_EVENT_NAME="create" @@ -254,8 +260,9 @@ teardown() { } @test "Prints curl error on HTTP error" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -273,8 +280,9 @@ teardown() { } @test "Prints curl error and ignores non-JSON response on HTTP error" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -294,8 +302,9 @@ teardown() { } @test "Prints curl error but not null JSON response message on HTTP error" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -314,8 +323,9 @@ teardown() { } @test "Prints curl error and JSON response message on HTTP error" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" export GITHUB_EVENT_NAME="create" EXPECTED_JSON='{"commit":"a-sha","branch":"a-branch","message":"","author":{"name":"The Pusher","email":"pusher@pusher.com"},"env":{"GITHUB_REPOSITORY":"buildkite/test-repo","SOURCE_REPO_SHA":"a-sha","SOURCE_REPO_REF":"a-branch"}}' @@ -333,35 +343,36 @@ teardown() { unstub curl } -@test "Prints error and fails if \$BUILD_ENV_VARS is not valid JSON" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export BUILD_ENV_VARS="broken" +@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 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" - export PIPELINE="my-org/my-pipeline" - export BUILD_META_DATA="broken" +@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 INPUT_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 PIPELINE="my-org/my-pipeline" + + export INPUT_BUILDKITE_API_ACCESS_TOKEN="123" + export INPUT_PIPELINE="my-org/my-pipeline" export GITHUB_ACTION="delete" export GITHUB_EVENT_NAME="delete" @@ -380,10 +391,11 @@ teardown() { unstub curl } -@test "Combines DELETED_EVENT_REF and BUILD_ENV_VARS correctly" { - export BUILDKITE_API_ACCESS_TOKEN="123" - export PIPELINE="my-org/my-pipeline" - export BUILD_ENV_VARS="{\"FOO\": \"bar\"}" +@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 INPUT_BUILD_ENV_VARS="{\"FOO\": \"bar\"}" export GITHUB_ACTION="delete" export GITHUB_EVENT_NAME="delete"