From ada9fcec4c70abe417e3d27d5f9109a65537d4c8 Mon Sep 17 00:00:00 2001 From: Gorkem Ercan Date: Sun, 14 Apr 2024 11:16:40 -0400 Subject: [PATCH] split platform builds Splits the release builds to corresponding platforms. Introduces go-releaser configuration for each platform. adds a new workflow that uses gh CLI to do the publish. --- .github/workflows/platform-release.yaml | 166 ++++++++++++++++++++++++ .github/workflows/release.yaml | 52 -------- .goreleaser.darwin.yaml | 47 +++++++ .goreleaser.linux.yaml | 39 ++++++ .goreleaser.windows.yaml | 37 ++++++ .goreleaser.yaml | 116 ----------------- 6 files changed, 289 insertions(+), 168 deletions(-) create mode 100644 .github/workflows/platform-release.yaml delete mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.darwin.yaml create mode 100644 .goreleaser.linux.yaml create mode 100644 .goreleaser.windows.yaml delete mode 100644 .goreleaser.yaml diff --git a/.github/workflows/platform-release.yaml b/.github/workflows/platform-release.yaml new file mode 100644 index 00000000..8200e0f4 --- /dev/null +++ b/.github/workflows/platform-release.yaml @@ -0,0 +1,166 @@ +name: Release with Platform builds + +on: + workflow_dispatch: + inputs: + skip_signing: + description: 'Skip code signing' + required: true + default: false + type: boolean + push: + tags: + - 'v*' + +permissions: + contents: write +jobs: + build-macos: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + # - name: Import Apple Code Signing Certificates + # if: ${{ github.event_name != 'workflow_dispatch' || !inputs.skip_signing }} + # uses: Apple-Actions/import-codesign-certs@v2 + # with: + # p12-file-base64: ${{ secrets.APPLE_CERTIFICATE_BASE64 }} + # p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + distribution: goreleaser + args: release --clean --snapshot --config ./.goreleaser.darwin.yaml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + APPLE_DEVELOPER_ID: ${{ secrets.APPLICATION_IDENTITY}} + APPLE_ID: ${{ vars.APPLE_ID }} + APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD}} + APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID}} + - name: Notarize the macOS binary + run: | + ./build/scripts/sign ./dist/kitops-darwin-amd64.zip + ./build/scripts/sign ./dist/kitops-darwin-x86_64.zip + - name: Upload macOS artifacts + uses: actions/upload-artifact@v4 + with: + name: dist-macos + if-no-files-found: error + retention-days: 7 + path: | + ./dist/*.zip + + build-windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + distribution: goreleaser + args: release --clean --snapshot --config ./.goreleaser.windows.yaml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Windows artifacts + uses: actions/upload-artifact@v4 + with: + name: dist-windows + if-no-files-found: error + retention-days: 7 + path: | + ./dist/*.zip + + build-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + distribution: goreleaser + args: release --clean --snapshot --config ./.goreleaser.linux.yaml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Linux artifacts + uses: actions/upload-artifact@v4 + with: + name: dist-linux + if-no-files-found: error + retention-days: 7 + path: | + ./dist/*.tar.gz + release: + runs-on: ubuntu-latest + needs: [build-linux, build-macos, build-windows] + steps: + - name: Merge built artifacts + uses: actions/download-artifact@v4 + with: + path: dist + pattern: dist-* + merge-multiple: true + - name: Create Checksums + env: + TAG_NAME: ${{ github.ref_name}} + run: | + shopt -s failglob + pushd dist + shasum -a 256 kitops-* > checksums.txt + mv checksums.txt kitops_${TAG_NAME}_checksums.txt + popd + - name: Create Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG_NAME: ${{ github.ref_name}} + REPO: ${{ github.repository }} + run: | + echo "Creating release for ${TAG_NAME}" + release_args=( + ${TAG_NAME} + ./dist/*.* + --title "Release ${TAG_NAME}" + --generate-notes + --repo ${REPO} + ) + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + previous_release="$(gh release list --repo $REPO --limit 1 --json tagName --jq '.[] | .tagName ')" + echo "Previous release: ${previous_release}" + release_args+=("--latest") + release_args+=("--verify-tag") + release_args+=("--notes-start-tag ${previous_release}") + fi + gh release create "${release_args[@]}" + - name: Generate CLI documentation + run: | + ./docs/src/docs/cli/generate.sh > /dev/null + + - name: PR for CLI documentation + uses: peter-evans/create-pull-request@v6 + with: + add-paths: | + docs/*.md + commit-message: "docs: update CLI documentation for ${{ github.ref_name }}" \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 3a016e4b..00000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Release - -on: - workflow_dispatch: - push: - tags: - - 'v*' - -permissions: - contents: write -jobs: - release-build: - runs-on: macos-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - - - name: Import Apple Code Signing Certificates - uses: Apple-Actions/import-codesign-certs@v2 - with: - p12-file-base64: ${{ secrets.APPLE_CERTIFICATE_BASE64 }} - p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 - with: - version: latest - distribution: goreleaser - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - APPLE_DEVELOPER_ID: ${{ secrets.APPLICATION_IDENTITY}} - APPLE_ID: ${{ vars.APPLE_ID }} - APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD}} - APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID}} - - - name: Generate CLI documentation - run: | - docs/src/docs/cli/generate.sh > /dev/null - - - name: PR for CLI documentation - uses: peter-evans/create-pull-request@v6 - with: - add-paths: | - docs/*.md - commit-message: "docs: update CLI documentation for ${{ github.ref_name }}" \ No newline at end of file diff --git a/.goreleaser.darwin.yaml b/.goreleaser.darwin.yaml new file mode 100644 index 00000000..7e9f7e8e --- /dev/null +++ b/.goreleaser.darwin.yaml @@ -0,0 +1,47 @@ + +version: 1 + +project_name: kitops + +before: + hooks: + - go mod tidy + +builds: + - id: "kit-macos" + env: + - CGO_ENABLED=0 + goos: + - darwin + goarch: + - amd64 + - arm64 + binary: kit + ldflags: + - -s -w -X kitops/pkg/cmd/version.Version={{.Version}} -X kitops/pkg/cmd/version.GitCommit={{.Commit}} -X kitops/pkg/cmd/version.BuildTime={{.CommitDate}} + hooks: + post: + - cmd: ./build/scripts/sign '{{ .Path }}' + output: true + +archives: + - id: kit-macos-archive + format: zip + builds: + - kit-macos + name_template: >- + {{ .ProjectName }}- + {{- tolower .Os }}- + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + wrap_in_directory: true + rlcp: true + files: + - LICENSE + - README.md + +git: + ignore_tags: + - "next" diff --git a/.goreleaser.linux.yaml b/.goreleaser.linux.yaml new file mode 100644 index 00000000..d17db2d3 --- /dev/null +++ b/.goreleaser.linux.yaml @@ -0,0 +1,39 @@ + +version: 1 + +project_name: kitops + +before: + hooks: + - go mod tidy + +builds: + - id: "kit-linux" + env: + - CGO_ENABLED=0 + goos: + - linux + binary: kit + ldflags: + - -s -w -X kitops/pkg/cmd/version.Version={{.Version}} -X kitops/pkg/cmd/version.GitCommit={{.Commit}} -X kitops/pkg/cmd/version.BuildTime={{.CommitDate}} + +archives: + - id: kit-archive + format: tar.gz + builds: + - kit-linux + name_template: >- + {{ .ProjectName }}- + {{- tolower .Os }}- + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + rlcp: true + files: + - LICENSE + - README.md + +git: + ignore_tags: + - "next" \ No newline at end of file diff --git a/.goreleaser.windows.yaml b/.goreleaser.windows.yaml new file mode 100644 index 00000000..f7389f83 --- /dev/null +++ b/.goreleaser.windows.yaml @@ -0,0 +1,37 @@ + +version: 1 + +project_name: kitops + +before: + hooks: + - go mod tidy + +builds: + - id: "kit-wins" + env: + - CGO_ENABLED=0 + goos: + - windows + binary: kit + ldflags: + - -s -w -X kitops/pkg/cmd/version.Version={{.Version}} -X kitops/pkg/cmd/version.GitCommit={{.Commit}} -X kitops/pkg/cmd/version.BuildTime={{.CommitDate}} + +archives: + - id: kit-archive + format: zip + builds: + - kit-wins + name_template: >- + {{ .ProjectName }}- + {{- tolower .Os }}- + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + rlcp: true + files: + - LICENSE + - README.md + + diff --git a/.goreleaser.yaml b/.goreleaser.yaml deleted file mode 100644 index 922a1666..00000000 --- a/.goreleaser.yaml +++ /dev/null @@ -1,116 +0,0 @@ - -version: 1 - -project_name: kitops - -before: - hooks: - - go mod tidy - -builds: - - id: "kit-linux" - env: - - CGO_ENABLED=0 - goos: - - linux - binary: kit - ldflags: - - -s -w -X kitops/pkg/cmd/version.Version={{.Version}} -X kitops/pkg/cmd/version.GitCommit={{.Commit}} -X kitops/pkg/cmd/version.BuildTime={{.CommitDate}} - - - id: "kit-wins" - env: - - CGO_ENABLED=0 - goos: - - windows - binary: kit - ldflags: - - -s -w -X kitops/pkg/cmd/version.Version={{.Version}} -X kitops/pkg/cmd/version.GitCommit={{.Commit}} -X kitops/pkg/cmd/version.BuildTime={{.CommitDate}} - - - id: "kit-macos" - env: - - CGO_ENABLED=0 - goos: - - darwin - goarch: - - amd64 - - arm64 - binary: kit - ldflags: - - -s -w -X kitops/pkg/cmd/version.Version={{.Version}} -X kitops/pkg/cmd/version.GitCommit={{.Commit}} -X kitops/pkg/cmd/version.BuildTime={{.CommitDate}} - hooks: - post: - - cmd: ./build/scripts/sign '{{ .Path }}' - output: true - -archives: - - id: kit-archive - format: tar.gz - builds: - - kit-linux - - kit-wins - name_template: >- - {{ .ProjectName }}- - {{- tolower .Os }}- - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - # use zip for windows archives - format_overrides: - - goos: windows - format: zip - rlcp: true - files: - - LICENSE - - README.md - - - id: kit-macos-archive - format: zip - builds: - - kit-macos - name_template: >- - {{ .ProjectName }}- - {{- tolower .Os }}- - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - wrap_in_directory: true - rlcp: true - files: - - LICENSE - - README.md - -signs: - - artifacts: archive - signature: "${artifact}" - ids: - - kit-macos-archive - cmd: build/scripts/sign - args: - - "${artifact}" - output: true - -changelog: - sort: asc - filters: - exclude: - - "^docs:" - - "^test:" - -git: - ignore_tags: - - "next" - -release: - github: - owner: jozu-ai - name: kitops - header: | - ## Kitops Release {{.Version}} ({{ .Date }}) - - footer: | - Thanks for supporting Kitops. - - name_template: "{{.ProjectName}}-{{.Version}}" - skip_upload: false