chore(ci): add pre release workflow with goreleaser #244
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference from: | |
# https://goreleaser.com/ci/actions/ | |
name: Release | |
on: | |
push: | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+' | |
- 'v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+' | |
- 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
permissions: | |
contents: write | |
jobs: | |
Test: | |
name: Unit Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go 1.19 | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.19 | |
- name: Running go tests with coverage | |
env: | |
GO111MODULE: on | |
run: make cover | |
GolangLint: | |
name: Golang Lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Go 1.19 | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.19 | |
# NOTE: This golangci-lint action MUST be specified as v2 version, otherwise an error will be reported: | |
# Running error: can't run linter goanalysis_metalinter\nbuildssa: failed to load package main: could | |
# not load export data: no export data for \"k8s.io/kube-aggregator\" | |
- name: golangci-lint | |
uses: golangci/golangci-lint-action@v2 | |
with: | |
version: v1.58.2 | |
# # Lints Pull Request commits with commitlint. | |
# # | |
# # Rules can be referenced: | |
# # https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional | |
CommitLint: | |
name: Commit Lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: wagoid/commitlint-github-action@v5 | |
# Release the artifacts, release note and images. | |
Release: | |
runs-on: ubuntu-latest | |
# needs: [Test, GolangLint, CommitLint] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Check if on tag | |
run: | | |
if [[ "${GITHUB_REF#refs/tags/}" != "$GITHUB_REF" ]]; then | |
echo "Running on tag ${GITHUB_REF#refs/tags/}" | |
else | |
echo "Not running on a tag" | |
fi | |
- name: Get version | |
id: get_version | |
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: 1.19 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install npm packages and build UI | |
working-directory: ./ui | |
run: | | |
npm install | |
# Using 'CI=false' prevents build errors due to warnings. | |
# It bypasses the 'process.env.CI = true' setting in CI environments | |
# that treats warnings as errors, ensuring a successful build. | |
CI=false npm run build | |
touch build/.gitkeep | |
- name: Determine GoReleaser Config with Regex | |
run: | | |
tag=${GITHUB_REF#refs/tags/} | |
alpha='v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+' | |
beta='v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+' | |
rc='v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' | |
release='v[0-9]+.[0-9]+.[0-9]+' | |
if [[ $tag =~ $alpha ]] || [[ $tag =~ $beta ]]; then | |
echo "Match found for alpha or beta tag" | |
echo "GO_RELEASER_CONFIG=alpha_or_beta_tag.yml" >> $GITHUB_ENV | |
elif [[ $tag =~ $rc ]] || [[ $tag =~ $release ]]; then | |
echo "Match found for rc or release tag" | |
echo "GO_RELEASER_CONFIG=rc_or_release_tag.yml" >> $GITHUB_ENV | |
else | |
echo "No match found" | |
exit 1 | |
fi | |
- name: Release the karpor with GoReleaser | |
uses: goreleaser/goreleaser-action@v2 | |
with: | |
distribution: goreleaser | |
version: latest | |
args: release --clean --config .goreleaser/${{ env.GO_RELEASER_CONFIG }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |