Skip to content

Commit

Permalink
Add the Terratest E2E test work to the CI pipeline (#95)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff McCoy <code@jeffm.us>
  • Loading branch information
RothAndrew authored and jeff-mccoy committed Oct 7, 2021
1 parent 28bc7a7 commit 55d584f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
79 changes: 36 additions & 43 deletions .github/workflows/test-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
run-ping: ${{ steps.parse.outputs.ping }}
run-hello: ${{ steps.parse.outputs.hello }}
run-quote: ${{ steps.parse.outputs.quote }}
run-e2e: ${{ steps.parse.outputs.e2e }}
steps:
- name: Parse Args
id: parse
Expand All @@ -32,7 +31,7 @@ jobs:
ARGS="${ARGS_V1}${ARGS_V2}"
printf "Args are %s\n" "$ARGS"
printf "\n\nslash_command is %s\n\n" "$DEBUG"
COMMANDS=(PING HELLO QUOTE)
COMMANDS=(PING E2E)
if printf "%s" "${ARGS^^}" | grep -qE '\bALL\b'; then
# "all" explicitly does not include "ping"
for cmd in "${COMMANDS[@]}"; do
Expand Down Expand Up @@ -71,11 +70,12 @@ jobs:
GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }}
GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }}

# Do a "hello world" example pipeline run
hello:
# Run E2E tests
e2e:
runs-on: ubuntu-latest
needs: parse
if: needs.parse.outputs.run-hello == 'true'
if: needs.parse.outputs.run-e2e == 'true'
container: cloudposse/test-harness:latest
steps:
# Update GitHub status for pending pipeline run
- name: "Update GitHub Status for pending"
Expand All @@ -85,7 +85,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_STATE: pending
GITHUB_CONTEXT: "/test hello"
GITHUB_CONTEXT: "/test e2e"
GITHUB_DESCRIPTION: "started by @${{ github.event.client_payload.github.actor }}"
GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }}
Expand All @@ -99,20 +99,33 @@ jobs:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

# Echo "Hello world!"
- name: "Echo something"
run: |
echo "Hello world!"
# # Throw a failure to test fail conditions
# - name: "Fail"
# run: |
# exit 1
# # Checkout the code from GitHub Pull Request
# - name: "Checkout the code"
# uses: actions/checkout@v2
# with:
# token: ${{ secrets.PAT }}
# repository: defenseunicorns/zarf
# ref: feature/add-terratest-e2e-to-pipeline

# # Wait a long time to give the dev time to test cancel conditions
# - name: "Wait"
# run: |
# sleep 600
- name: "Run E2E tests"
shell: bash -x -e -o pipefail {0}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_DEFENSEUNICORNS_COMMERCIAL_SA_ZARF }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEFENSEUNICORNS_COMMERCIAL_SA_ZARF }}
AWS_DEFAULT_REGION: us-east-1
run: |
# cloudposse/test-harness has golang 1.15, we need 1.16. This is the easiest way I know to do it. This should definitely be revisited and cleaned up.
git clone --branch v0.8.0 --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf
source ~/.asdf/asdf.sh
export PATH="$HOME/.asdf/bin:$PATH"
asdf plugin-add golang https://github.com/kennyp/asdf-golang.git
asdf install golang 1.16.7
asdf global golang 1.16.7
export GOPATH="$HOME/go"
export PATH="$PATH:$GOPATH/bin"
make build-cli-linux
./build/zarf tools registry login registry1.dso.mil --username "${{ secrets.REGISTRY1_USERNAME_ROTHANDREW2 }}" --password "${{ secrets.REGISTRY1_PASSWORD_ROTHANDREW2 }}"
make init-package test-e2e
# Update GitHub status for failing pipeline run
- name: "Update GitHub Status for failure"
Expand All @@ -123,7 +136,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_STATE: failure
GITHUB_CONTEXT: "/test hello"
GITHUB_CONTEXT: "/test e2e"
GITHUB_DESCRIPTION: "run failed"
GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }}
Expand All @@ -137,7 +150,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_STATE: success
GITHUB_CONTEXT: "/test hello"
GITHUB_CONTEXT: "/test e2e"
GITHUB_DESCRIPTION: "run passed"
GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }}
Expand All @@ -152,28 +165,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_STATE: error
GITHUB_CONTEXT: "/test hello"
GITHUB_CONTEXT: "/test e2e"
GITHUB_DESCRIPTION: "run cancelled"
GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }}
GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }}

# Add a quote to the status section
quote:
runs-on: ubuntu-latest
needs: parse
if: needs.parse.outputs.run-quote == 'true'
steps:
# Update GitHub status
- name: "Update GitHub Status for successful pipeline run"
uses: "docker://cloudposse/github-status-updater"
with:
args: "-action update_state -ref ${{ github.event.client_payload.pull_request.head.sha }} -repo ${{ github.event.client_payload.github.payload.repository.name }}"
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GITHUB_STATE: success
GITHUB_CONTEXT: "/test quote"
GITHUB_DESCRIPTION: "Insanity is doing the same thing over and over and expecting different results."
GITHUB_TARGET_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_REF: ${{ github.event.client_payload.pull_request.head.ref }}
GITHUB_OWNER: ${{ github.event.client_payload.github.payload.repository.owner.login }}
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ e2e-ssh: ## Run this if you set SKIP_teardown=1 and want to SSH into the still-r
cd test/tf/public-ec2-instance/.test-data && cat Ec2KeyPair.json | jq -r .PrivateKey > privatekey.pem && chmod 600 privatekey.pem
cd test/tf/public-ec2-instance && ssh -i .test-data/privatekey.pem ubuntu@$$(terraform output public_instance_ip)

build-cli: ## Build the CLI
rm -fr build
clean: ## Clean the build dir
rm -rf build

build-cli-linux: ## Build the Linux CLI
cd cli && $(MAKE) build

build-cli-mac: ## Build the Mac CLI
cd cli && $(MAKE) build-mac

build-cli: clean build-cli-linux build-cli-mac ## Build the CLI

init-package: ## Create the zarf init package
$(ZARF_BIN) package create --confirm
mv zarf-init.tar.zst build

cd build && sha256sum -b zarf* > zarf.sha256
ls -lh build

Expand Down

0 comments on commit 55d584f

Please sign in to comment.