-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (132 loc) · 4.06 KB
/
Copy pathrelease.yml
File metadata and controls
149 lines (132 loc) · 4.06 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Semantic version tag to release, for example v0.1.0'
required: true
type: string
permissions:
contents: write
jobs:
build:
name: Build release artifacts
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
archive: tar.gz
- goos: linux
goarch: arm64
archive: tar.gz
- goos: darwin
goarch: amd64
archive: tar.gz
- goos: darwin
goarch: arm64
archive: tar.gz
- goos: windows
goarch: amd64
archive: zip
steps:
- name: Check out source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Resolve release metadata
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION="${GITHUB_REF_NAME}"
else
VERSION="${{ inputs.version }}"
fi
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
echo "Version must be a semantic version tag like v0.1.0 or v0.1.0-rc.1" >&2
exit 1
fi
COMMIT="$(git rev-parse --short=12 HEAD)"
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
BINARY_NAME="quickpod-cli"
if [[ "${{ matrix.goos }}" == "windows" ]]; then
BINARY_NAME="quickpod-cli.exe"
fi
ARCHIVE_BASENAME="quickpod-cli_${VERSION#v}_${{ matrix.goos }}_${{ matrix.goarch }}"
{
echo "VERSION=$VERSION"
echo "COMMIT=$COMMIT"
echo "BUILD_DATE=$BUILD_DATE"
echo "BINARY_NAME=$BINARY_NAME"
echo "ARCHIVE_BASENAME=$ARCHIVE_BASENAME"
} >> "$GITHUB_ENV"
- name: Build binary
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
set -euo pipefail
mkdir -p dist
go build \
-trimpath \
-buildvcs=true \
-ldflags "-s -w -X quickpod-cli/internal/version.Version=${VERSION} -X quickpod-cli/internal/version.Commit=${COMMIT} -X quickpod-cli/internal/version.BuildDate=${BUILD_DATE}" \
-o "dist/${BINARY_NAME}" \
.
- name: Package archive
shell: bash
run: |
set -euo pipefail
mkdir -p release
if [[ "${{ matrix.archive }}" == "zip" ]]; then
cd dist
zip -q "../release/${ARCHIVE_BASENAME}.zip" "${BINARY_NAME}"
cd ..
else
tar -C dist -czf "release/${ARCHIVE_BASENAME}.tar.gz" "${BINARY_NAME}"
fi
sha256sum "release/${ARCHIVE_BASENAME}.${{ matrix.archive }}" > "release/${ARCHIVE_BASENAME}.${{ matrix.archive }}.sha256"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_BASENAME }}
path: release/*
release:
name: Publish GitHub release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: release-artifacts
merge-multiple: true
- name: Resolve release version
id: meta
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION="${GITHUB_REF_NAME}"
else
VERSION="${{ inputs.version }}"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Publish release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.version }}
generate_release_notes: true
files: release-artifacts/*