From 1d85b81ddfcd163844bfb6f90d55a621d71ea3cd Mon Sep 17 00:00:00 2001 From: Utku Ozdemir Date: Sun, 21 Apr 2024 21:00:03 +0200 Subject: [PATCH] ci: improve ci and builds Remove deprecated goreleaser config. Signed-off-by: Utku Ozdemir --- .github/workflows/build.yml | 62 ++++++++++++++++++++++++++++++----- .github/workflows/release.yml | 7 +++- .goreleaser.yml | 7 ++-- Taskfile.yml | 10 ++++++ 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77f4ac7f1..c672695ac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,14 @@ --- name: build +permissions: + # Required: allow read access to the content for analysis. + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + # Optional: Allow write access to checks to allow the action to annotate code in the PR. + checks: write + on: push: branches: @@ -36,14 +44,18 @@ jobs: build: runs-on: ubuntu-22.04 steps: + - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@v4.1.1 + - name: Install go uses: actions/setup-go@v5.0.0 with: go-version-file: go.mod + - name: Ensure go.mod is already tidied run: go mod tidy && git diff --no-patch --exit-code + - name: Run linters uses: golangci/golangci-lint-action@v4.0.0 with: @@ -51,6 +63,7 @@ jobs: version: v1.57.2 args: --timeout=10m0s install-mode: goinstall + - name: Build with Goreleaser if: ${{ always() }} uses: goreleaser/goreleaser-action@v5.0.0 @@ -58,20 +71,31 @@ jobs: # renovate: depName=goreleaser/goreleaser datasource=github-releases version: v1.25.1 args: build --snapshot --clean --single-target + test: runs-on: ubuntu-22.04 steps: + - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@v4.1.1 + - name: Install go uses: actions/setup-go@v5.0.0 with: go-version-file: go.mod - - name: Install richgo - # renovate: depName=kyoh86/richgo - run: go install github.com/kyoh86/richgo@v0.3.12 - - name: Install helm - run: curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + + - name: Set up gotestfmt + uses: gotesttools/gotestfmt-action@v2.2.0 + with: + # Optional: pass GITHUB_TOKEN to avoid rate limiting. + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install Helm + uses: azure/setup-helm@v4.2.0 + with: + # renovate: depName=cilium/cilium-cli datasource=github-releases + version: v3.14.4 + - name: Install cilium-cli env: # renovate: depName=cilium/cilium-cli datasource=github-releases @@ -88,15 +112,19 @@ jobs: # renovate: depName=kubernetes-sigs/kind datasource=github-releases version: v0.22.0 config: test/kind-config.yaml + - name: kind-1 - Create metallb-system namespace run: kubectl create namespace metallb-system --dry-run=client -oyaml | kubectl apply -f - + - name: kind-1 - Install allow-all network policies on system namespaces run: | kubectl -n kube-system apply -f test/netpol-allow-all.yaml kubectl -n local-path-storage apply -f test/netpol-allow-all.yaml kubectl -n metallb-system apply -f test/netpol-allow-all.yaml + - name: kind-1 - Install Cilium with default-deny policy run: cilium install --set policyEnforcementMode=always + - name: kind-1 - Install MetalLB env: # renovate: depName=metallb datasource=helm registryUrl=https://charts.bitnami.com/bitnami @@ -141,16 +169,19 @@ jobs: # renovate: depName=kubernetes-sigs/kind datasource=github-releases version: v0.22.0 config: test/kind-config.yaml + - name: kind-2 - Install allow-all network policies on system namespaces env: KUBECONFIG: /home/runner/.kube/kind-2.yaml run: | kubectl -n kube-system apply -f test/netpol-allow-all.yaml kubectl -n local-path-storage apply -f test/netpol-allow-all.yaml + - name: kind-2 - Install Cilium with default-deny policy env: KUBECONFIG: /home/runner/.kube/kind-2.yaml run: cilium install --set policyEnforcementMode=always + - name: kind-2 - Wait for all pods in the cluster to be ready env: KUBECONFIG: /home/runner/.kube/kind-2.yaml @@ -165,8 +196,23 @@ jobs: env: RICHGO_FORCE_COLOR: "1" PVMIG_TEST_EXTRA_KUBECONFIG: /home/runner/.kube/kind-2.yaml - run: richgo test -tags integration -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -timeout 20m -v ./... + run: | + set -euo pipefail + go test -json -v -tags integration -race -coverpkg=./... \ + -coverprofile=coverage.txt -covermode=atomic -timeout 20m -v ./... 2>&1 \ + | tee /tmp/gotest.log \ + | gotestfmt + - name: Send coverage uses: codecov/codecov-action@v4.3.0 with: files: coverage.txt + + # Upload the original test log to the artifacts + - name: Upload test log + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-log + path: /tmp/gotest.log + if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1002f50bd..a3f959d2d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,21 +10,25 @@ jobs: release: runs-on: ubuntu-22.04 steps: + - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@v4.1.1 with: # to be able to generate the full changelog: # https://github.com/goreleaser/goreleaser-action/issues/56#issuecomment-568718162 fetch-depth: 0 + - name: Setup Go uses: actions/setup-go@v5.0.0 with: go-version-file: go.mod + - name: Login to DockerHub uses: docker/login-action@v3.1.0 with: username: utkuozdemir password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: GoReleaser uses: goreleaser/goreleaser-action@v5.0.0 with: @@ -34,5 +38,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PRIVATE_ACCESS_TOKEN: ${{ secrets.PRIVATE_ACCESS_TOKEN }} + - name: Update new version in krew-index uses: rajatjindal/krew-release-bot@v0.0.46 diff --git a/.goreleaser.yml b/.goreleaser.yml index 2b693929b..58a148ad1 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -30,7 +30,6 @@ builds: archives: - id: pv-migrate-archive - rlcp: true # default name template except we use .Tag instead of .Version to keep the "v" prefix name_template: >- {{ .ProjectName }}_ @@ -107,14 +106,14 @@ docker_manifests: # disable: true brews: - - tap: + - repository: owner: utkuozdemir name: homebrew-pv-migrate token: "{{ .Env.PRIVATE_ACCESS_TOKEN }}" commit_author: name: Utku Ozdemir email: uoz@protonmail.com - folder: Formula + directory: Formula goarm: "7" homepage: https://github.com/utkuozdemir/pv-migrate description: Persistent volume migration plugin for Kubernetes @@ -128,7 +127,7 @@ brews: fish_completion.install "completions/pv-migrate.fish" scoops: - - bucket: + - repository: owner: utkuozdemir name: scoop-pv-migrate token: "{{ .Env.PRIVATE_ACCESS_TOKEN }}" diff --git a/Taskfile.yml b/Taskfile.yml index f62112f68..a699f139b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,6 +1,15 @@ version: "3" tasks: + install-tools: + desc: install tools + cmds: + - go install mvdan.cc/gofumpt@latest + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - go install github.com/goreleaser/goreleaser@latest + - go install github.com/daixiang0/gci@latest + - go install github.com/caarlos0/svu@latest + fmt: desc: format code vars: @@ -17,6 +26,7 @@ tasks: cmds: - golangci-lint run ./... - helm lint helm/pv-migrate + - goreleaser check clean: desc: clean