Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Actions Integration Tests #2326

Merged
merged 22 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
40223df
Add GitHub Actions for Linux Integration Test with latest CAPI
moleske Sep 29, 2022
60c9b2f
You apparently can't reference things outside of workflows for uses
moleske Sep 29, 2022
1ab5d26
Use environment name as identifier for metadata instead of hardcoding
moleske Sep 30, 2022
b0febe2
Apparently you can't have any nested folders with workflows in github…
moleske Sep 30, 2022
f970649
inline url cause actions not happy with extraction
moleske Sep 30, 2022
32a0e8d
Separate tools installation from claim environment
moleske Sep 30, 2022
ea9bed2
Remove unneeded && \
moleske Sep 30, 2022
c922064
Intelligent toolsmith error handling
a-b Sep 30, 2022
6aa2017
Make TOOLSMITHS_HOSTNAME secret
a-b Sep 30, 2022
e7bc25b
Use correct path for aws install
moleske Oct 3, 2022
d5a886c
Use output of step instead of job for setup-cf-env
moleske Oct 3, 2022
54e4b9f
Add step output to setup cf env
moleske Oct 4, 2022
d966089
remove aws cli install
moleske Oct 4, 2022
86fa39a
Use /usr/local/bin for bosh
moleske Oct 4, 2022
acba28b
use /usr/local/bin for bosh
moleske Oct 4, 2022
1fdabae
extract credhub to tmp and then move to /usr/local/bin
moleske Oct 5, 2022
d3c5b7a
write credhub.tgz to home directory
moleske Oct 5, 2022
2bbfdfc
Delets unecessary line
Oct 5, 2022
4b8f3cc
don't need to cd into cli as that's what checkout does
moleske Oct 6, 2022
8f16cc5
Add built cli to path
moleske Oct 7, 2022
eb2705e
remove oidc credentials
moleske Oct 12, 2022
f3209f4
force unclaim to only run after run-integration-tests
moleske Oct 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Integration Tests

on:
workflow_dispatch:
pull_request:
branches:
- master
- v8
- v7
paths-ignore:
- 'doc/**'
- '.github/**'
- '.gitpod.yml'
- 'README.md'
push:
branches:
- master
- v8
- v7
paths-ignore:
- 'doc/**'
- '.github/**'
- '.gitpod.yml'
- 'README.md'

permissions:
contents: read

jobs:
shared-values:
name: Shared Values
runs-on: ubuntu-latest
outputs:
secrets-environment: ${{ steps.set-secrets-environment.outputs.secrets-environment }}
go-version: ${{ steps.set-go-version.outputs.go-version }}

steps:
- name: Checkout
uses: actions/checkout@v3

- id: set-secrets-environment
name: Set environment
run: echo "::set-output name=secrets-environment::PROD"

- id: set-go-version
name: Parse Golang Version
run: |
go_version=($(grep -E '^go 1\.[[:digit:]]{1,2}' go.mod))
echo "golang version: ${go_version[1]}"
echo "::set-output name=go-version::${go_version[1]}"

get-linux-env-with-edge-capi:
needs: shared-values
uses: ./.github/workflows/setup-cf-env.yml
with:
environment: ${{ needs.shared-values.outputs.secrets-environment }}
capi-version: edge
secrets: inherit

run-integration-tests-linux-env-with-edge-capi:
needs:
- shared-values
- get-linux-env-with-edge-capi
runs-on: ubuntu-latest
environment: ${{ needs.shared-values.outputs.secrets-environment }}

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Up Go
uses: actions/setup-go@v3
with:
go-version: ${{ needs.shared-values.outputs.go-version}}
check-latest: true
- name: Download metadata
uses: actions/download-artifact@v3
with:
name: ${{ needs.get-linux-env-with-edge-capi.outputs.environment-name }}
- name: Install Tools
run: |
wget https://github.com/cloudfoundry/bosh-bootloader/releases/download/v8.4.110/bbl-v8.4.110_linux_x86-64 -P /tmp
mv /tmp/bbl-* /usr/local/bin/bbl
chmod +x /usr/local/bin/bbl
bbl --version

