Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create and attach binaries on tag, release #91

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ name: Build
on:
workflow_dispatch:
push:
tags: [v*]
branches: [main]
paths-ignore:
- '**.md'
pull_request:
branches: [main]
release:
types: [published]

jobs:
build-chisel:
Expand All @@ -30,17 +34,82 @@ jobs:
machine_arch: 'S/390'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# The checkout action in previous step overwrites annonated tag
# with lightweight tags breaking ``git describe``
# See https://github.com/actions/checkout/issues/882
# and https://github.com/actions/checkout/issues/290
# The following step is a workaround to restore the latest tag
# to it's original state.
- name: Restore (annonated) tag
run: git fetch --force origin ${GITHUB_REF}:${GITHUB_REF}
if: ${{ github.ref_type == 'tag' }}

- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'

- name: Build Chisel for linux/${{ matrix.arch }}
run: GOARCH=${{ matrix.arch }} go build ./cmd/chisel/
id: build
env:
GOOS: "linux"
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: "0"
run: |
echo "Generating version file"
go generate ./cmd/

echo "Building for $GOOS $GOARCH"
go build -trimpath -ldflags='-s -w' ./cmd/chisel

# Get version via "chisel version" to ensure it matches that exactly
CHISEL_VERSION=$(GOOS=linux GOARCH=amd64 go run ./cmd/chisel version)
echo "Version: $CHISEL_VERSION"

# Version should not be "unknown"
[ "$CHISEL_VERSION" != "unknown" ] || exit 1
rebornplusplus marked this conversation as resolved.
Show resolved Hide resolved

# Share variables with subsequent steps
echo "CHISEL_VERSION=${CHISEL_VERSION}" >>$GITHUB_OUTPUT

- name: Test if is executable
run: test -x ./chisel

- name: Test if binary has the right machine architecture
run: |
[ "$(readelf -h chisel | grep 'Machine:' | awk -F' ' '{print $NF}')" == "${{ matrix.machine_arch }}" ]

- name: Create archive
id: archive
env:
GOOS: "linux"
GOARCH: ${{ matrix.arch }}
CHISEL_VERSION: ${{ steps.build.outputs.CHISEL_VERSION }}
run: |
ARCHIVE_FILE=chisel_${CHISEL_VERSION}_${GOOS}_${GOARCH}.tar.gz
echo "Creating archive $ARCHIVE_FILE"

mkdir -p dist/build
cp chisel LICENSE README.md dist/build
find dist/build -printf "%P\n" | tar -czf dist/$ARCHIVE_FILE --no-recursion -C dist/build -T -
jnsgruk marked this conversation as resolved.
Show resolved Hide resolved

# Share variables with subsequent steps
echo "ARCHIVE_FILE=${ARCHIVE_FILE}" >>$GITHUB_OUTPUT

- name: Upload archive as Actions artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.archive.outputs.ARCHIVE_FILE }}
path: dist/${{ steps.archive.outputs.ARCHIVE_FILE }}

- name: Upload archive to release
env:
CHISEL_VERSION: ${{ steps.build.outputs.CHISEL_VERSION }}
ARCHIVE_FILE: ${{ steps.archive.outputs.ARCHIVE_FILE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ github.event_name == 'release' }}
run: |
echo "Uploading $ARCHIVE_FILE to release $CHISEL_VERSION"
gh release upload $CHISEL_VERSION dist/$ARCHIVE_FILE
2 changes: 1 addition & 1 deletion cmd/mkversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if [ -z "$v" ]; then
if command -v git >/dev/null; then
# not using "--dirty" here until the following bug is fixed:
# https://bugs.launchpad.net/snapcraft/+bug/1662388
v="$(git describe --always | sed -e 's/-/+git/;y/-/./' )"
v="$(git describe --tags --always | sed -e 's/-/+git/;y/-/./' )"
o=git
fi
fi
Expand Down