-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b8e12c5
Showing
8 changed files
with
203 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Tag release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
create_tag: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: check if tag already exists | ||
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0 | ||
|
||
- name: create tag | ||
run: | | ||
git config --global user.email "${{ github.actor }}" | ||
git config --global user.name "${{ github.actor }}" | ||
git tag -a -m "$(cat VERSION)" $(cat VERSION) | ||
git push --follow-tags |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
run_tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: setup git | ||
run: | | ||
git config --global user.email "${{ github.actor }}" | ||
git config --global user.name "${{ github.actor }}" | ||
- name: test failure on no terraform version | ||
id: fail_no_version | ||
continue-on-error: true | ||
uses: ./ | ||
|
||
- name: no terraform version failed | ||
if: steps.fail_no_version.outcome != 'failure' | ||
run: exit 1 | ||
|
||
- name: test failure on invalid terraform version | ||
id: fail_invalid_version | ||
continue-on-error: true | ||
uses: ./ | ||
with: | ||
terraform_version: asdf | ||
|
||
- name: invalid terraform version failed | ||
if: steps.fail_invalid_version.outcome != 'failure' | ||
run: exit 1 | ||
|
||
- name: test failure on missing terraform version | ||
id: fail_missing_version | ||
continue-on-error: true | ||
uses: ./ | ||
with: | ||
terraform_version: 999.999.999 | ||
|
||
- name: missing terraform version failed | ||
if: steps.fail_no_version.outcome != 'failure' | ||
run: exit 1 | ||
|
||
- name: munge test.tf for a failing commit | ||
run: echo "" >> test.tf | ||
|
||
- name: commit the munged test.tf | ||
run: git add . && git commit -m "running tests" | ||
|
||
- name: test failure | ||
id: failure_step | ||
continue-on-error: true | ||
uses: ./ | ||
with: | ||
terraform_version: 0.14.6 | ||
|
||
- name: failure failed | ||
if: steps.failure_step.outcome != 'failure' | ||
run: exit 1 | ||
|
||
- name: commit the newly fmt'd files | ||
run: git add . && git commit -m "running tests" | ||
|
||
- name: test success on the new commit | ||
uses: ./ | ||
with: | ||
terraform_version: 0.14.6 | ||
|
||
check_version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: check if tag already exists | ||
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0 |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Container image that runs your code | ||
FROM alpine:3.10 | ||
|
||
RUN apk update && apk add curl unzip git | ||
|
||
# Copies your code file from your action repository to the filesystem path `/` of the container | ||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
# Code file to execute when the docker container starts up (`entrypoint.sh`) | ||
ENTRYPOINT ["/entrypoint.sh"] |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Enforce Terraform fmt | ||
Status check which fails if any of the committed files have changes after running `terraform fmt` | ||
|
||
## Example usage | ||
```yaml | ||
uses: leigholiver/[email protected] | ||
with: | ||
terraform_version: 0.14.6 | ||
``` | ||
## Inputs | ||
### `terraform_version` | ||
**Required** The Terraform version to use | ||
|
||
## Outputs | ||
### `diff` | ||
The diff of terraform fmt changes |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.0.0 |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: 'Enforce Terraform fmt' | ||
description: 'Status check which fails if any of the committed files have changes after running `terraform fmt`' | ||
branding: | ||
icon: git-pull-request | ||
color: purple | ||
inputs: | ||
terraform_version: | ||
description: 'The Terraform version to use' | ||
required: true | ||
outputs: | ||
diff: | ||
description: 'The diff of terraform fmt changes' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.terraform_version }} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/sh -l | ||
set -e | ||
|
||
if [ -z "${INPUT_TERRAFORM_VERSION}" ]; then | ||
echo "No terraform version specified" | ||
exit 1 | ||
fi | ||
|
||
VERSION=$(expr "${INPUT_TERRAFORM_VERSION}" : [0-9]\\+\.[0-9]\\+\.[0-9]\\+) | ||
if [ "$VERSION" = "0" ]; then | ||
echo "Invalid terraform version specified" | ||
exit 1 | ||
fi | ||
|
||
# get terraform | ||
curl "https://releases.hashicorp.com/terraform/${INPUT_TERRAFORM_VERSION}/terraform_${INPUT_TERRAFORM_VERSION}_linux_amd64.zip" \ | ||
--output terraform_${INPUT_TERRAFORM_VERSION}_linux_amd64.zip | ||
|
||
if [ -f "terraform_${INPUT_TERRAFORM_VERSION}_linux_amd64.zip" ]; then | ||
unzip -o terraform_${INPUT_TERRAFORM_VERSION}_linux_amd64.zip | ||
else | ||
echo "Couldn't find terraform version" | ||
exit 1 | ||
fi | ||
|
||
# get the changed .tf/.tf.json files | ||
FAILED="false" | ||
for FILENAME in $(git diff --name-only HEAD HEAD~1); do | ||
if [ ! $(expr "${FILENAME}" : ".*\.[tf|tf.json]") = "0" ]; then | ||
# fmt them | ||
RESULT=$(./terraform fmt ${FILENAME} 2> /dev/null || echo "error") | ||
if [ "${RESULT}" = "${FILENAME}" ] || [ "${RESULT}" = "error" ]; then | ||
FAILED="true" | ||
echo "${FILENAME} failed" | ||
else | ||
echo "${FILENAME} is ok" | ||
fi | ||
fi | ||
done | ||
|
||
if [ "$FAILED" = "true" ] ; then | ||
# output the git diff | ||
echo "::set-output name=diff::$(git diff $(git diff --name-only HEAD HEAD~1))" | ||
exit 1 | ||
fi | ||
exit 0 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform { | ||
required_version = ">= 0.12.26" | ||
} |