wget https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-7.0.1-linux-amd64 --output-document="/usr/local/bin/bosh"
chmod +x /usr/local/bin/bosh
bosh --version

wget https://github.com/cloudfoundry/credhub-cli/releases/download/2.9.4/credhub-linux-2.9.4.tgz -P ~/
tar xzvf ~/credhub-linux-2.9.4.tgz
mv credhub /usr/local/bin/credhub
chmod +x /usr/local/bin/credhub
credhub --version
rm ~/credhub-linux-2.9.4.tgz
- name: Run Integration Tests
run: |
ENV=$(cat metadata.json | jq -r '.name')
eval "$(bbl print-env --metadata-file ./metadata.json)"
export CF_INT_PASSWORD="$(credhub get -n /bosh-$ENV/cf/cf_admin_password | bosh interpolate --path /value -)"
export CF_INT_API="https://api.${ENV}.cf-app.com"
export CF_DIAL_TIMEOUT=15
export CF_USERNAME=admin
export FLAKE_ATTEMPTS=2
export NODES=16
go install github.com/onsi/ginkgo/ginkgo@v1.16.4

make build
export PATH="$(pwd)/out:$PATH"
make integration-tests-full-ci

unclaim-linux-env-with-edge-capi:
needs:
- shared-values
- get-linux-env-with-edge-capi
- run-integration-tests-linux-env-with-edge-capi
if: always()
uses: ./.github/workflows/unclaim-cf-env.yml
with:
environment: ${{ needs.shared-values.outputs.secrets-environment }}
identifier-for-metadata-file: ${{ needs.get-linux-env-with-edge-capi.outputs.environment-name }}
secrets: inherit
95 changes: 95 additions & 0 deletions .github/workflows/setup-cf-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Setup CF Environment

on:
workflow_call:
inputs:
environment:
required: true
type: string
capi-version:
required: true
type: string
outputs:
environment-name:
description: "Name of claimed environment"
value: ${{ jobs.setup-cf-env.outputs.environment-name }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be ${{ steps.claim-toolsmiths-env.outputs.environment-name }} as we want the output of the step, not an out put of the job. See this for original issue


jobs:
setup-cf-env:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
environment-name: ${{ steps.claim-toolsmiths-env.outputs.environment-name }}
steps:
- id: claim-toolsmiths-env
name: Claim Toolsmiths Environment
env:
api_token: ${{ secrets.TOOLSMITHS_API_TOKEN }}
hostname: ${{ secrets.TOOLSMITHS_HOSTNAME }}
notes: CF CLI Github Actions Integration Tests
pool_name: cf-deployment
run: |
while true; do
curl -s --show-error -D >(tee headers.txt >&2) -H 'Accept: application/json' \
-X POST "https://${hostname}/pooled_gcp_engineering_environments/claim" \
--data-urlencode "api_token=${api_token}" \
--data-urlencode "pool_name=${pool_name}" \
--data-urlencode "notes=${notes}" > metadata.json \
|| echo "Unable to reach server, trying again in 30 seconds..."

ERR_500="Sorry, the Toolsmiths Environments app is currently encountering issues. Trying again in 30 seconds..."
ERR_429="Sorry, Toolsmiths are out of environments in your requested pool. New environments are on their way but you can stop by the Toolsmiths slack channel for more help."
ERR_409="Sorry, was not able to claim an environment. Trying again in 30 seconds..."

grep -q -E "HTTP/[[:digit:]\.]{1,3} 401" headers.txt && exit 1
grep -q -E "HTTP/[[:digit:]\.]{1,3} 404" headers.txt && exit 2
grep -q -E "HTTP/[[:digit:]\.]{1,3} 500" headers.txt && echo "$ERR_500"
grep -q -E "HTTP/[[:digit:]\.]{1,3} 200" headers.txt && break
grep -q -E "HTTP/[[:digit:]\.]{1,3} 429" && echo "$ERR_429"
grep -q -E "HTTP/[[:digit:]\.]{1,3} 409" && echo "$ERR_409"

sleep 30
done

ENV=$(cat metadata.json | jq -r '.name')
echo "::set-output name=environment-name::${ENV}"

- name: 'Upload Metadata'
uses: actions/upload-artifact@v3
with:
name: ${{ steps.claim-toolsmiths-env.outputs.environment-name }}
path: metadata.json

- name: Checkout cli-ci
uses: actions/checkout@v3
with:
repository: cloudfoundry/cli-ci
path: cli-ci

- name: Install Tools
run: |
wget https://github.com/cloudfoundry/bosh-bootloader/releases/download/v8.4.110/bbl-v8.4.110_linux_x86-64 -P /tmp
mv /tmp/bbl-* /usr/local/bin/bbl
chmod +x /usr/local/bin/bbl
bbl --version

wget https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-7.0.1-linux-amd64 --output-document="/usr/local/bin/bosh"
chmod +x /usr/local/bin/bosh
bosh --version

- name: Deploy edge CAPI
if: ${{ inputs.capi-version == 'edge' }}
run: |
# find latest capi
FILENAME="$(aws s3 ls capi-releases --no-sign-request --recursive --region us-east-1 | sort | tail -n 1 | awk '{print $4}')"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this means it is possible to have the same release version and we're just grabbing the latest? Or that since this is edge just always grab the latest and we don't actually know the latest version of capi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know what the latest edge is, we just grab it. This is from the output of capi-create-release, which passed unit tests but has not passed integration tests

Future PRs will allow specification of CAPI, to support running tests with a minimum supported version of CAPI

aws s3 cp s3://capi-releases/$FILENAME $FILENAME --no-sign-request --region us-east-1
eval "$(bbl print-env --metadata-file metadata.json)"
bosh upload-release --sha2 "$FILENAME"
rm $FILENAME

# deploy
bosh -d cf manifest > /tmp/manifest.json
bosh -d cf deploy /tmp/manifest.json -o cli-ci/ci/infrastructure/operations/use-latest-capi.yml -n

echo "Deployed CAPI version:"
bosh -d cf releases | grep capi
43 changes: 43 additions & 0 deletions .github/workflows/unclaim-cf-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Unclaim an environment

on:
workflow_call:
inputs:
environment:
required: true
type: string
identifier-for-metadata-file:
required: true
type: string

jobs:
build-env:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}

