Skip to content

Commit

Permalink
test integration workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lizrabuya committed Sep 18, 2023
1 parent b1bb995 commit d4ed44c
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 319 deletions.
21 changes: 0 additions & 21 deletions .github/main.workflow

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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: Integration test 1
uses: ./
with:
buildkite-token: 123
pipeline: "test-pipeline"
10 changes: 3 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: 'A GitHub Action for triggering a build on a Buildkite pipeline.'
inputs:
buildkite-token:
description: 'Buildkite API Access Token'
required: false
required: true
pipeline:
description: 'The pipline to create a build on, in the format <org-slug>/<pipeline-slug>'
required: false
required: true
commit:
description: 'The commit SHA of the build'
required: false
Expand All @@ -31,11 +31,7 @@ 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 }}
BUILDKITE_API_ACCESS_TOKEN: ${{ inputs.buildkite-token }}
BUILD_ENV_VARS: ${{ inputs.build-env-vars }}
BUILD_META_DATA: ${{ inputs.build-meta-data }}
IGNORE_PIPELINE_BRANCH_FILTER: ${{ inputs.ignore-pipeline-branch-filter }}
67 changes: 32 additions & 35 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function get_github_env_json() {
}

function get_build_env_vars_json() {
BUILD_ENV_VARS=$(
jq -c -s 'add' \
<(echo "$1") \
<(echo "$2") \
<(echo "$3")
)
BUILD_ENV_VARS=$(
jq -c -s 'add' \
<(echo "$1") \
<(echo "$2") \
<(echo "$3")
)
echo "$BUILD_ENV_VARS"
}

Expand All @@ -57,17 +57,17 @@ if [[ -z "${BUILDKITE_API_ACCESS_TOKEN:-}" ]]; then
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 INPUT_PIPELINE environment variable (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")
Expand All @@ -77,28 +77,27 @@ BUILD_ENV_VARS="${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 ! echo "$BUILD_ENV_VARS" | jq empty; then
echo ""
echo "Error: BUILD_ENV_VARS provided invalid JSON: $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)")"


# 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,
Expand All @@ -111,7 +110,7 @@ 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

Expand All @@ -136,9 +135,9 @@ 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}'
)
FINAL_JSON=$(
echo "$JSON" | jq -c --argjson env "$BUILD_ENV_VARS_JSON" '. + {env: $env}'
)
else
FINAL_JSON=$JSON
fi
Expand All @@ -156,7 +155,7 @@ RESPONSE=$(
) || 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
Expand All @@ -166,17 +165,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
Loading

0 comments on commit d4ed44c

Please sign in to comment.