Skip to content

Commit

Permalink
Add build step to release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuchiki committed Oct 26, 2023
1 parent 8c69c76 commit b65de76
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 64 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@ on:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
goreleaser:
build_and_release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Go
uses: actions/setup-go@v4
- name: Build
uses: crazy-max/ghaction-xgo@v3
with:
go-version-file: go.mod
xgo_version: latest
go_version: 1.21
dest: build
prefix: slp
pkg: ./cmd/slp/
targets: windows/amd64,windows/arm64,linux/amd64,linux/arm64,linux/mips64,linux/mips64le,darwin/amd64,darwin/arm64,freebsd/amd64,freebsd/arm64,netbsd/amd64,netbsd/arm64,openbsd/amd64,openbsd/arm64,solaris/amd64,solaris/arm64,
v: true
x: false
race: false
ldflags: -s -w
buildmode: default
trimpath: true
- name: Archive binaries
run: |
bash ./scripts/ci/archive.sh "${GITHUB_REF#refs/*/}"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ dist
cmd/slp/slp
from.yaml
to.yaml
/build/
68 changes: 10 additions & 58 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,11 @@
before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=1
main: ./cmd/slp/main.go
binary: slp
ldflags:
- -s -w
- -X main.version={{.Version}}
flags:
- -trimpath
goos:
- linux
- darwin
- windows
- freebsd
- netbsd
- openbsd
- solaris
goarch:
- amd64
- arm64
- mips64
- mips64le
ignore:
- goos: darwin
goarch: 386
- goos: freebsd
goarch: 386
- goos: netbsd
goarch: 386
- goos: openbsd
goarch: 386
- goos: linux
goarch: 386
- goos: windows
goarch: 386
- goos: freebsd
goarch: arm
- goos: netbsd
goarch: arm
- goos: netbsd
goarch: arm
- goos: linux
goarch: arm

archives:
- id: tar-gz
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
files:
- none*
- id: zip
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
files:
- none*
format: zip
- binary: slp
skip: true
release:
github:
owner: tkuchiki
name: slp
extra_files:
- glob: "build/*.zip"
- glob: "build/*.tar.gz"
- glob: "build/*_checksums.txt"
25 changes: 25 additions & 0 deletions scripts/ci/archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

bin="slp"
version="${1}"

set -e

cd build
for file in ./${bin}-* ; do
dir=$(echo ${file} | awk -F'-' -v bin=${bin} '{print bin"_"$(NF-1)"_"$(NF)}')
mkdir ${dir}
mv ${file} ${dir}/${bin}
# zip
zip ${dir}.zip -j ${dir}/${bin} ../README.md ../LICENSE
# tar
cd ${dir}
cp ../../README.md .
cp ../../LICENSE .
tar czf ${dir}.tar.gz ${bin} README.md LICENSE
mv ${dir}.tar.gz ../
cd ../
rm -rf ${dir}
done

shasum -a 256 *.zip > ${bin}_${version}_checksums.txt

0 comments on commit b65de76

Please sign in to comment.