Skip to content

Commit e68310f

Browse files
rebornplusplusjnsgruk
authored andcommitted
chore: create and attach binaries on tag, release
Create binaries on push, tag creation and when a release has been published. Create an archive with the binary, and attach it to the release if a release is published. In all cases, attach the archive in the workflow run as an artifact. The actions/checkout@v3 action overwrites annonated tag with lightweight tags breaking ``git describe``. See [1], [2]. This commit adds a workaround to restore the latest tag to it's original state. References: - [1] actions/checkout#882 - [2] actions/checkout#290
1 parent 50b1cb3 commit e68310f

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

.github/workflows/build.yml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ name: Build
33
on:
44
workflow_dispatch:
55
push:
6+
tags: [v*]
7+
branches: [main]
68
paths-ignore:
79
- '**.md'
810
pull_request:
911
branches: [main]
12+
release:
13+
types: [published]
1014

1115
jobs:
1216
build-chisel:
@@ -30,17 +34,82 @@ jobs:
3034
machine_arch: 'S/390'
3135
steps:
3236
- uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
40+
# The checkout action in previous step overwrites annonated tag
41+
# with lightweight tags breaking ``git describe``
42+
# See https://github.com/actions/checkout/issues/882
43+
# and https://github.com/actions/checkout/issues/290
44+
# The following step is a workaround to restore the latest tag
45+
# to it's original state.
46+
- name: Restore (annonated) tag
47+
run: git fetch --force origin ${GITHUB_REF}:${GITHUB_REF}
48+
if: ${{ github.ref_type == 'tag' }}
3349

3450
- uses: actions/setup-go@v3
3551
with:
3652
go-version-file: 'go.mod'
3753

3854
- name: Build Chisel for linux/${{ matrix.arch }}
39-
run: GOARCH=${{ matrix.arch }} go build ./cmd/chisel/
55+
id: build
56+
env:
57+
GOOS: "linux"
58+
GOARCH: ${{ matrix.arch }}
59+
CGO_ENABLED: "0"
60+
run: |
61+
echo "Generating version file"
62+
go generate ./cmd/
63+
64+
echo "Building for $GOOS $GOARCH"
65+
go build -trimpath -ldflags='-s -w' ./cmd/chisel
66+
67+
# Get version via "chisel version" to ensure it matches that exactly
68+
CHISEL_VERSION=$(GOOS=linux GOARCH=amd64 go run ./cmd/chisel version)
69+
echo "Version: $CHISEL_VERSION"
70+
71+
# Version should not be "unknown"
72+
[ "$CHISEL_VERSION" != "unknown" ] || exit 1
73+
74+
# Share variables with subsequent steps
75+
echo "CHISEL_VERSION=${CHISEL_VERSION}" >>$GITHUB_OUTPUT
4076
4177
- name: Test if is executable
4278
run: test -x ./chisel
4379

4480
- name: Test if binary has the right machine architecture
4581
run: |
4682
[ "$(readelf -h chisel | grep 'Machine:' | awk -F' ' '{print $NF}')" == "${{ matrix.machine_arch }}" ]
83+
84+
- name: Create archive
85+
id: archive
86+
env:
87+
GOOS: "linux"
88+
GOARCH: ${{ matrix.arch }}
89+
CHISEL_VERSION: ${{ steps.build.outputs.CHISEL_VERSION }}
90+
run: |
91+
ARCHIVE_FILE=chisel_${CHISEL_VERSION}_${GOOS}_${GOARCH}.tar.gz
92+
echo "Creating archive $ARCHIVE_FILE"
93+
94+
mkdir -p dist/build
95+
cp chisel LICENSE README.md dist/build
96+
find dist/build -printf "%P\n" | tar -czf dist/$ARCHIVE_FILE --no-recursion -C dist/build -T -
97+
98+
# Share variables with subsequent steps
99+
echo "ARCHIVE_FILE=${ARCHIVE_FILE}" >>$GITHUB_OUTPUT
100+
101+
- name: Upload archive as Actions artifact
102+
uses: actions/upload-artifact@v3
103+
with:
104+
name: ${{ steps.archive.outputs.ARCHIVE_FILE }}
105+
path: dist/${{ steps.archive.outputs.ARCHIVE_FILE }}
106+
107+
- name: Upload archive to release
108+
env:
109+
CHISEL_VERSION: ${{ steps.build.outputs.CHISEL_VERSION }}
110+
ARCHIVE_FILE: ${{ steps.archive.outputs.ARCHIVE_FILE }}
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
if: ${{ github.event_name == 'release' }}
113+
run: |
114+
echo "Uploading $ARCHIVE_FILE to release $CHISEL_VERSION"
115+
gh release upload $CHISEL_VERSION dist/$ARCHIVE_FILE

0 commit comments

Comments
 (0)