Skip to content

ci: avoid marking chart releases as latest #6

ci: avoid marking chart releases as latest

ci: avoid marking chart releases as latest #6

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
ref:
description: "Tag to release, for example v0.0.18"
required: true
type: string
permissions:
contents: write
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- name: Validate release tag
env:
TAG: ${{ github.event.inputs.ref || github.ref_name }}
run: |
case "$TAG" in
v*) ;;
*) echo "release tag must start with v"; exit 1 ;;
esac
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: Test
run: go test -v -race ./...
build:
name: build ${{ matrix.goos }}/${{ matrix.goarch }}
needs: test
strategy:
fail-fast: false
matrix:
include:
- goos: darwin
goarch: amd64
runs-on: macos-15-intel
- goos: darwin
goarch: arm64
runs-on: macos-15
- goos: linux
goarch: amd64
runs-on: ubuntu-latest
- goos: linux
goarch: arm64
runs-on: ubuntu-24.04-arm
- goos: windows
goarch: amd64
runs-on: windows-latest
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: Verify native build target
shell: bash
run: |
test "$(go env GOHOSTOS)" = "${{ matrix.goos }}"
test "$(go env GOHOSTARCH)" = "${{ matrix.goarch }}"
- name: Build archive
shell: bash
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
tag="${{ github.event.inputs.ref || github.ref_name }}"
version="${tag#v}"
revision="${version}+$(git rev-parse --short HEAD)"
output="go-csp-collector_${version}_${GOOS}_${GOARCH}"
mkdir -p dist
if [ "$GOOS" = "windows" ]; then
go build -trimpath -ldflags "-s -w -X main.Rev=${revision}" -o "dist/${output}.exe" .
tar -czf "dist/${output}.tar.gz" -C dist "${output}.exe"
else
go build -trimpath -ldflags "-s -w -X main.Rev=${revision}" -o "dist/${output}" .
tar -czf "dist/${output}.tar.gz" -C dist "${output}"
fi
- name: Upload archive
uses: actions/upload-artifact@v7
with:
name: go-csp-collector-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/*.tar.gz
if-no-files-found: error
release:
name: publish release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- name: Download archives
uses: actions/download-artifact@v8
with:
path: dist
pattern: go-csp-collector-*
merge-multiple: true
- name: Generate checksums
working-directory: dist
run: shasum -a 256 -- *.tar.gz > checksums.txt
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.inputs.ref || github.ref_name }}
run: gh release create "$TAG" dist/*.tar.gz dist/checksums.txt --title "$TAG" --generate-notes
release-chart:
name: publish helm chart
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
fetch-depth: 0
- uses: azure/setup-helm@v4
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Package chart
env:
TAG: ${{ github.event.inputs.ref || github.ref_name }}
run: |
version="${TAG#v}"
helm lint deployments/kubernetes-helm
helm template csp-collector deployments/kubernetes-helm --set image.tag="$version"
helm package deployments/kubernetes-helm \
--destination .cr-release-packages \
--version "$version" \
--app-version "$version"
- name: Publish chart
uses: helm/chart-releaser-action@v1.7.0
with:
skip_packaging: true
skip_existing: true
mark_as_latest: false
env:
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}