From b31c5ba8eecf3d7a6fed9c1b571aef5eff35e782 Mon Sep 17 00:00:00 2001 From: Heather Lanigan Date: Tue, 22 Oct 2024 11:22:28 +0200 Subject: [PATCH] chore: testing github runners --- .github/workflows/build.yml | 114 ----------- .github/workflows/cla.yml | 16 -- .github/workflows/k8s_tunnel.yml | 198 ------------------- .github/workflows/release.yml | 42 ---- .github/workflows/static-analysis.yaml | 17 -- .github/workflows/test_add_machine.yml | 126 ------------ .github/workflows/test_integration.yml | 2 +- .github/workflows/test_integration_jaas.yaml | 101 ---------- .github/workflows/unit_test.yaml | 44 ----- 9 files changed, 1 insertion(+), 659 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/cla.yml delete mode 100644 .github/workflows/k8s_tunnel.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/static-analysis.yaml delete mode 100644 .github/workflows/test_add_machine.yml delete mode 100644 .github/workflows/test_integration_jaas.yaml delete mode 100644 .github/workflows/unit_test.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index bf61e395..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,114 +0,0 @@ -# Terraform Provider testing workflow using different terraform versions -# and clouds. - -name: Build - -# This GitHub action runs your tests for each pull request. -on: - pull_request: - types: [opened, synchronize, reopened, ready_for_review] -# paths-ignore: -# DON'T SET - these are "required" so they need to run on every PR - push: - branches: - - "main" - -# Testing only needs permissions to read the repository contents. -permissions: - contents: read - -jobs: - # Ensure project builds before running testing matrix - go-install: - name: install - runs-on: [self-hosted, jammy] - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: go mod tidy - - run: go install - - # Ensure the generated docs are up todate - generate: - runs-on: [self-hosted, jammy] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: "1.9.*" - terraform_wrapper: false - - run: go generate ./... - - name: git diff - run: | - git diff --compact-summary --exit-code || \ - (echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) - - # Ensure the go code is formatted properly - format: - runs-on: [self-hosted, jammy] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: gofmt -w -l -s . - - name: git diff - run: | - git diff --compact-summary --exit-code || \ - (echo; echo "Unexpected difference in directories after go fmt. Run 'gofmt -w -l -s .' command and commit."; exit 1) - - - # This runs golangci-lint against the codebase - lint: - name: golangci-lint - runs-on: [self-hosted, jammy] - steps: - - uses: actions/checkout@v4 - - name: Determine which tests to run - uses: dorny/paths-filter@v3 - id: filter - with: - filters: | - go: - - '**.go' - - 'go.mod' - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: v1.54.0 - args: --print-issued-lines=true - - # This runs golangci-lint against the codebase - copyright-check: - name: copyright-check - runs-on: [self-hosted, jammy] - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: false - - run: | - OUT=$(find . -name '*.go' | sort | xargs grep -L -E '// (Copyright|Code generated)' || true) - LINES=$(echo "${OUT}" | wc -w) - if [ "$LINES" != 0 ]; then - echo "" - echo "$(red 'Found some issues:')" - echo -e '\nThe following files are missing copyright headers' - echo "${OUT}" - exit 1 - fi - diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml deleted file mode 100644 index 04301a0f..00000000 --- a/.github/workflows/cla.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: "CLA check" -on: [pull_request, workflow_dispatch] - -permissions: - contents: read - -jobs: - cla-check: - permissions: - pull-requests: write # for canonical/has-signed-canonical-cla to create & update comments - runs-on: [self-hosted, jammy] - steps: - - name: Check if CLA signed - uses: canonical/has-signed-canonical-cla@1.2.3 - with: - accept-existing-contributors: true diff --git a/.github/workflows/k8s_tunnel.yml b/.github/workflows/k8s_tunnel.yml deleted file mode 100644 index d53b9acc..00000000 --- a/.github/workflows/k8s_tunnel.yml +++ /dev/null @@ -1,198 +0,0 @@ -name: Tunnel to Juju controller via load balancer on k8s - -on: - pull_request: - paths-ignore: - - "README.md" - - "project-docs/**" - push: - branches: - - "main" - paths-ignore: - - "README.md" - - "project-docs/**" - -# Testing only needs permissions to read the repository contents. -permissions: - contents: read - -jobs: - # Ensure project builds before running testing matrix - build: - name: Build - runs-on: [self-hosted, jammy] - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: go build -v . - - # Run acceptance tests in a matrix with Terraform CLI versions - add-machine-test: - name: Add Machine - needs: build - runs-on: [self-hosted, jammy] - env: - ACTIONS_ALLOW_IPV6: false - strategy: - fail-fast: false - matrix: - # Only on lxd - cloud: - - "microk8s" - terraform: - - "1.9.*" - timeout-minutes: 60 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - # set up terraform - - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: ${{ matrix.terraform }} - terraform_wrapper: false - # set up snap, lxd, tox, Juju, bootstrap a controller, etc. - - name: Setup operator environment - uses: charmed-kubernetes/actions-operator@main - with: - provider: ${{ matrix.cloud }} - juju-channel: 2.9/stable - - run: go mod download - - name: "Bring up loadbalancer & access via terraform plan" - run: | - echo "Determine Juju details" - CONTROLLER=$(juju whoami --format yaml | yq .controller) - JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"') - JUJU_USERNAME=$(juju show-controller | yq .$CONTROLLER.account.user) - JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password) - JUJU_CA_CERT=$(juju show-controller | yq .$CONTROLLER.details.ca-cert | sed ':a;N;$!ba;s/\n/\\n/g') - - # Ensure Juju controller name - echo "Controller name: $CONTROLLER" - echo "Juju Username: $JUJU_USERNAME" - - # Enable Ingress in MicroK8s - sudo microk8s enable ingress - - # Determine a subnet for MetalLB - subnet="$(ip route get 1 | head -n 1 | awk '{print $7}' | awk -F. '{print $1 "." $2 "." $3 ".240/24"}')" - echo "MetalLB subnet: $subnet" - - # Add the current user to the microk8s group - echo "Adding current user to the microk8s group" - sudo usermod -a -G microk8s $(whoami) - chown -R $(whoami) ~/.kube - - # Apply changes to group membership - newgrp microk8s - /snap/microk8s/current/usr/bin/env - - # Enable MetalLB on MicroK8s - sudo microk8s enable metallb:$subnet - - namespace="controller-$CONTROLLER" - service_name="controller-service-lb" - - # Display services layout - echo "Services layout:" - sudo microk8s.kubectl get services -n $namespace - - # Create a LoadBalancer service - sudo microk8s.kubectl apply -f - <= 0.9.1\" - } - } - } - provider \"juju\" { - controller_addresses = \"$external_ip:17070\" - username = \"$JUJU_USERNAME\" - password = \"$JUJU_PASSWORD\" - ca_certificate = \"$JUJU_CA_CERT\" - } - - resource \"juju_model\" \"testmodel\" { - name = \"test-model\" - } - - resource \"juju_application\" \"testapp\" { - name = \"juju-qa-test\" - model = juju_model.testmodel.name - - charm { - name = \"juju-qa-test\" - } - } - " > ./terraform_config.tf - - echo "====== Using Terraform Config: ===========" - cat ./terraform_config.tf - echo "==========================================" - - # Initialize and apply Terraform - echo "Initializing Terraform..." - terraform init - echo "Planning Terraform changes..." - terraform plan - echo "Applying Terraform changes..." - terraform apply --auto-approve - - # Cleanup: Remove Terraform configuration file - rm ./terraform_config.tf diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 45878ab0..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,42 +0,0 @@ -# Terraform Provider release workflow. -name: Release - -# This GitHub action creates a release when a tag that matches the pattern -# "v*" (e.g. v0.1.0) is created. -on: - push: - tags: - - 'v*' - -# Releases need permissions to read and write the repository contents. -# GitHub considers creating releases and uploading assets as writing contents. -permissions: - contents: write - -jobs: - goreleaser: - runs-on: [self-hosted, jammy] - environment: Release Environment - steps: - - uses: actions/checkout@v4 - with: - # Allow goreleaser to access older tag information. - fetch-depth: 0 - - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - cache: true - - name: Import GPG key - id: import_gpg - uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # => v5 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.PASSPHRASE }} - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v6 - with: - args: release --clean - env: - # GitHub sets the GITHUB_TOKEN secret automatically. - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml deleted file mode 100644 index eb2f3e82..00000000 --- a/.github/workflows/static-analysis.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: "Static Analysis" -on: - push: - branches: [main] - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - -permissions: - contents: read - -jobs: - conventional-commits: - name: Check conventional commits - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: wagoid/commitlint-github-action@v6 diff --git a/.github/workflows/test_add_machine.yml b/.github/workflows/test_add_machine.yml deleted file mode 100644 index b6d06295..00000000 --- a/.github/workflows/test_add_machine.yml +++ /dev/null @@ -1,126 +0,0 @@ -# Terraform Provider testing workflow using different terraform versions -# on lxd. This action is specifically for testing manual provision. -# It sets up an external machine and adds it into the Juju model using -# terraform. -name: Manual machine provision - -on: - pull_request: - paths-ignore: - - "README.md" - - "project-docs/**" - - ".github/ISSUE_TEMPLATE/**" - - ".github/PULL_REQUEST_TEMPLATE.md" - push: - branches: - - "main" - paths-ignore: - - "README.md" - - "project-docs/**" - - ".github/ISSUE_TEMPLATE/**" - - ".github/PULL_REQUEST_TEMPLATE.md" - -# Testing only needs permissions to read the repository contents. -permissions: - contents: read - -jobs: - # Ensure project builds before running testing matrix - build: - name: Build - runs-on: [self-hosted, jammy] - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: go build -v . - - # Run acceptance tests in a matrix with Terraform CLI versions - add-machine-test: - name: Add Machine - needs: build - runs-on: [self-hosted, jammy] - env: - ACTIONS_ALLOW_IPV6: false - strategy: - fail-fast: false - matrix: - # Only on lxd - cloud: - - "lxd" - terraform: - - "1.9.*" - juju: - - "2.9/stable" - - "3/stable" - timeout-minutes: 60 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - # set up terraform - - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: ${{ matrix.terraform }} - terraform_wrapper: false - # set up snap, lxd, tox, Juju, bootstrap a controller, etc. - - name: Setup operator environment - uses: charmed-kubernetes/actions-operator@main - with: - provider: ${{ matrix.cloud }} - juju-channel: ${{ matrix.juju }} - - name: "Set environment to configure provider" - # language=bash - run: | - CONTROLLER=$(juju whoami --format yaml | yq .controller) - - echo "JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"')" >> $GITHUB_ENV - echo "JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.api-endpoints | yq -r '. | join(",")')" >> $GITHUB_ENV - echo "JUJU_USERNAME=$(juju show-controller | yq .$CONTROLLER.account.user)" >> $GITHUB_ENV - echo "JUJU_PASSWORD=$(cat ~/.local/share/juju/accounts.yaml | yq .controllers.$CONTROLLER.password)" >> $GITHUB_ENV - echo "JUJU_CA_CERT<> $GITHUB_ENV - juju show-controller | yq .$CONTROLLER.details.ca-cert >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - run: go mod download - - name: Create a new machine on lxd - run: | - /snap/bin/lxc launch ubuntu:22.04 mtest - echo "Waiting on the container to be up and ready" - while [[ -z $(lxc list --format=json | jq -r '.[] | select(.state.status == "Running") | .name' | grep mtest) ]]; do sleep 1; done - # Running status doesn't mean the network interface is up, so wait another 10 seconds - sleep 10 - echo "Container for test is ready" - - name: Final setup and test - env: - TF_ACC: "1" - TEST_CLOUD: ${{ matrix.cloud }} - run: | - # generate a new key pair and add it to the agent - ssh-keygen -t rsa -N "" -f ./test-add-machine - eval "$(ssh-agent -s)" - ssh-add ./test-add-machine - - # set the env variables - echo $(/snap/bin/lxc list mtest --format=json | jq -r '.[0].state.network.eth0.addresses[]') - export TEST_ADD_MACHINE_IP=$(/snap/bin/lxc list mtest --format=json | jq -r '.[0].state.network.eth0.addresses[] | select(.family == "inet").address') - export TEST_SSH_PUB_KEY_PATH=$(pwd)/test-add-machine.pub - export TEST_SSH_PRIV_KEY_PATH=$(pwd)/test-add-machine - echo "Testing with machine at $TEST_ADD_MACHINE_IP with keys $TEST_SSH_PUB_KEY_PATH and $TEST_SSH_PRIV_KEY_PATH" - - echo "Pushing the ssh public key at $TEST_SSH_PUB_KEY_PATH into the container" - /snap/bin/lxc file push $TEST_SSH_PUB_KEY_PATH mtest/home/ubuntu/.ssh/authorized_keys - - # to avoid the host key verification prompt - echo "adding the host fingerprint to known_hosts" - mkdir -p ~/.ssh - ssh-keyscan $TEST_ADD_MACHINE_IP >> ~/.ssh/known_hosts - - echo "Running the test" - cd ./internal/provider/ - go test ./... -timeout 30m -v -test.run TestAcc_ResourceMachine_AddMachine - timeout-minutes: 40 diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index 317397b2..8e816ec8 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -45,7 +45,7 @@ jobs: strategy: fail-fast: false matrix: - terraform: ["1.7.*", "1.8.*", "1.9.*"] + terraform: ["1.9.*"] action-operator: - { lxd-channel: "5.21/stable", cloud: "lxd", cloud-channel: "5.21", juju: "2.9" } - { lxd-channel: "5.21/stable", cloud: "lxd", cloud-channel: "5.21", juju: "3" } diff --git a/.github/workflows/test_integration_jaas.yaml b/.github/workflows/test_integration_jaas.yaml deleted file mode 100644 index 6209005c..00000000 --- a/.github/workflows/test_integration_jaas.yaml +++ /dev/null @@ -1,101 +0,0 @@ -# A similar set of tests to test_integration but against a JAAS controller -name: Integration tests with JAAS - -# This GitHub action runs your tests for each pull request. -on: - pull_request: - paths-ignore: - - "README.md" - - "project-docs/**" - - ".github/ISSUE_TEMPLATE/**" - - ".github/PULL_REQUEST_TEMPLATE.md" - push: - branches: - - "main" - paths-ignore: - - "README.md" - - "project-docs/**" - - ".github/ISSUE_TEMPLATE/**" - - ".github/PULL_REQUEST_TEMPLATE.md" - workflow_dispatch: - -# Testing needs read permission and access to Github's container registry to pull JIMM. -permissions: - contents: read - packages: read - -jobs: - # Ensure project builds before running test - build: - name: Build-JAAS - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: go build -v . - - test: - name: Integration-JAAS - needs: build - runs-on: ubuntu-latest - strategy: - fail-fast: false - timeout-minutes: 60 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: "1.9.*" - terraform_wrapper: false - # Starting JAAS will start the JIMM controller and dependencies and create a Juju controller on LXD and connect it to JIMM. - - name: Setup JAAS - uses: canonical/jimm/.github/actions/test-server@v3 - id: jaas - with: - jimm-version: v3.1.10 - juju-channel: 3/stable - ghcr-pat: ${{ secrets.GITHUB_TOKEN }} - - name: Setup microk8s for juju_kubernetes_cloud test - run: | - sudo snap install microk8s --channel=1.28-strict/stable - sudo usermod -a -G snap_microk8s $USER - sudo chown -R $USER ~/.kube - sudo microk8s.enable dns storage - sudo microk8s.enable dns local-storage - sudo -g snap_microk8s -E microk8s status --wait-ready --timeout=600 - echo "MICROK8S_CONFIG<> $GITHUB_ENV - sudo microk8s.config view >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - name: Create additional networks when testing with LXD - run: | - sudo lxc network create management-br ipv4.address=10.150.40.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false - sudo lxc network create public-br ipv4.address=10.170.80.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false - - name: "Set environment to configure provider" - # language=bash - run: | - CONTROLLER=$(juju whoami --format yaml | yq .controller) - - echo "IS_JAAS=true" >> $GITHUB_ENV - echo "JUJU_AGENT_VERSION=$(juju show-controller | yq .$CONTROLLER.details.agent-version |tr -d '"')" >> $GITHUB_ENV - echo "JUJU_CONTROLLER_ADDRESSES=$(juju show-controller | yq .$CONTROLLER.details.api-endpoints | yq -r '. | join(",")')" >> $GITHUB_ENV - echo "JUJU_CLIENT_ID=${{ steps.jaas.outputs.client-id }}" >> $GITHUB_ENV - echo "JUJU_CLIENT_SECRET=${{ steps.jaas.outputs.client-secret }}" >> $GITHUB_ENV - echo "JUJU_CA_CERT<> $GITHUB_ENV - echo "${{ steps.jaas.outputs.ca-cert }}" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - echo "TEST_MANAGEMENT_BR=10.150.40.0/24" >> $GITHUB_ENV - echo "TEST_PUBLIC_BR=10.170.80.0/24" >> $GITHUB_ENV - - run: go mod download - - env: - TF_ACC: "1" - TEST_CLOUD: "lxd" - run: go test -parallel 1 -timeout 40m -v -cover ./internal/provider/ - timeout-minutes: 40 diff --git a/.github/workflows/unit_test.yaml b/.github/workflows/unit_test.yaml deleted file mode 100644 index f5c7018e..00000000 --- a/.github/workflows/unit_test.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Terraform Provider testing workflow using different terraform versions -# and clouds. -name: Unit Tests - -# This GitHub action runs your tests for each pull request. -on: - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - # paths-ignore: - # DON'T SET - these are "required" so they need to run on every PR - push: - branches: - - "main" - -# Testing only needs permissions to read the repository contents. -permissions: - contents: read - -jobs: - # Ensure project builds before running unit tests - build: - name: Build - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: go build -v . - - # Run internal/juju unit tests - test: - name: Juju unit tests - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache: true - - run: make juju-unit-test