From 2edf7acf93773c77a611efef387199ba184f1539 Mon Sep 17 00:00:00 2001 From: Bence Csati Date: Mon, 2 Sep 2024 08:52:36 +0200 Subject: [PATCH] feat(ci): add release pipeline flow Signed-off-by: Bence Csati feat(ci): add release pipeline flow Signed-off-by: Bence Csati feat(ci): add release pipeline flow Signed-off-by: Bence Csati feat(ci): add release pipeline flow Signed-off-by: Bence Csati feat(ci): add release pipeline flow Signed-off-by: Bence Csati feat(ci): add release pipeline flow Signed-off-by: Bence Csati --- .github/workflows/artifacts.yaml | 131 ++++++++++++++++++ .github/workflows/ci.yaml | 88 ++---------- .github/workflows/release.yaml | 17 +++ internal/config/config_test.go | 1 - .../autocomplete/autocomplete_test.go | 3 +- .../autocomplete/filter/filteroptions_test.go | 3 +- 6 files changed, 161 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/artifacts.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/artifacts.yaml b/.github/workflows/artifacts.yaml new file mode 100644 index 0000000..3d05438 --- /dev/null +++ b/.github/workflows/artifacts.yaml @@ -0,0 +1,131 @@ +name: Artifacts + +on: + workflow_call: + inputs: + publish: + description: 'Publish artifacts' + required: true + default: false + type: boolean + +jobs: + container-image: + name: Container-Image + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up Cosign + if: ${{ inputs.publish }} + uses: sigstore/cosign-installer@v3.6.0 + + - name: Gather build metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + flavor: | + latest = false + tags: | + type=ref,event=branch + type=ref,event=pr,prefix=pr- + type=semver,pattern={{raw}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + if: ${{ inputs.publish }} + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Build Docker image + uses: docker/build-push-action@v6 + if: ${{ inputs.publish == false }} + with: + context: . + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=oci,dest=image.tar + + - name: Build and push Docker image + id: build + uses: docker/build-push-action@v6 + if: ${{ inputs.publish == true }} + with: + context: . + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=image, push=true + + - name: Sign image with GitHub OIDC Token + if: ${{ inputs.publish && github.repository_owner == 'csatib02' }} + env: + DIGEST: ${{ inputs.publish && steps.build.outputs.digest }} + TAGS: ${{ steps.meta.outputs.tags }} + run: | + images="" + for tag in ${TAGS}; do + images+="${tag}@${DIGEST} " + done + + cosign sign --yes ${images} + + - name: Upload image artifact + uses: actions/upload-artifact@v4 + with: + name: Kube-Pod-Autocomplete image + path: image.tar + + binary: + name: Binary + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: '.go-version' + + - name: Run GoReleaser ~ Build + uses: goreleaser/goreleaser-action@v6 + if : ${{ inputs.publish == false }} + with: + distribution: goreleaser + version: '~> v2' + args: release --skip=publish --snapshot + + - name: Run GoReleaser ~ Release + uses: goreleaser/goreleaser-action@v6 + if: ${{ inputs.publish == true }} + with: + distribution: goreleaser + version: '~> v2' + args: goreleaser release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: Kube-Pod-Autocomplete-Binary + path: build/dist diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4162256..7f2e4f8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -56,85 +56,6 @@ jobs: with: version: latest - artifacts-container-image: - name: Artifacts-Container-Image - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Gather build metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }} - flavor: | - latest = false - tags: | - type=ref,event=branch - type=ref,event=pr,prefix=pr- - type=semver,pattern={{raw}} - type=raw,value=latest,enable={{is_default_branch}} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ github.token }} - - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - outputs: type=oci, dest=image.tar - - - name: Upload image artifact - uses: actions/upload-artifact@v4 - with: - name: Kube-Pod-Autocomplete-Image - path: image.tar - - artifacts-binary: - name: Artifacts-Binary - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: '.go-version' - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v6 - with: - distribution: goreleaser - version: '~> v2' - args: release --skip=publish --snapshot - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload binary artifact - uses: actions/upload-artifact@v4 - with: - name: Kube-Pod-Autocomplete-Binary - path: build/dist - e2e-test: name: E2E Test runs-on: ubuntu-latest @@ -150,3 +71,12 @@ jobs: - name: Run E2E tests run: make test-e2e + + artifacts: + name: Artifacts + uses: ./.github/workflows/artifacts.yaml + with: + publish: false + permissions: + contents: read + packages: write diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..e5a083e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,17 @@ +name: Release + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" + +jobs: + artifacts: + name: Artifacts + uses: ./.github/workflows/artifacts.yaml + with: + publish: true + permissions: + contents: read + packages: write diff --git a/internal/config/config_test.go b/internal/config/config_test.go index c2a36ae..35ce29f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -68,7 +68,6 @@ func TestLoadConfig(t *testing.T) { if ttp.wantConfig != nil { assert.Equal(t, ttp.wantConfig, config, "Unexpected config") } - }) } } diff --git a/internal/services/autocomplete/autocomplete_test.go b/internal/services/autocomplete/autocomplete_test.go index 3096557..d2fb3c7 100644 --- a/internal/services/autocomplete/autocomplete_test.go +++ b/internal/services/autocomplete/autocomplete_test.go @@ -3,8 +3,9 @@ package autocomplete import ( "testing" - "github.com/csatib02/kube-pod-autocomplete/internal/services/autocomplete/model" "github.com/stretchr/testify/assert" + + "github.com/csatib02/kube-pod-autocomplete/internal/services/autocomplete/model" ) var serviceTest = Service{} diff --git a/internal/services/autocomplete/filter/filteroptions_test.go b/internal/services/autocomplete/filter/filteroptions_test.go index f97f1a5..492a0b5 100644 --- a/internal/services/autocomplete/filter/filteroptions_test.go +++ b/internal/services/autocomplete/filter/filteroptions_test.go @@ -3,8 +3,9 @@ package filter import ( "testing" - "github.com/csatib02/kube-pod-autocomplete/internal/services/autocomplete/model" "github.com/stretchr/testify/assert" + + "github.com/csatib02/kube-pod-autocomplete/internal/services/autocomplete/model" ) var optionsTest = Options{}