From b0e4a29c1fc1bbc051455165364b5a8f4eb130f7 Mon Sep 17 00:00:00 2001 From: panshuai-ps Date: Wed, 29 May 2024 10:25:32 +0800 Subject: [PATCH] chore: add unstable go releaser --- .github/workflows/release.yaml | 59 ++++++--- .github/workflows/unstable-release.yaml | 112 +++++++++++++++++ .goreleaser-alphabeta.yml | 143 ++++++++++++++++++++++ .goreleaser.yml => .goreleaser-rc.yml | 0 .goreleaser-release.yml | 154 ++++++++++++++++++++++++ 5 files changed, 451 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/unstable-release.yaml create mode 100644 .goreleaser-alphabeta.yml rename .goreleaser.yml => .goreleaser-rc.yml (100%) create mode 100644 .goreleaser-release.yml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7987377f..9c0f67d8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,10 +4,10 @@ name: Release on: push: tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - '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: @@ -94,21 +94,46 @@ jobs: with: node-version: '20' - - name: Install npm packages and build UI - working-directory: ./ui +# - 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: | - 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 + 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 beta tag" + echo "GO_RELEASER_CONFIG=.goreleaser-alphabeta-tag.yml" >> $GITHUB_ENV + elif [[ $tag =~ $rc ]]; then + echo "Match found for rc tag" + echo "GO_RELEASER_CONFIG=.goreleaser-rc-tag.yml" >> $GITHUB_ENV + elif [[ $tag =~ $release ]]; then + echo "Match found for release tag" + echo "GO_RELEASER_CONFIG=.goreleaser-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 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Test + run: | + echo "release --clean --config ${{ env.GO_RELEASER_CONFIG }}" + +# - name: Release the karpor with GoReleaser +# uses: goreleaser/goreleaser-action@v2 +# with: +# distribution: goreleaser +# version: latest +# args: release --clean --config ${{ env.GO_RELEASER_CONFIG }} +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/unstable-release.yaml b/.github/workflows/unstable-release.yaml new file mode 100644 index 00000000..15c5541b --- /dev/null +++ b/.github/workflows/unstable-release.yaml @@ -0,0 +1,112 @@ +# 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]+' +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: Release the karpor with GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --clean --config .unstable-goreleaser.yml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser-alphabeta.yml b/.goreleaser-alphabeta.yml new file mode 100644 index 00000000..00bee64d --- /dev/null +++ b/.goreleaser-alphabeta.yml @@ -0,0 +1,143 @@ +# Copyright The Karpor Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is an example .goreleaser.yml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + # GOOS list to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # + # Default: [ 'darwin', 'linux', 'windows' ] + goos: + - linux + # - windows + - darwin + # GOARCH to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # + # Default: [ '386', 'amd64', 'arm64' ] + goarch: + - amd64 + - arm64 + # 使用 ldflags="-s -w" 去掉符号表和调试信息,以减少发布包的大小 + ldflags: + - -s -w + main: ./cmd/ +archives: + - id: release + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + builds_info: + mode: 0644 + # format is `time.RFC3339Nano` + mtime: 2008-01-02T15:04:05Z + # format_overrides: + # - goos: windows + # format: zip + files: + - LICENSE + - README.md + - docs/* + - src: dist/CHANGELOG.md + strip_parent: true +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: desc + # Changelog generation implementation to use. + # + # Valid options are: + # - `git`: uses `git log`; + # - `github`: uses the compare GitHub API, appending the author login to the changelog. + # - `gitlab`: uses the compare GitLab API, appending the author name and email to the changelog. + # - `github-native`: uses the GitHub release notes generation API, disables the groups feature. + # + # Default: 'git' + use: github + # Group commits messages by given regex and title. + # Order value defines the order of the groups. + # Providing no regex means all commits will be grouped under the default group. + # Groups are disabled when using github-native, as it already groups things by itself. + # Matches are performed against strings of the form: "[:] ". + # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax. + groups: + - title: Features + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: 'Bug fixes' + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: 'Performance improvements' + regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$' + order: 2 + - title: 'Refactors' + regexp: '^.*?refactor(\([[:word:]]+\))??!?:.+$' + order: 3 + - title: 'Tests' + regexp: '^.*?test(\([[:word:]]+\))??!?:.+$' + order: 4 + - title: 'Documents' + regexp: '^.*?docs(\([[:word:]]+\))??!?:.+$' + order: 5 + - title: 'Chores' + regexp: '^.*?chore(\([[:word:]]+\))??!?:.+$' + order: 6 + - title: 'CI' + regexp: '^.*?ci(\([[:word:]]+\))??!?:.+$' + order: 7 + - title: Others + order: 999 + filters: + exclude: + - '^style:' + +dockers: +- image_templates: + - 'kusionstack/{{ .ProjectName }}:{{ .Tag }}' + - 'kusionstack/{{ .ProjectName }}:latest' + dockerfile: Dockerfile + use: docker + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=linux/amd64" + extra_files: + - ui/ + - config/relationship.yaml +# - image_templates: +# - 'kusionstack/{{ .ProjectName }}:{{ .Tag }}-arm64' +# dockerfile: Dockerfile +# use: docker +# build_flag_templates: +# - "--pull" +# - "--label=org.opencontainers.image.created={{.Date}}" +# - "--label=org.opencontainers.image.name={{.ProjectName}}" +# - "--label=org.opencontainers.image.revision={{.FullCommit}}" +# - "--label=org.opencontainers.image.version={{.Version}}" +# - "--label=org.opencontainers.image.source={{.GitURL}}" +# - "--platform=linux/arm64" +# goarch: arm64 +# extra_files: +# - ui/ diff --git a/.goreleaser.yml b/.goreleaser-rc.yml similarity index 100% rename from .goreleaser.yml rename to .goreleaser-rc.yml diff --git a/.goreleaser-release.yml b/.goreleaser-release.yml new file mode 100644 index 00000000..5ad7cc9a --- /dev/null +++ b/.goreleaser-release.yml @@ -0,0 +1,154 @@ +# Copyright The Karpor Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is an example .goreleaser.yml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + # GOOS list to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # + # Default: [ 'darwin', 'linux', 'windows' ] + goos: + - linux + # - windows + - darwin + # GOARCH to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # + # Default: [ '386', 'amd64', 'arm64' ] + goarch: + - amd64 + - arm64 + # 使用 ldflags="-s -w" 去掉符号表和调试信息,以减少发布包的大小 + ldflags: + - -s -w + main: ./cmd/ +archives: + - id: release + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + builds_info: + mode: 0644 + # format is `time.RFC3339Nano` + mtime: 2008-01-02T15:04:05Z + # format_overrides: + # - goos: windows + # format: zip + files: + - LICENSE + - README.md + - docs/* + - src: dist/CHANGELOG.md + strip_parent: true +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: desc + # Changelog generation implementation to use. + # + # Valid options are: + # - `git`: uses `git log`; + # - `github`: uses the compare GitHub API, appending the author login to the changelog. + # - `gitlab`: uses the compare GitLab API, appending the author name and email to the changelog. + # - `github-native`: uses the GitHub release notes generation API, disables the groups feature. + # + # Default: 'git' + use: github + # Group commits messages by given regex and title. + # Order value defines the order of the groups. + # Providing no regex means all commits will be grouped under the default group. + # Groups are disabled when using github-native, as it already groups things by itself. + # Matches are performed against strings of the form: "[:] ". + # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax. + groups: + - title: Features + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: 'Bug fixes' + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: 'Performance improvements' + regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$' + order: 2 + - title: 'Refactors' + regexp: '^.*?refactor(\([[:word:]]+\))??!?:.+$' + order: 3 + - title: 'Tests' + regexp: '^.*?test(\([[:word:]]+\))??!?:.+$' + order: 4 + - title: 'Documents' + regexp: '^.*?docs(\([[:word:]]+\))??!?:.+$' + order: 5 + - title: 'Chores' + regexp: '^.*?chore(\([[:word:]]+\))??!?:.+$' + order: 6 + - title: 'CI' + regexp: '^.*?ci(\([[:word:]]+\))??!?:.+$' + order: 7 + - title: Others + order: 999 + filters: + exclude: + - '^style:' + +release: + github: + owner: KusionStack + name: karpor + draft: false + footer: | + ## Docker Images + * `kusionstack/karpor:{{ .Tag }}` + + ## Thanks! + +dockers: +- image_templates: + - 'kusionstack/{{ .ProjectName }}:{{ .Tag }}' + - 'kusionstack/{{ .ProjectName }}:latest' + dockerfile: Dockerfile + use: docker + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - "--label=org.opencontainers.image.source={{.GitURL}}" + - "--platform=linux/amd64" + extra_files: + - ui/ + - config/relationship.yaml +# - image_templates: +# - 'kusionstack/{{ .ProjectName }}:{{ .Tag }}-arm64' +# dockerfile: Dockerfile +# use: docker +# build_flag_templates: +# - "--pull" +# - "--label=org.opencontainers.image.created={{.Date}}" +# - "--label=org.opencontainers.image.name={{.ProjectName}}" +# - "--label=org.opencontainers.image.revision={{.FullCommit}}" +# - "--label=org.opencontainers.image.version={{.Version}}" +# - "--label=org.opencontainers.image.source={{.GitURL}}" +# - "--platform=linux/arm64" +# goarch: arm64 +# extra_files: +# - ui/