Skip to content

Commit

Permalink
Merge pull request #48 from hivelocity/e2e-tests
Browse files Browse the repository at this point in the history
🌱 e2e tests
  • Loading branch information
guettli authored Jun 7, 2023
2 parents 80f850c + e41afb5 commit 1e3f934
Show file tree
Hide file tree
Showing 64 changed files with 5,093 additions and 350 deletions.
1 change: 1 addition & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# https://direnv.net/
export HIVELOCITY_API_KEY=...
export KUBECONFIG=$PWD/.mgt-cluster-kubeconfig.yaml
65 changes: 65 additions & 0 deletions .github/actions/e2e/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "E2E Test"
description: "Runs the e2e test"
inputs:
e2e_name:
description: "e2e_name"
required: true
e2e_make_target:
description: "e2e_make_target"
required: true
e2e_hivelocity_api_key:
description: "e2e_hivelocity_api_key"
required: true
e2e_ssh_pub:
description: "e2e_ssh_pub"
required: false
runs:
using: "composite"
steps:
- uses: ./.github/actions/setup-go
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: hack/tools/bin
key: ${{ runner.os }}-tools-bin-e2e-${{ hashFiles('Makefile') }}
restore-keys: |
${{ runner.os }}-tools-bin-e2e-
${{ runner.os }}-tools-bin-
- name: Download artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3
with:
name: test-release
path: out

- name: Generate metadata
id: meta
uses: ./.github/actions/metadata
with:
metadata_flavor: ${{ env.metadata_flavor }}
metadata_tags: ${{ env.metadata_tags }}

- name: Prepull the pre-built image
shell: bash
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}
env:
TAG: ${{ steps.meta.outputs.version }}

- name: "e2e-${{ inputs.e2e_name }}"
shell: bash
env:
CI: "true"
REGISTRY: ${{ env.REGISTRY }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
TAG: ${{ steps.meta.outputs.version }}
E2E_CONF_FILE_SOURCE: "${{ github.workspace }}/test/e2e/config/hivelocity-ci.yaml"
MANIFEST_PATH: "../../../out"
HIVELOCITY_API_KEY: ${{ env.HIVELOCITY_API_KEY }}
HIVELOCITY_SSH_PUB: ${{ inputs.e2e_ssh_pub }}
SKIP_IMAGE_BUILD: "1"
CAPHV_LATEST_VERSION: "v1.0.0-alpha.1"
run: make ${{ inputs.e2e_make_target }}
- name: Upload artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3
if: ${{ always() }}
with:
name: e2e-${{ inputs.e2e_name }}
path: _artifacts
65 changes: 65 additions & 0 deletions .github/actions/manager-image/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Manager Image"
description: "Build and Push Manager Image"
inputs:
registry_password:
description: "registry_password"
required: true
runs:
using: "composite"
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2.5.0

- name: Login to ghcr.io for CI
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ env.registry_password }}

- name: Generate metadata
id: meta
uses: ./.github/actions/metadata
with:
metadata_flavor: ${{ env.metadata_flavor }}
metadata_tags: ${{ env.metadata_tags }}

# Load Golang cache build from GitHub
- name: Load caphv Golang cache build from GitHub
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
id: cache
with:
path: /tmp/.cache/caphv
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-caphv-${{ github.sha }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-caphv-
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-go-
- name: Create caphv cache directory
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
mkdir -p /tmp/.cache/caphv
# Import GitHub's cache build to docker cache
- name: Copy caphv Golang cache to docker cache
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0
with:
provenance: false
context: /tmp/.cache/caphv
file: ./images/cache/Dockerfile
push: false
platforms: linux/amd64
target: import-cache

- name: Build and push manager image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4
with:
provenance: false
context: .
push: true
file: ./images/caphv/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
31 changes: 31 additions & 0 deletions .github/actions/test-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Test Release"
description: "Testing Release"
runs:
using: "composite"
steps:
- uses: ./.github/actions/setup-go
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: hack/tools/bin
key: ${{ runner.os }}-tools-bin-release-${{ hashFiles('Makefile') }}
restore-keys: |
${{ runner.os }}-tools-bin-release-
${{ runner.os }}-tools-bin-
- name: Generate metadata
id: meta
uses: ./.github/actions/metadata
with:
metadata_flavor: ${{ env.metadata_flavor }}
metadata_tags: ${{ env.metadata_tags }}

- name: Test Release
shell: bash
env:
TAG: ${{ steps.meta.outputs.version }}
run: make test-release
- name: Upload artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3
with:
name: test-release
path: out
74 changes: 74 additions & 0 deletions .github/workflows/pr-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: E2E PR Blocking
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
- e2e-tests
- "releases/**"
paths:
- "**.go"
- "**go.mod"
- "**go.sum"
- "<templates|test>/**/*.<yml|yaml>"
- ".github/actions/**/*"
- ".github/workflows/e2e-*"
- ".github/workflows/pr-*"
- "images/caphv/**"
- "!**/vendor/**"
env:
IMAGE_NAME: caphv-staging
REGISTRY: ghcr.io/hivelocity
metadata_flavor: latest=false
metadata_tags: type=ref,event=pr
registry_password: ${{ secrets.GITHUB_TOKEN }}
jobs:
manager-image:
name: Build and push manager image
if: github.event_name != 'pull_request_target' || !github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Build and push manager image
id: manager-image
uses: ./.github/actions/manager-image

test-release:
name: Create a Test Release
if: github.event_name != 'pull_request_target' || !github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Test Release
id: manager-image
uses: ./.github/actions/test-release

e2e-basic:
name: End-to-End Test Basic
if: github.event_name != 'pull_request_target' || !github.event.pull_request.draft
concurrency: ci-${{ github.ref }}-e2e-basic
runs-on: ubuntu-latest
needs:
- manager-image
- test-release
steps:
- name: checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run e2e Test
id: e2e
uses: ./.github/actions/e2e
with:
e2e_name: e2e-basic
e2e_make_target: test-e2e
e2e_hivelocity_api_key: ${{ secrets.HIVELOCITY_API_KEY }}
e2e_ssh_pub: ${{ secrets.HIVELOCITY_SSH_PUB }}
2 changes: 1 addition & 1 deletion .github/workflows/pr-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
with:
go-version: "^1.19"
- name: Test
run: make test
run: make test-unit
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ vendor
_artifacts
resp.json
**manifest.json
.coverage
test/e2e/config/hivelocity-ci-envsubst.yaml
test/e2e/ginkgo-log.txt

# release artifacts
out
Expand All @@ -79,4 +82,4 @@ tmp_*

# generated kube-configs
.workload-cluster-kubeconfig.yaml
.mgt-cluster-kube-config.yaml
.mgt-cluster-kubeconfig.yaml
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- govet
- importas
- ineffassign
- loggercheck
- misspell
- nakedret
- nilerr
Expand Down
Loading

0 comments on commit 1e3f934

Please sign in to comment.