Merge pull request #26 from entireio/add-goreleaser-publish-release · Entire

Merge pull request #26 from entireio/add-goreleaser-publish-release

8762b07→main ·

gtrrz-victor·2mo ago·5 files·+186 added/-0 removed

Add GoReleaser release pipeline + git-sync version subcommand

Changes

name: Release

on:
  workflow_dispatch:
    inputs:
      version:
        description: "Release tag (semver with v prefix, e.g. v1.2.3)"
        required: true
        type: string
  push:
    tags:
      - "v*"

permissions:
  contents: write

env:
  RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
        with:
          fetch-depth: 0
          ref: ${{ env.RELEASE_TAG }}

- uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4

- name: Setup Go
        uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
        with:
          cache: false
          go-version-file: go.mod

- name: Generate Homebrew Tap token
        id: app-token
        uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
        with:
          app-id: ${{ secrets.HOMEBREW_TAP_APP_ID }}
          private-key: ${{ secrets.HOMEBREW_TAP_APP_PRIVATE_KEY }}
          owner: ${{ github.repository_owner }}
          repositories: |
            homebrew-tap

- name: Extract release notes from CHANGELOG.md
        run: |
          VERSION="${RELEASE_TAG#v}"
          awk -v ver="$VERSION" 'BEGIN{header="^## \[" ver "\]"} $0 ~ header{found=1; next} /^## \[/{if(found) exit} found{print}' CHANGELOG.md > "$RUNNER_TEMP/release_notes.md"
          if [ ! -s "$RUNNER_TEMP/release_notes.md" ]; then
            echo "::error::No changelog entry found for version ${VERSION} in CHANGELOG.md"
            exit 1
          fi
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@1a80836c5c9d9e5755a25cb59ec6f45a3b5f41a8 # v7
        with:
          distribution: goreleaser-pro
          version: latest
          args: release --clean --release-notes=${{ runner.temp }}/release_notes.md
        env:
          GORELEASER_CURRENT_TAG: ${{ env.RELEASE_TAG }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAP_GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
          GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
          MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
          MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
          MACOS_NOTARY_ISSUER_ID: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}
          MACOS_NOTARY_KEY_ID: ${{ secrets.MACOS_NOTARY_KEY_ID }}
          MACOS_NOTARY_KEY: ${{ secrets.MACOS_NOTARY_KEY }}

notify-slack:
    runs-on: ubuntu-latest
    needs: [release]
    if: ${{ always() && needs.release.result == 'failure' }}
    steps:
      - name: Notify Slack of release failure
        uses: slackapi/slack-github-action@03ea5433c137af7c0495bc0cad1af10403fc800c # v3.0.2
        with:
          webhook: ${{ secrets.E2E_SLACK_WEBHOOK_URL }}
          webhook-type: incoming-webhook
          payload: |
            {
              "blocks": [
                {
                  "type": "section",
                  "text": {
                    "type": "mrkdwn",
                    "text": ":red_circle: *Release Failed* for `${{ env.RELEASE_TAG }}`\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run details>"
                  }
                },
                {
                  "type": "context",
                  "elements": [
                    {
                      "type": "mrkdwn",
                      "text": "Tag: `${{ env.RELEASE_TAG }}` by ${{ github.actor }}"
                    }
                  ]
                }
              ]
            }
        

A.github/workflows/release.yml

44 unmodified lines

M.gitignore

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

A.goreleaser.yaml

# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json
version: 2
pro: true

before:
  hooks:
    - go mod tidy

builds:
  - main: ./cmd/git-sync
    binary: git-sync
    env:
      - CGO_ENABLED=0
    goos:
      - darwin
      - linux
    goarch:
      - amd64
      - arm64
    ldflags:
      - -s -w
      - -X entire.io/entire/git-sync/cmd/git-sync/internal/versioninfo.Version={{.Version}}
      - -X entire.io/entire/git-sync/cmd/git-sync/internal/versioninfo.Commit={{.ShortCommit}}
      - -X entire.io/entire/git-sync/cmd/git-sync/internal/versioninfo.Date={{.CommitDate}}

notarize:
  macos:
    - enabled: '{{ isEnvSet "MACOS_SIGN_P12" }}'
      sign:
        certificate: "{{.Env.MACOS_SIGN_P12}}"
        password: "{{.Env.MACOS_SIGN_PASSWORD}}"
      notarize:
        issuer_id: "{{.Env.MACOS_NOTARY_ISSUER_ID}}"
        key_id: "{{.Env.MACOS_NOTARY_KEY_ID}}"
        key: "{{.Env.MACOS_NOTARY_KEY}}"
        wait: true # do not let an unusable binary slip into the wild

archives:
  - formats:
      - tar.gz
    name_template: "git-sync_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
    files:
      - src: LICENSE
        info:
          owner: root
          group: root
          mtime: "{{ .CommitDate }}"
      - src: README.md
        info:
          owner: root
          group: root
          mtime: "{{ .CommitDate }}"

checksum:
  name_template: "checksums.txt"

homebrew_casks:
  - name: git-sync
    repository:
      owner: entireio
      name: homebrew-tap
      token: "{{ .Env.TAP_GITHUB_TOKEN }}"
    directory: Casks
    homepage: "https://github.com/entireio/git-sync"
    description: "git-sync — replicate and sync Git repositories"
    binaries:
      - git-sync
    skip_upload: auto

A.cmd/git-sync/internal/versioninfo/versioninfo.go

package versioninfo

var (
    Version = "dev"
    Commit  = "none"
    Date    = "unknown"
)

A.cmd/git-sync/main.go

9 unmodified lines