From 7c2cc267dc3f2b1e6e8229042452d2b1eb068a18 Mon Sep 17 00:00:00 2001 From: ypoplavs <45286051+ypoplavs@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:04:19 +0300 Subject: [PATCH] add goreleaser pro (#921) optimize CI flow with `goreleaser pro` --- .builds-darwin.goreleaser.yml | 23 ++++++++ .builds-linux.goreleaser.yml | 24 ++++++++ .builds-windows.goreleaser.yml | 24 ++++++++ .github/workflows/release.yaml | 103 ++++++++++++++++++++++++++++----- .gitignore | 8 ++- .goreleaser.yml | 27 ++++----- 6 files changed, 176 insertions(+), 33 deletions(-) create mode 100644 .builds-darwin.goreleaser.yml create mode 100644 .builds-linux.goreleaser.yml create mode 100644 .builds-windows.goreleaser.yml diff --git a/.builds-darwin.goreleaser.yml b/.builds-darwin.goreleaser.yml new file mode 100644 index 000000000..681ec2d1b --- /dev/null +++ b/.builds-darwin.goreleaser.yml @@ -0,0 +1,23 @@ +before: + hooks: + - go mod tidy + - go mod verify + - go generate +dist: darwin +builds: + - main: ./cmd/kusk + id: kusk + binary: kusk + env: + - CGO_ENABLED=0 + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -w -s + - -X 'github.com/kubeshop/kusk-gateway/pkg/build.Version={{.Env.VERSION}}' + - -X 'github.com/kubeshop/kusk-gateway/pkg/analytics.TelemetryToken={{.Env.TELEMETRY_TOKEN}}' +archives: + - format: binary diff --git a/.builds-linux.goreleaser.yml b/.builds-linux.goreleaser.yml new file mode 100644 index 000000000..f020e35bc --- /dev/null +++ b/.builds-linux.goreleaser.yml @@ -0,0 +1,24 @@ +before: + hooks: + - go mod tidy + - go mod verify + - go generate +dist: linux +builds: + - main: ./cmd/kusk + id: kusk + binary: kusk + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + - 386 + ldflags: + - -w -s + - -X 'github.com/kubeshop/kusk-gateway/pkg/build.Version={{.Env.VERSION}}' + - -X 'github.com/kubeshop/kusk-gateway/pkg/analytics.TelemetryToken={{.Env.TELEMETRY_TOKEN}}' +archives: + - format: binary diff --git a/.builds-windows.goreleaser.yml b/.builds-windows.goreleaser.yml new file mode 100644 index 000000000..b84f1f264 --- /dev/null +++ b/.builds-windows.goreleaser.yml @@ -0,0 +1,24 @@ +before: + hooks: + - go mod tidy + - go mod verify + - go generate +dist: windows +builds: + - main: ./cmd/kusk + id: kusk + binary: kusk + env: + - CGO_ENABLED=0 + goos: + - windows + goarch: + - amd64 + - arm64 + - 386 + ldflags: + - -w -s + - -X 'github.com/kubeshop/kusk-gateway/pkg/build.Version={{.Env.VERSION}}' + - -X 'github.com/kubeshop/kusk-gateway/pkg/analytics.TelemetryToken={{.Env.TELEMETRY_TOKEN}}' +archives: + - format: binary diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fa4c87922..c3f5da9b3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,13 +16,10 @@ on: - "v[0-9]+.[0-9]+.[0-9]+-*" jobs: - release: - name: Create and upload release-artifacts, triggers Helm charts release - if: github.event.base_ref == 'refs/heads/main' + image_build: + name: Build and push Docker image runs-on: ubuntu-latest - outputs: - changed_resources: ${{ steps.check_modified_resources.outputs.changed_resources }} - release_version: ${{ steps.check_modified_resources.outputs.release_version }} + if: github.event.base_ref == 'refs/heads/main' steps: - name: Checkout @@ -30,11 +27,6 @@ jobs: with: fetch-depth: 0 - - name: setup-golang - uses: actions/setup-go@v2 - with: - go-version: 1.19 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -73,16 +65,95 @@ jobs: TELEMETRY_TOKEN=${{ secrets.TELEMETRY_TOKEN }} VERSION=${{ env.VERSION }} - - name: Run GoReleaser to publish release notes + + pre_build: + name: Pre-build binaries + if: github.event.base_ref == 'refs/heads/main' + runs-on: ubuntu-latest + strategy: + matrix: + include: + - name: "linux" + path: .builds-linux.goreleaser.yml + - name: "windows" + path: .builds-windows.goreleaser.yml + - name: "darwin" + path: .builds-darwin.goreleaser.yml + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: setup-golang + uses: actions/setup-go@v2 + with: + go-version: 1.19 + + - name: setup-goreleaser-environment-variables + run: | + echo "VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV + + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: - distribution: goreleaser + distribution: goreleaser-pro version: latest - args: release --rm-dist --skip-sign + args: release -f ${{ matrix.path }} --skip-publish env: GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + GORELEASER_KEY: ${{ secrets.GORELEASER_LICENSE }} TELEMETRY_TOKEN: ${{ secrets.TELEMETRY_TOKEN }} + - name: Upload Artifacts + uses: actions/upload-artifact@master + with: + name: kusk_${{ matrix.name }} + path: | + ${{ matrix.name }}/kusk_${{ matrix.name }}_* + retention-days: 1 + + release: + name: Build binaries, upload release-artifacts + needs: pre_build + runs-on: ubuntu-latest + + outputs: + changed_resources: ${{ steps.check_modified_resources.outputs.changed_resources }} + release_version: ${{ steps.check_modified_resources.outputs.release_version }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Download Artifacts for Linux + uses: actions/download-artifact@master + with: + name: kusk_linux + path: linux + - name: Download Artifacts for Windows + uses: actions/download-artifact@master + with: + name: kusk_windows + path: windows + - name: Download Artifacts for Darwin + uses: actions/download-artifact@master + with: + name: kusk_darwin + path: darwin + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser-pro + version: latest + args: release -f .goreleaser.yml + env: + GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + GORELEASER_KEY: ${{ secrets.GORELEASER_LICENSE }} + - name: Check if we have modified CRDs or RBAC between the 2 last tags id: check_modified_resources run: | @@ -100,7 +171,7 @@ jobs: echo "::set-output name=changed_resources::false" fi - # This job runs when we have changed_resources from the upstream release job +# This job runs when we have changed_resources from the upstream release job notify_slack_if_resources_changed: name: "Notify when CRD or RBAC changed" needs: "release" @@ -120,7 +191,7 @@ jobs: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} SLACK_FOOTER: "Kubeshop --> Kusk Gateway" - # This job runs when we there is no changed resources in the upstream job +# This job runs when we there is no changed resources in the upstream job helm_chart_version_bump: name: "Trigger Helm chart appVersion update" needs: "release" diff --git a/.gitignore b/.gitignore index 916914a3d..8b405da2c 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,10 @@ env # Ignore goreleaser output dist/ -cmd/kusk/cmd/manifest_data.go \ No newline at end of file +cmd/kusk/cmd/manifest_data.go +/artifacts +movie.mp4 +/tmp +/linux +/windows +/darwin diff --git a/.goreleaser.yml b/.goreleaser.yml index cdc1a9ee7..20d3fa149 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,24 +1,19 @@ -before: - hooks: - - go mod tidy - - go mod verify - - go generate builds: - - id: kusk-gateway - skip: true - - id: kusk - main: ./cmd/kusk/ - env: - - CGO_ENABLED=0 - binary: kusk + - builder: prebuilt + id: kusk goos: - linux - windows - darwin - ldflags: - - -w -s - - -X 'github.com/kubeshop/kusk-gateway/pkg/build.Version={{.Env.VERSION}}' - - -X 'github.com/kubeshop/kusk-gateway/pkg/analytics.TelemetryToken={{.Env.TELEMETRY_TOKEN}}' + goarch: + - amd64 + - arm64 + - 386 + goamd64: + - v1 + prebuilt: + path: '{{ .Os }}/kusk_{{ .Os }}_{{ .Arch }}{{ with .Amd64 }}_{{ . }}{{ end }}/kusk{{ .Ext }}' + binary: kusk archives: - replacements: darwin: macOS