Skip to content

Commit

Permalink
Use GoReleaser to build binaries
Browse files Browse the repository at this point in the history
This replaces most of the manual workflow steps. GoReleaser config
tweaked to match the current release filenames.

Signed-off-by: Matt Dainty <[email protected]>
  • Loading branch information
bodgit committed Aug 10, 2023
1 parent 54f4dc2 commit f2ebd42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 57 deletions.
76 changes: 19 additions & 57 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ on:
push:
branches:
- main

release:
types: [published]
tags:
- v*

pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions:
contents: write
pull-requests: read

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand All @@ -24,8 +27,10 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: '^1.18.8' # The Go version to download (if necessary) and use.
- name: Install Build Dependencies
Expand All @@ -39,59 +44,16 @@ jobs:
- name: Cover
run: make cover
- name: Build
run: |
set -ex
for dist in amd64 arm64; do
target=out/wait-for-port-linux-$dist
rm -rf "$target"
make build/$dist TOOL_PATH="$target"
file $target
tar -C "$(dirname "$target")" -czf "$target.tar.gz" "$(basename "$target")"
done
- uses: actions/upload-artifact@v2
with:
name: built-binaries
path: |
out/*.tar.gz
release:
needs: [ 'build-and-test' ]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
uses: goreleaser/goreleaser-action@v4
if: ! startsWith(github.ref, 'refs/tags/')
with:
path: ./artifacts
- name: Set tag name
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
version: latest
args: build --snapshot --clean
- name: Release
run: |
set -e
create_digest_file() {
local digest_file=${1:?You must provide the digest file path}
shift
for file in "$@"; do
(
cd "$(dirname "$file")"
sha256sum "$(basename "$file")"
) >> "$digest_file"
done
}
assets=( ./artifacts/built-binaries/*.gz )
tag_name="${{ steps.vars.outputs.tag }}"
checksums_file="${tag_name}_checksums.txt"
create_digest_file "$checksums_file" "${assets[@]}"
assets+=( "$checksums_file" )
if gh release view "$tag_name" >/dev/null 2>/dev/null; then
echo "Release $tag_name already exists. Updating"
gh release upload "$tag_name" "${assets[@]}"
else
echo "Creating new release $tag_name"
# Format checksums for the release text
printf '```\n%s\n```' "$(<"$checksums_file")" > release.txt
gh release create -t "$tag_name" "$tag_name" -F release.txt "${assets[@]}"
fi
uses: goreleaser/goreleaser-action@v4
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
out/
/dist
12 changes: 12 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
env:
- CGO_ENABLED=0
builds:
- targets:
- linux_amd64
- linux_arm64
archives:
- name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
checksum:
name_template: '{{ .Version }}_checksums.txt'
changelog:
use: github-native

0 comments on commit f2ebd42

Please sign in to comment.