Skip to content

ci: publish helm index directly #8

ci: publish helm index directly

ci: publish helm index directly #8

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}"
echo "CHART_VERSION=$version" >> "$GITHUB_ENV"
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: Install chart-releaser
env:
CR_VERSION: v1.7.0
run: |
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/${CR_VERSION}/chart-releaser_${CR_VERSION#v}_linux_amd64.tar.gz"
tar -xzf cr.tar.gz -C "$RUNNER_TEMP"
rm cr.tar.gz
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Publish chart
env:
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
owner="${GITHUB_REPOSITORY%/*}"
repo="${GITHUB_REPOSITORY#*/}"
cr upload \
--owner "$owner" \
--git-repo "$repo" \
--commit "$(git rev-parse HEAD)" \
--skip-existing \
--make-release-latest=false
- name: Publish chart index
run: |
git fetch origin gh-pages
git worktree add .gh-pages origin/gh-pages
index_args=(.cr-release-packages --url "https://github.com/${GITHUB_REPOSITORY}/releases/download/csp-collector-${CHART_VERSION}")
if [ -f .gh-pages/index.yaml ]; then
index_args+=(--merge .gh-pages/index.yaml)
fi
helm repo index "${index_args[@]}"
cp .cr-release-packages/index.yaml .gh-pages/index.yaml
git -C .gh-pages add index.yaml
if git -C .gh-pages diff --cached --quiet; then
exit 0
fi
git -C .gh-pages commit -m "Update index.yaml"
git -C .gh-pages push origin HEAD:gh-pages