From a4af82ff0a4ec743a2203c755059d54205de7464 Mon Sep 17 00:00:00 2001 From: Igor Souza Date: Mon, 21 Oct 2019 21:51:51 -0300 Subject: [PATCH] init --- Dockerfile | 15 +++++++++++++++ README.md | 4 ++++ entrypoint.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63242ca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM hashicorp/terraform:0.12.12 + +LABEL "com.github.actions.name"="terraform validate" +LABEL "com.github.actions.description"="Validate the terraform files in a directory" +LABEL "com.github.actions.icon"="alert-triangle" +LABEL "com.github.actions.color"="purple" + +LABEL "repository"="https://github.com/hashicorp/terraform-github-actions" +LABEL "homepage"="http://github.com/hashicorp/terraform-github-actions" +LABEL "maintainer"="HashiCorp Terraform Team " + +RUN apk --update --no-cache add jq curl bash + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..d854653 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Terraform Validate Action +Runs `terraform validate` to validate the terraform files in a directory. + +See [https://www.terraform.io/docs/github-actions/actions/validate.html](https://www.terraform.io/docs/github-actions/actions/validate.html). diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..f696f24 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -e +set -o pipefail + +if [[ -n "$TOKEN" ]]; then + GITHUB_TOKEN=$TOKEN +fi + +if [[ -z "$GITHUB_TOKEN" ]]; then + echo "Set the GITHUB_TOKEN env variable." + exit 1 +fi + +URI=https://api.github.com +API_VERSION=v3 +API_HEADER="Accept: application/vnd.github.${API_VERSION}+json" +AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" + +NO_BRANCH_DELETED_EXIT_CODE=${NO_BRANCH_DELETED_EXIT_CODE:-0} + +main(){ + action=$(jq --raw-output .action "$GITHUB_EVENT_PATH") + merged=$(jq --raw-output .pull_request.merged "$GITHUB_EVENT_PATH") + + echo "DEBUG -> action: $action merged: $merged" + + + ref=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH") + owner=$(jq --raw-output .pull_request.head.repo.owner.login "$GITHUB_EVENT_PATH") + repo=$(jq --raw-output .pull_request.head.repo.name "$GITHUB_EVENT_PATH") + + + echo ::set-env name=BRANCH_NAME::${ref} + + exit 0 +} + +main "$@"