2022-01-14 17:47:02 +00:00
|
|
|
# Run secret-dependent e2e tests only after /ok-to-test-managed approval
|
2021-12-29 12:02:56 +00:00
|
|
|
on:
|
|
|
|
repository_dispatch:
|
2022-01-14 17:47:02 +00:00
|
|
|
types: [ok-to-test-managed-command]
|
2021-12-29 12:02:56 +00:00
|
|
|
|
|
|
|
env:
|
|
|
|
# Common versions
|
2022-09-06 17:46:36 +00:00
|
|
|
GO_VERSION: '1.19'
|
|
|
|
GINKGO_VERSION: 'v2.1.6'
|
2021-12-29 12:02:56 +00:00
|
|
|
DOCKER_BUILDX_VERSION: 'v0.4.2'
|
|
|
|
|
|
|
|
# Common users. We can't run a step 'if secrets.GHCR_USERNAME != ""' but we can run
|
|
|
|
# a step 'if env.GHCR_USERNAME' != ""', so we copy these to succinctly test whether
|
|
|
|
# credentials have been provided before trying to run steps that need them.
|
|
|
|
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
GCP_SM_SA_JSON: ${{ secrets.GCP_SM_SA_JSON}}
|
|
|
|
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID}}
|
|
|
|
TF_VAR_GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID}}
|
|
|
|
GCP_SM_SA_GKE_JSON: ${{ secrets.GCP_SM_SA_GKE_JSON}}
|
|
|
|
GCP_GKE_CLUSTER: test-cluster
|
|
|
|
GCP_GKE_ZONE: ${{ secrets.GCP_GKE_ZONE}}
|
|
|
|
GCP_GSA_NAME: ${{ secrets.GCP_GSA_NAME}} # Goolge Service Account
|
|
|
|
GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME}} # Kubernetes Service Account
|
|
|
|
TF_VAR_GCP_GSA_NAME: ${{ secrets.GCP_GSA_NAME}} # Goolge Service Account for tf
|
|
|
|
TF_VAR_GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME}} # Kubernetes Service Account for tf
|
2022-01-21 20:05:37 +00:00
|
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
|
|
AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
|
|
|
|
AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
|
|
|
|
AWS_REGION: "eu-west-1"
|
|
|
|
AWS_CLUSTER_NAME: "eso-e2e-managed"
|
|
|
|
TF_VAR_AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
|
|
|
|
TF_VAR_AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
|
|
|
|
TF_VAR_AWS_REGION: "eu-west-1"
|
|
|
|
TF_VAR_AWS_CLUSTER_NAME: "eso-e2e-managed"
|
|
|
|
|
2021-12-29 12:02:56 +00:00
|
|
|
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID}}
|
|
|
|
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET}}
|
|
|
|
TENANT_ID: ${{ secrets.TENANT_ID}}
|
|
|
|
VAULT_URL: ${{ secrets.VAULT_URL}}
|
|
|
|
|
|
|
|
name: e2e tests
|
|
|
|
|
|
|
|
jobs:
|
2022-01-21 20:05:37 +00:00
|
|
|
integration-managed:
|
2021-12-29 12:02:56 +00:00
|
|
|
runs-on: ubuntu-latest
|
2022-01-21 20:05:37 +00:00
|
|
|
if: github.event_name == 'repository_dispatch'
|
|
|
|
|
2021-12-29 12:02:56 +00:00
|
|
|
steps:
|
|
|
|
|
2022-01-25 07:12:35 +00:00
|
|
|
# create new status check for this specific provider
|
2022-02-14 08:05:09 +00:00
|
|
|
- uses: actions/github-script@v6
|
2022-01-25 07:12:35 +00:00
|
|
|
if: ${{ always() }}
|
|
|
|
env:
|
|
|
|
number: ${{ github.event.client_payload.pull_request.number }}
|
|
|
|
provider: ${{ github.event.client_payload.slash_command.args.named.provider }}
|
|
|
|
job: ${{ github.job }}
|
|
|
|
with:
|
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
script: |
|
2022-02-15 15:23:45 +00:00
|
|
|
const { data: pull } = await github.rest.pulls.get({
|
2022-01-25 07:12:35 +00:00
|
|
|
...context.repo,
|
|
|
|
pull_number: process.env.number
|
|
|
|
});
|
|
|
|
const ref = pull.head.sha;
|
|
|
|
console.log("\n\nPR sha: " + ref)
|
2022-02-15 15:08:41 +00:00
|
|
|
const { data: checks } = await github.rest.checks.listForRef({
|
2022-01-25 07:12:35 +00:00
|
|
|
...context.repo,
|
|
|
|
ref
|
|
|
|
});
|
|
|
|
const job_name = process.env.job + "-" + process.env.provider
|
|
|
|
console.log("\n\nPR CHECKS: " + checks)
|
|
|
|
const check = checks.check_runs.filter(c => c.name === job_name);
|
|
|
|
console.log("\n\nPR Filtered CHECK: " + check)
|
|
|
|
console.log(check)
|
2022-01-25 14:12:21 +00:00
|
|
|
if(check && check.length > 0){
|
2022-02-15 15:08:41 +00:00
|
|
|
const { data: result } = await github.rest.checks.update({
|
2022-01-25 07:12:35 +00:00
|
|
|
...context.repo,
|
|
|
|
check_run_id: check[0].id,
|
|
|
|
status: 'in_progress',
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
2022-02-15 15:08:41 +00:00
|
|
|
const { data: result } = await github.rest.checks.create({
|
2022-01-25 07:12:35 +00:00
|
|
|
...context.repo,
|
|
|
|
name: job_name,
|
2022-01-25 14:18:39 +00:00
|
|
|
head_sha: pull.head.sha,
|
2022-01-25 07:12:35 +00:00
|
|
|
status: 'in_progress',
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
2022-01-14 17:47:02 +00:00
|
|
|
# Check out merge commit
|
|
|
|
- name: Fork based /ok-to-test-managed checkout
|
2022-03-07 08:06:46 +00:00
|
|
|
uses: actions/checkout@v3
|
2022-01-14 17:47:02 +00:00
|
|
|
with:
|
|
|
|
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
|
2021-12-29 12:02:56 +00:00
|
|
|
|
|
|
|
- name: Fetch History
|
|
|
|
run: git fetch --prune --unshallow
|
|
|
|
|
|
|
|
- name: Setup Go
|
2022-04-11 08:06:16 +00:00
|
|
|
uses: actions/setup-go@v3
|
2021-12-29 12:02:56 +00:00
|
|
|
with:
|
|
|
|
go-version: ${{ env.GO_VERSION }}
|
|
|
|
|
|
|
|
- name: Find the Go Cache
|
|
|
|
id: go
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=build-cache::$(go env GOCACHE)"
|
|
|
|
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
|
|
|
|
- name: Cache the Go Build Cache
|
2022-03-28 08:07:03 +00:00
|
|
|
uses: actions/cache@v3
|
2021-12-29 12:02:56 +00:00
|
|
|
with:
|
|
|
|
path: ${{ steps.go.outputs.build-cache }}
|
|
|
|
key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
|
|
|
|
restore-keys: ${{ runner.os }}-build-unit-tests-
|
|
|
|
|
|
|
|
- name: Cache Go Dependencies
|
2022-03-28 08:07:03 +00:00
|
|
|
uses: actions/cache@v3
|
2021-12-29 12:02:56 +00:00
|
|
|
with:
|
|
|
|
path: ${{ steps.go.outputs.mod-cache }}
|
|
|
|
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
|
|
|
|
restore-keys: ${{ runner.os }}-pkg-
|
2022-01-21 20:05:37 +00:00
|
|
|
|
2021-12-29 12:02:56 +00:00
|
|
|
- name: Setup TFLint
|
2022-04-04 08:05:52 +00:00
|
|
|
uses: terraform-linters/setup-tflint@v2
|
2021-12-29 12:02:56 +00:00
|
|
|
with:
|
|
|
|
tflint_version: v0.28.0 # Must be specified. See: https://github.com/terraform-linters/tflint/releases for latest versions
|
|
|
|
|
|
|
|
- name: Run TFLint
|
|
|
|
run: find ${{ github.workspace }} | grep tf$ | xargs -n1 dirname | xargs -IXXX -n1 /bin/sh -c 'set -o errexit; cd XXX; pwd; tflint --loglevel=info .; cd - >/dev/null'
|
|
|
|
|
|
|
|
- name: Setup TF Gcloud Provider
|
2022-01-21 20:05:37 +00:00
|
|
|
if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
|
2021-12-29 12:02:56 +00:00
|
|
|
run: |-
|
|
|
|
mkdir -p terraform/gcp/secrets
|
|
|
|
echo ${GCP_SM_SA_GKE_JSON} > terraform/gcp/secrets/gcloud-service-account-key.json
|
|
|
|
|
2022-01-21 20:05:37 +00:00
|
|
|
- name: Show TF
|
2021-12-29 12:02:56 +00:00
|
|
|
run: |-
|
2022-01-21 20:05:37 +00:00
|
|
|
PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
|
|
|
|
make tf.show.${PROVIDER}
|
2021-12-29 12:02:56 +00:00
|
|
|
|
|
|
|
- name: Setup Infracost
|
2022-05-30 13:57:18 +00:00
|
|
|
uses: infracost/actions/setup@v2
|
2021-12-29 12:02:56 +00:00
|
|
|
with:
|
|
|
|
api-key: ${{ secrets.INFRACOST_API_KEY }}
|
|
|
|
|
2022-01-24 09:49:19 +00:00
|
|
|
- name: Generate Infracost JSON for provider
|
2022-06-21 21:56:23 +00:00
|
|
|
run: |
|
|
|
|
infracost breakdown \
|
|
|
|
--path terraform/${{github.event.client_payload.slash_command.args.named.provider}}/plan.json \
|
|
|
|
--format json \
|
|
|
|
--out-file /tmp/infracost.json
|
2021-12-29 12:02:56 +00:00
|
|
|
|
|
|
|
- name: Post Infracost comment
|
2022-06-21 21:56:23 +00:00
|
|
|
run: |
|
|
|
|
infracost comment github --path=/tmp/infracost.json \
|
|
|
|
--repo=$GITHUB_REPOSITORY \
|
|
|
|
--github-token=${{ secrets.GITHUB_TOKEN }} \
|
|
|
|
--pull-request=${{ github.event.client_payload.pull_request.number }} \
|
|
|
|
--behavior=update
|
2021-12-29 12:02:56 +00:00
|
|
|
|
2022-01-21 20:05:37 +00:00
|
|
|
- name: Apply TF
|
2021-12-29 12:02:56 +00:00
|
|
|
run: |-
|
2022-01-21 20:05:37 +00:00
|
|
|
PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
|
|
|
|
make tf.apply.${PROVIDER}
|
|
|
|
|
|
|
|
- name: Setup gcloud CLI
|
|
|
|
if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
|
2022-03-23 10:50:46 +00:00
|
|
|
uses: google-github-actions/setup-gcloud@v0
|
2022-01-21 20:05:37 +00:00
|
|
|
with:
|
|
|
|
service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
|
|
|
|
project_id: ${{ env.GCP_PROJECT_ID }}
|
2021-12-29 12:02:56 +00:00
|
|
|
|
|
|
|
- name: Get the GKE credentials
|
2022-01-24 13:42:56 +00:00
|
|
|
if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
|
2021-12-29 12:02:56 +00:00
|
|
|
run: |-
|
|
|
|
gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
|
|
|
|
|
2022-01-21 20:05:37 +00:00
|
|
|
- name: Get the AWS credentials
|
|
|
|
if: github.event.client_payload.slash_command.args.named.provider == 'aws'
|
|
|
|
run: |-
|
|
|
|
aws --region $AWS_REGION eks update-kubeconfig --name $AWS_CLUSTER_NAME
|
|
|
|
|
2021-12-29 12:02:56 +00:00
|
|
|
- name: Login to Docker
|
2022-05-09 08:05:30 +00:00
|
|
|
uses: docker/login-action@v2
|
2021-12-29 12:02:56 +00:00
|
|
|
if: env.GHCR_USERNAME != ''
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
|
2022-01-21 20:05:37 +00:00
|
|
|
- name: Run managed e2e Tests
|
2021-12-29 12:02:56 +00:00
|
|
|
run: |
|
|
|
|
export PATH=$PATH:$(go env GOPATH)/bin
|
2022-01-21 20:05:37 +00:00
|
|
|
PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
|
2022-09-06 17:46:36 +00:00
|
|
|
go install github.com/onsi/ginkgo/v2/ginkgo@${{env.GINKGO_VERSION}}
|
2022-05-23 14:14:21 +00:00
|
|
|
make test.e2e.managed GINKGO_LABELS="${PROVIDER}" TEST_SUITES="provider"
|
2021-12-29 12:02:56 +00:00
|
|
|
|
2022-01-21 20:05:37 +00:00
|
|
|
- name: Destroy TF
|
2021-12-29 12:02:56 +00:00
|
|
|
if: always()
|
|
|
|
run: |-
|
2022-01-21 20:05:37 +00:00
|
|
|
PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
|
|
|
|
make tf.destroy.${PROVIDER}
|
2021-12-29 12:02:56 +00:00
|
|
|
|
2022-01-21 20:05:37 +00:00
|
|
|
# set status=completed
|
2022-02-14 08:05:09 +00:00
|
|
|
- uses: actions/github-script@v6
|
2021-12-29 12:02:56 +00:00
|
|
|
if: ${{ always() }}
|
|
|
|
env:
|
2022-01-24 13:05:37 +00:00
|
|
|
number: ${{ github.event.client_payload.pull_request.number }}
|
2022-01-25 07:12:35 +00:00
|
|
|
provider: ${{ github.event.client_payload.slash_command.args.named.provider }}
|
2021-12-29 12:02:56 +00:00
|
|
|
job: ${{ github.job }}
|
|
|
|
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
|
|
|
|
conclusion: ${{ job.status }}
|
|
|
|
with:
|
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
script: |
|
2022-02-15 15:08:41 +00:00
|
|
|
const { data: pull } = await github.rest.pulls.get({
|
2021-12-29 12:02:56 +00:00
|
|
|
...context.repo,
|
|
|
|
pull_number: process.env.number
|
|
|
|
});
|
|
|
|
const ref = pull.head.sha;
|
|
|
|
console.log("\n\nPR sha: " + ref)
|
2022-02-15 15:08:41 +00:00
|
|
|
const { data: checks } = await github.rest.checks.listForRef({
|
2021-12-29 12:02:56 +00:00
|
|
|
...context.repo,
|
|
|
|
ref
|
|
|
|
});
|
2022-01-25 07:12:35 +00:00
|
|
|
const job_name = process.env.job + "-" + process.env.provider
|
2021-12-29 12:02:56 +00:00
|
|
|
console.log("\n\nPR CHECKS: " + checks)
|
2022-01-25 07:12:35 +00:00
|
|
|
const check = checks.check_runs.filter(c => c.name === job_name);
|
2021-12-29 12:02:56 +00:00
|
|
|
console.log("\n\nPR Filtered CHECK: " + check)
|
|
|
|
console.log(check)
|
2022-02-15 15:08:41 +00:00
|
|
|
const { data: result } = await github.rest.checks.update({
|
2021-12-29 12:02:56 +00:00
|
|
|
...context.repo,
|
|
|
|
check_run_id: check[0].id,
|
|
|
|
status: 'completed',
|
|
|
|
conclusion: process.env.conclusion
|
|
|
|
});
|
|
|
|
return result;
|