Skip to content

Commit

Permalink
add goreleaser pro (#921)
Browse files Browse the repository at this point in the history
optimize CI flow with `goreleaser pro`
  • Loading branch information
ypoplavs authored Oct 24, 2022
1 parent bd44dad commit 7c2cc26
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 33 deletions.
23 changes: 23 additions & 0 deletions .builds-darwin.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions .builds-linux.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions .builds-windows.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
103 changes: 87 additions & 16 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@ 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
uses: actions/checkout@v2
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

Expand Down Expand Up @@ -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: |
Expand All @@ -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"
Expand All @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ env

# Ignore goreleaser output
dist/
cmd/kusk/cmd/manifest_data.go
cmd/kusk/cmd/manifest_data.go
/artifacts
movie.mp4
/tmp
/linux
/windows
/darwin
27 changes: 11 additions & 16 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7c2cc26

Please sign in to comment.