Skip to content

Commit

Permalink
rework build system to support CGO
Browse files Browse the repository at this point in the history
for yubikey support we require CGO support. CGO on crosscompile is hard,
to avoid we build natively where suppported and disabled where not

since goreleaser does only support prebuilt archives in the pro version,
the brew publishing step had to be moved to a different github action
  • Loading branch information
bitte-ein-bit committed May 21, 2024
1 parent ff9bead commit 4889b74
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 1 deletion.
82 changes: 82 additions & 0 deletions .github/workflows/build-artifacts-and-draft-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build release artifacts and draft release

on:
push:
tags:
- "*.*.*"

jobs:
build-binary:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
cache: true
- if: ${{ matrix.platform == 'ubuntu-latest' }}
name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gcc-multilib
- name: Build
uses: goreleaser/goreleaser-action@v5
with:
args: release --skip=publish --config .goreleaser-${{ matrix.platform }}.yaml
- name: Upload
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-binary
path: dist/clisso*
retention-days: 2

draft-release:
needs: [build-binary]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: 1.22
check-latest: true
cache: true
- name: Make directories
run: |
mkdir -p ./release/linux
mkdir -p ./release/darwin
mkdir -p ./release/windows
- name: Download linux binaries
uses: actions/download-artifact@v4
with:
name: ubuntu-latest-binary
path: ./release/linux
- name: Download MacOS binaries
uses: actions/download-artifact@v4
with:
name: macos-latest-binary
path: ./release/darwin
- name: Download windows binaries
uses: actions/download-artifact@v4
with:
name: windows-latest-binary
path: ./release/windows
- name: Merge checksum file
run: |
cd ./release
find .
find . -name "clisso*checksums.txt" -exec sh -c 'cat {} >> checksums.txt' \;
find . -name "clisso*checksums.txt" -delete
- name: Release
uses: goreleaser/goreleaser-action@v5
with:
args: release --config .goreleaser-release.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 changes: 50 additions & 0 deletions .github/workflows/homebrew-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# .github/workflows/release.yml
# Start Homebrew Releaser when a new GitHub release is created
name: Update Homebrew Tap
on:
release:
types: [published]

jobs:
homebrew-releaser:
runs-on: ubuntu-latest
name: homebrew-releaser
steps:
- name: Release my project to my Homebrew tap
uses: Justintime50/homebrew-releaser@v1
with:
# The name of the homebrew tap to publish your formula to as it appears on GitHub.
# Required - strings
homebrew_owner: allcloud-io
homebrew_tap: homebrew-tools

# The name of the folder in your homebrew tap where formula will be committed to.
# Default is shown - string
formula_folder: .

# The Personal Access Token (saved as a repo secret) that has `repo` permissions for the repo running the action AND Homebrew tap you want to release to.
# Required - string
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

# Custom install command for your formula.
# Required - string
install: 'bin.install "clisso"'

# Adds URL and checksum targets for different OS and architecture pairs. Using this option assumes
# a tar archive exists on your GitHub repo with the following URL pattern (this cannot be customized):
# https://github.com/{GITHUB_OWNER}/{REPO_NAME}/releases/download/{TAG}/{REPO_NAME}-{VERSION}-{OPERATING_SYSTEM}-{ARCHITECTURE}.tar.gz'
# Darwin AMD pre-existing path example: https://github.com/justintime50/myrepo/releases/download/v1.2.0/myrepo-1.2.0-darwin-amd64.tar.gz
# Linux ARM pre-existing path example: https://github.com/justintime50/myrepo/releases/download/v1.2.0/myrepo-1.2.0-linux-arm64.tar.gz
# Optional - booleans
target_darwin_amd64: true
target_darwin_arm64: true
target_linux_amd64: true
target_linux_arm64: true

# Skips committing the generated formula to a homebrew tap (useful for local testing).
# Default is shown - boolean
skip_commit: false

# Logs debugging info to console.
# Default is shown - boolean
debug: false
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ steps_output.txt
bottle_output.txt

dist/
clisso.yaml
clisso.yaml
release/
33 changes: 33 additions & 0 deletions .goreleaser-macos-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
project_name: clisso
before:
hooks:
- go mod tidy

builds:
- id: macos-amd64
binary: clisso
env:
- CGO_ENABLED=1
goos:
- darwin
goarch:
- "amd64"
# hooks:
# post: gon gon-amd64.json
- id: macos-arm64
binary: clisso
env:
- CGO_ENABLED=1
goos:
- darwin
goarch:
- "arm64"
# hooks:
# post: gon gon-arm64.json

archives:
- format: tar.gz
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

snapshot:
name_template: "{{ incpatch .Version }}-next"
15 changes: 15 additions & 0 deletions .goreleaser-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
builds:
- skip: true
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
release:
draft: true
mode: append
extra_files:
- glob: ./release/**/*
- glob: ./release/checksums.txt
name_template: "Release {{.Tag}}"
45 changes: 45 additions & 0 deletions .goreleaser-ubuntu-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
project_name: clisso
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- id: linux
binary: clisso
env:
- CGO_ENABLED=1
goos:
- linux
goarch:
- "amd64"
- "386"

# The build-chain does not support CGO for ARM64 on Linux
- id: unsupported-cgo
binary: clisso
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- "arm64"
goarm:
- "6"
- "7"

archives:
- format: tar.gz
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
45 changes: 45 additions & 0 deletions .goreleaser-windows-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
project_name: clisso
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- id: windows
binary: clisso
env:
- CGO_ENABLED=1
goos:
- windows
goarch:
- "amd64"

# The build-chain does not support CGO for ARM64 and 386 on Windows
- id: unsupported-cgo
binary: clisso
env:
- CGO_ENABLED=0
goos:
- windows
goarch:
- "arm64"
- "386"
goarm:
- "6"
- "7"

archives:
- format: zip
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ builds:
- "7"
- id: macos-amd64
binary: clisso
env:
- CGO_ENABLED=1
goos:
- darwin
goarch:
Expand All @@ -28,6 +30,8 @@ builds:
# post: gon gon-amd64.json
- id: macos-arm64
binary: clisso
env:
- CGO_ENABLED=1
goos:
- darwin
goarch:
Expand Down

0 comments on commit 4889b74

Please sign in to comment.