-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 2.8 KB
/
Copy pathrelease.yml
File metadata and controls
85 lines (75 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: release
# Build cross-platform rossoctl binaries and attach them to the GitHub release.
# Assets are named to match the download URL:
# rossoctl-${ROSSOCTL_CLI_VERSION}-${OSEXT}-${OS_ARCH}.tar.gz
# where ROSSOCTL_CLI_VERSION is the release tag, OSEXT is a `uname` value
# (Linux, Darwin) and OS_ARCH is a `uname -m` value (x86_64, arm64).
on:
release:
types: [published]
# Manual trigger for testing: attaches assets to an existing release/tag.
workflow_dispatch:
inputs:
tag:
description: "Release tag to build and upload assets for (e.g. v0.1.0)"
required: true
permissions:
contents: write # required to upload release assets
jobs:
build:
name: build ${{ matrix.osext }}-${{ matrix.os_arch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { osext: Linux, os_arch: x86_64, goos: linux, goarch: amd64 }
- { osext: Linux, os_arch: arm64, goos: linux, goarch: arm64 }
- { osext: Darwin, os_arch: x86_64, goos: darwin, goarch: amd64 }
- { osext: Darwin, os_arch: arm64, goos: darwin, goarch: arm64 }
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Resolve version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
version="${{ github.event.release.tag_name }}"
else
version="${{ github.event.inputs.tag }}"
fi
if [ -z "$version" ]; then
echo "could not determine release version" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Build and package
id: package
env:
VERSION: ${{ steps.version.outputs.version }}
OSEXT: ${{ matrix.osext }}
OS_ARCH: ${{ matrix.os_arch }}
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
run: |
set -euo pipefail
pkg="github.com/rossoctl/rossoctl-cli/cmd"
commit="$(git rev-parse --short HEAD)"
date="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
ldflags="-s -w \
-X '${pkg}.version=${VERSION}' \
-X '${pkg}.commit=${commit}' \
-X '${pkg}.date=${date}'"
mkdir -p dist/rossoctl
go build -trimpath -ldflags "$ldflags" -o dist/rossoctl/rossoctl .
archive="rossoctl-${VERSION}-${OSEXT}-${OS_ARCH}.tar.gz"
tar -czf "$archive" -C dist/rossoctl rossoctl
echo "archive=$archive" >> "$GITHUB_OUTPUT"
- name: Upload asset to release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.version }}
files: ${{ steps.package.outputs.archive }}