Skip to content

Commit

Permalink
Build & publish pre-release and release artifacts
Browse files Browse the repository at this point in the history
Fixes the build and publish workflows so they successfully publish an
array of artifacts to GitHub alongside a release.
  • Loading branch information
rustydb committed Aug 8, 2023
1 parent 1bef070 commit 05fab2c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 62 deletions.
71 changes: 41 additions & 30 deletions .github/workflows/promote-prerelease.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
name: Build a pre-release
env:
GO_VERSION: '1.20'
name: Build and publish a pre-release
on:
push:
tags:
Expand All @@ -10,39 +8,52 @@ on:
workflow_dispatch:

jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
hash_file_command: 'shasum -a 256'
- os: macos-latest
hash_file_command: 'shasum -a 256'
- os: windows-latest
hash_file_command: 'get-filehash -Algorithm SHA256'
build-and-promote:
runs-on: ${{ matrix.os }}
make-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: lint
run: |
make bin/gru
echo GOOS=$(go env GOOS) >> $GITHUB_ENV
echo GOARCH=$(go env GOARCH) >> $GITHUB_ENV
- name: write binary checksum
run: |
${{ matrix.hash_file_command }} bin/gru-${{ env.GOOS }}-${{ env.GOARCH }}* >> bin/gru-${{ env.GOOS }}-${{ env.GOARCH }}.sha256sum
- uses: ncipollo/release-action@v1
with:
allowUpdates: true # if the job is re-ran to catch missed artifacts, allow updates
generateReleaseNotes: true
# artifacts: ${{ env.DIR_UPLOAD }}/*
prerelease: true
makeLatest: false

build-and-promote:
needs: make-release
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm64]
exclude:
- goarch: "386"
goos: darwin
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3

- name: Set variables
run: |
GO_VERSION=$(grep -Eo "^go .*" go.mod | cut -d " " -f2)
echo $GO_VERSION
echo GO_VERSION=$GO_VERSION >> $GITHUB_ENV
TAG=${GITHUB_REF##*/}
echo $TAG
echo TAG=$TAG >> $GITHUB_ENV
REPO_NAME="${GITHUB_REPOSITORY#*/}"
echo $REPO_NAME
echo REPO_NAME=$REPO_NAME >> $GITHUB_ENV
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: ${{ env.GO_VERSION }}
build_command: "make ${{ env.REPO_NAME }}"
release_tag: ${{ env.TAG }}
md5sum: 'FALSE'
sha256sum: 'TRUE'
72 changes: 41 additions & 31 deletions .github/workflows/promote-release.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
name: Build a release
env:
GO_VERSION: '1.20'
name: Build and publish a release
on:
push:
tags:
- 'v?[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:

jobs:
strategy:
matrix:
include:
- os: ubuntu-latest
hash_file_command: 'shasum -a 256'
- os: macos-latest
hash_file_command: 'shasum -a 256'
- os: windows-latest
hash_file_command: 'get-filehash -Algorithm SHA256'
build-and-promote:
runs-on: ${{ matrix.os }}
make-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: lint
run: |
make bin/gru
echo GOOS=$(go env GOOS) >> $GITHUB_ENV
echo GOARCH=$(go env GOARCH) >> $GITHUB_ENV
- name: write binary checksum
run: |
${{ matrix.hash_file_command }} bin/gru-${{ env.GOOS }}-${{ env.GOARCH }}* >> bin/gru-${{ env.GOOS }}-${{ env.GOARCH }}.sha256sum
- uses: ncipollo/release-action@v1
with:
allowUpdates: true # if the job is re-ran to catch missed artifacts, allow updates
generateReleaseNotes: true
artifacts:
- bin/gru-${{ env.GOOS }}-${{ env.GOARCH }}*
prerelease: false
makeLatest: true

build-and-promote:
needs: make-release
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm64]
exclude:
- goarch: "386"
goos: darwin
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3

- name: Set variables
run: |
GO_VERSION=$(grep -Eo "^go .*" go.mod | cut -d " " -f2)
echo $GO_VERSION
echo GO_VERSION=$GO_VERSION >> $GITHUB_ENV
TAG=${GITHUB_REF##*/}
echo $TAG
echo TAG=$TAG >> $GITHUB_ENV
REPO_NAME="${GITHUB_REPOSITORY#*/}"
echo $REPO_NAME
echo REPO_NAME=$REPO_NAME >> $GITHUB_ENV
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: ${{ env.GO_VERSION }}
build_command: "make ${{ env.REPO_NAME }}"
release_tag: ${{ env.TAG }}
md5sum: 'FALSE'
sha256sum: 'TRUE'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ vendor/

build/
gru.y[a?]ml

gru
gru-*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ build: tidy $(addprefix bin/,$(binaries))

go_build := $(go_path) go build $(go_flags) -ldflags '$(go_ldflags)' -o

bin/%: cmd/% FORCE
%: cmd/% FORCE
@echo Building $@
$(E)$(go_build) $@$(exe) ./$<
cp $@$(exe) $@-$(GOOS)-$(GOARCH)$(exe)
Expand Down

0 comments on commit 05fab2c

Please sign in to comment.