From 164f235ab4799a76acaeac0acff2d3d5c18939ea Mon Sep 17 00:00:00 2001 From: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:51:21 +0200 Subject: [PATCH] chore(ci): rework ci for ghcr (#7) --- .github/workflows/ci.yaml | 34 +++---- .../{release-executable.yaml => release.yaml} | 25 ++--- .goreleaser.yml | 97 +++++++++++++++++++ 3 files changed, 126 insertions(+), 30 deletions(-) rename .github/workflows/{release-executable.yaml => release.yaml} (56%) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca3f510..ce7bbb0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,39 +1,35 @@ name: Build and Test on: - push: - branches: - - 'main' pull_request: + types: [opened, reopened, synchronize, ready_for_review] branches: - - '*' + - 'main' + +permissions: + contents: write jobs: build: + if: "!github.event.pull_request.draft" strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] runs-on: ${{ matrix.os }} name: Build & Test steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup go - uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup go + uses: actions/setup-go@v5 with: go-version: '^1.16.0' - - - name: Download dependencies + + - name: Download dependencies run: go mod download - - - name: Build & Test + + - name: Build & Test run: | go build -o ./helm-changelog -v ./cmd/ go test ./... - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - with: - args: release --snapshot --skip-publish --rm-dist diff --git a/.github/workflows/release-executable.yaml b/.github/workflows/release.yaml similarity index 56% rename from .github/workflows/release-executable.yaml rename to .github/workflows/release.yaml index 819de8b..077abbd 100644 --- a/.github/workflows/release-executable.yaml +++ b/.github/workflows/release.yaml @@ -5,27 +5,30 @@ on: tags: - v*.*.* +permissions: + contents: write + packages: write + jobs: build: runs-on: ubuntu-latest name: goreleaser steps: - - - name: Checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v4 with: fetch-depth: 0 - - - name: Setup go - uses: actions/setup-go@v2 + + - name: Setup go + uses: actions/setup-go@v5 with: go-version: '^1.16.0' - - - name: Download dependencies + + - name: Download dependencies run: go mod download - - - name: Release via goreleaser - uses: goreleaser/goreleaser-action@v2 + + - name: Release via goreleaser + uses: goreleaser/goreleaser-action@v5 with: args: release --rm-dist env: diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..268ff79 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,97 @@ +project_name: helm-changelog + +builds: + - binary: helm-changelog + main: ./ + + env: + - CGO_ENABLED=0 + flags: + - -trimpath + ldflags: + - -s -w -X main.version={{.Version}} + + goos: + - windows + - darwin + - linux + goarch: + - amd64 + - arm64 + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^doc:' + - '^chore:' + - '^test:' + - '^tests:' + +archives: + - id: helm-changelog + name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + format: tar.gz + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + +docker_manifests: + - name_template: 'ghcr.io/traefik/helm-changelog:{{ .Tag }}' + image_templates: + - 'ghcr.io/traefik/helm-changelog:{{ .Tag }}-amd64' + - 'ghcr.io/traefik/helm-changelog:{{ .Tag }}-arm64' + - name_template: 'ghcr.io/traefik/helm-changelog:latest' + image_templates: + - 'ghcr.io/traefik/helm-changelog:{{ .Tag }}-amd64' + - 'ghcr.io/traefik/helm-changelog:{{ .Tag }}-arm64' + - name_template: 'ghcr.io/traefik/helm-changelog:v{{ .Major }}.{{ .Minor }}' + image_templates: + - 'ghcr.io/traefik/helm-changelog:v{{ .Major }}.{{ .Minor }}-amd64' + - 'ghcr.io/traefik/helm-changelog:v{{ .Major }}.{{ .Minor }}-arm64' + +dockers: + - use: buildx + goos: linux + goarch: amd64 + dockerfile: buildx.Dockerfile + image_templates: + - 'ghcr.io/traefik/helm-changelog:latest-amd64' + - 'ghcr.io/traefik/helm-changelog:{{ .Tag }}-amd64' + - 'ghcr.io/traefik/helm-changelog:v{{ .Major }}.{{ .Minor }}-amd64' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Myrmica Bibikoffi - Closes stale issues' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation={{.GitURL}}' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/amd64' + + - use: buildx + goos: linux + goarch: arm64 + dockerfile: buildx.Dockerfile + image_templates: + - 'ghcr.io/traefik/helm-changelog:latest-arm64' + - 'ghcr.io/traefik/helm-changelog:{{ .Tag }}-arm64' + - 'ghcr.io/traefik/helm-changelog:v{{ .Major }}.{{ .Minor }}-arm64' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Myrmica Bibikoffi - Closes stale issues' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation={{.GitURL}}' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/arm64'