From f9564ddc50bb16cbfa10fba56d88a212d771846e Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Sun, 12 Apr 2026 12:40:49 +0200 Subject: [PATCH] ci: migrate release pipeline to GoReleaser Same proven pattern from esq-cli and atl-cli. Differences from the other CLIs: - Version ldflag path: github.com/enthus-appdev/n8n-cli/internal/cmd.version (version variable lives in internal/cmd, not main) - Only one ldflag (no commit or date injection) - Binary and formula name: n8nctl (distinct from repo name n8n-cli) - Test uses `n8nctl version` subcommand (not --version flag) --- .github/workflows/release.yml | 119 +++++----------------------------- .goreleaser.yml | 69 ++++++++++++++++++++ internal/cmd/root.go | 8 ++- 3 files changed, 90 insertions(+), 106 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86a1af7..d1ac3e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,108 +27,21 @@ jobs: - name: Run tests run: go test -v -race ./... - - name: Build binaries - run: | - VERSION=${GITHUB_REF_NAME} - COMMIT=$(git rev-parse --short HEAD) - DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - LDFLAGS="-s -w -X github.com/enthus-appdev/n8n-cli/internal/cmd.version=${VERSION}" - - mkdir -p dist - - # Build for each platform - platforms=( - "linux/amd64" - "linux/arm64" - "darwin/amd64" - "darwin/arm64" - "windows/amd64" - "windows/arm64" - ) - - for platform in "${platforms[@]}"; do - GOOS=${platform%/*} - GOARCH=${platform#*/} - - output_name="n8nctl-${GOOS}-${GOARCH}" - if [ "$GOOS" = "windows" ]; then - output_name+=".exe" - fi - - echo "Building $output_name..." - GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "${LDFLAGS}" -o "dist/${output_name}" ./cmd/n8nctl - done - - # Create archives - cd dist - for file in n8nctl-*; do - if [[ "$file" == *.exe ]]; then - zip "${file%.exe}.zip" "$file" - rm "$file" - else - tar czf "${file}.tar.gz" "$file" - rm "$file" - fi - done - - # Generate checksums - sha256sum * > checksums.txt - - - name: Generate changelog - id: changelog - run: | - # Get previous tag - PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") - - if [ -n "$PREV_TAG" ]; then - CHANGELOG=$(git log --pretty=format:"- %s (%h)" "$PREV_TAG".."$GITHUB_REF_NAME" --no-merges) - else - CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges) - fi - - echo "changelog<> $GITHUB_OUTPUT - echo "$CHANGELOG" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - name: Create Release - uses: softprops/action-gh-release@v2 + - name: Generate GitHub App token for tap + id: app-token + uses: actions/create-github-app-token@v2 with: - name: ${{ github.ref_name }} - body: | - ## What's Changed - - ${{ steps.changelog.outputs.changelog }} - - ## Installation - - ### macOS (Apple Silicon) - ```bash - curl -L https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/n8nctl-darwin-arm64.tar.gz | tar xz - chmod +x n8nctl-darwin-arm64 - sudo mv n8nctl-darwin-arm64 /usr/local/bin/n8nctl - ``` - - ### macOS (Intel) - ```bash - curl -L https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/n8nctl-darwin-amd64.tar.gz | tar xz - chmod +x n8nctl-darwin-amd64 - sudo mv n8nctl-darwin-amd64 /usr/local/bin/n8nctl - ``` + app-id: ${{ secrets.HOMEBREW_TAP_APP_ID }} + private-key: ${{ secrets.HOMEBREW_TAP_APP_PRIVATE_KEY }} + owner: enthus-appdev + repositories: homebrew-tap - ### Linux (x64) - ```bash - curl -L https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/n8nctl-linux-amd64.tar.gz | tar xz - chmod +x n8nctl-linux-amd64 - sudo mv n8nctl-linux-amd64 /usr/local/bin/n8nctl - ``` - - ### Windows - Download `n8nctl-windows-amd64.zip` (or `n8nctl-windows-arm64.zip` for ARM) and add to your PATH. - - ## Checksums - - See `checksums.txt` for SHA256 checksums of all binaries. - files: | - dist/* - draft: false - prerelease: ${{ contains(github.ref_name, '-') }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_TAP_TOKEN: ${{ steps.app-token.outputs.token }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..b128689 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,69 @@ +version: 2 + +project_name: n8nctl + +builds: + - main: ./cmd/n8nctl + binary: n8nctl + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + ldflags: + - -s -w + - -X github.com/enthus-appdev/n8n-cli/internal/cmd.version={{.Version}} + - -X github.com/enthus-appdev/n8n-cli/internal/cmd.commit={{.ShortCommit}} + - -X github.com/enthus-appdev/n8n-cli/internal/cmd.date={{.Date}} + +archives: + - formats: + - tar.gz + format_overrides: + - goos: windows + formats: + - zip + +checksum: + name_template: checksums.txt + +changelog: + sort: asc + +release: + github: + owner: enthus-appdev + name: n8n-cli + header: | + ## Installation + + ### Homebrew (macOS and Linux) + ```bash + brew install enthus-appdev/tap/n8nctl + ``` + + ### Binary download + Download the archive for your platform below, extract, and add to your PATH. + +brews: + - name: n8nctl + repository: + owner: enthus-appdev + name: homebrew-tap + token: "{{ .Env.HOMEBREW_TAP_TOKEN }}" + directory: Formula + homepage: https://github.com/enthus-appdev/n8n-cli + description: "CLI for managing n8n workflows - pull, push, execute, activate" + license: MIT + commit_author: + name: enthus-appdev-tap-bumper[bot] + email: 275364917+enthus-appdev-tap-bumper[bot]@users.noreply.github.com + commit_msg_template: "chore(formula): bump {{ .ProjectName }} to {{ .Tag }}" + test: | + assert_match version.to_s, shell_output("#{bin}/n8nctl version") + install: | + bin.install "n8nctl" diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 6b622db..ecddd00 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -15,7 +15,9 @@ import ( ) var ( - version = "dev" + version = "dev" + commit = "none" + date = "unknown" jsonOutput bool ) @@ -51,10 +53,10 @@ func newVersionCmd() *cobra.Command { Short: "Print the version number", Run: func(cmd *cobra.Command, args []string) { if jsonOutput { - out, _ := json.Marshal(map[string]string{"version": version}) + out, _ := json.Marshal(map[string]string{"version": version, "commit": commit, "date": date}) fmt.Println(string(out)) } else { - fmt.Printf("n8n-cli %s\n", version) + fmt.Printf("n8n-cli %s\ncommit: %s\nbuilt: %s\n", version, commit, date) } }, }