steps:
- name: Download metadata
uses: actions/download-artifact@v3
with:
name: ${{ inputs.identifier-for-metadata-file }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some testing in a private space seems to indicate that this line is not quite correct. I'm getting a problem where this input is empty ('') causing all artifacts to be downloaded, which results in a pathing problem. For example, if the environment name is rosebud then instead of downloading just the metadata json file, it puts in the json file in a directory called rosebud. This causes the next step to fail on cat metadata.json | jq -r .name as the file is actually rosebud/metadata.json

I'm hoping I'm just not seeing something silly, like the input is badly passed in integration.yml or incorrectly exported out setup-cf-env.yml

github docs for reference on anyone trying to help

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thinking harder for a few minutes, the problem is actually over here


- name: Unclaim environment
env:
api_token: ${{ secrets.TOOLSMITHS_API_TOKEN }}
hostname: ${{ secrets.TOOLSMITHS_HOSTNAME }}
run: |
env_name=$(cat metadata.json | jq -r .name)

while true; do
output=$(curl -s --show-error -D >(tee headers.txt >&2) -H 'Accept: application/json' \
-X POST "https://${hostname}/pooled_gcp_engineering_environments/unclaim" \
--data-urlencode "api_token=${api_token}" \
--data-urlencode "name=${env_name}")

ERR_500="Sorry, the Toolsmiths Environments app is currently encountering issues. Trying again in 30 seconds..."

grep -q -E "HTTP/[[:digit:]\.]{1,3} 500" headers.txt && echo "$ERR_500" && sleep 30 && continue
grep -q -E "HTTP/[[:digit:]\.]{1,3} 401" headers.txt && echo $(echo "$output" | jq '.messages | join(", ")') && exit 1
grep -q -E "HTTP/[[:digit:]\.]{1,3} 404" headers.txt && echo $(echo "$output" | jq '.messages | join(", ")') && exit 2
grep -q -E "HTTP/[[:digit:]\.]{1,3} 202" headers.txt && break
done