-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-release-artifacts.yaml
More file actions
78 lines (75 loc) · 2.51 KB
/
generate-release-artifacts.yaml
File metadata and controls
78 lines (75 loc) · 2.51 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
name: Generate release artifacts
on:
release:
types: [released]
jobs:
debug_info:
name: Debug info
runs-on: ubuntu-24.04
steps:
- name: Print github context JSON
run: |
cat <<EOF
${{ toJson(github) }}
EOF
gather_facts:
name: Gather facts
runs-on: ubuntu-24.04
outputs:
ref_version: ${{ steps.ref_version.outputs.refversion }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get version
id: get_version
env:
TAG_NAME: ${{ github.event.release.tag_name }}
run: |
version="${TAG_NAME#v}" # Strip "v" prefix.
echo "version=${version}"
echo "version=${version}" >> $GITHUB_OUTPUT
create_and_upload_build_artifacts:
name: Create and upload build artifacts
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
platform:
- darwin-amd64
- darwin-arm64
- linux-amd64
- linux-arm64
env:
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
GO_VERSION: 1.26.1
ARTIFACT_DIR: bin-dist
TAG: v${{ needs.gather_facts.outputs.version }}
needs:
- gather_facts
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v6.3.0
with:
go-version: ${{ env.GO_VERSION }}
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ env.TAG }}
- name: Build ${{ matrix.platform }} binary
run: |
platform="${{ matrix.platform }}"
os="${platform%-*}"
arch="${platform##*-}"
mkdir -p ${{ env.ARTIFACT_DIR }}
GOOS="$os" GOARCH="$arch" go build \
-ldflags "-X github.com/glitchcrab/sonar/pkg/project.version=${{ needs.gather_facts.outputs.version }}" \
-o ${{ env.ARTIFACT_DIR }}/${{ github.event.repository.name }} .
tar -czf ${{ env.ARTIFACT_DIR }}/${{ github.event.repository.name }}-${{ env.TAG }}-${{ matrix.platform }}.tar.gz \
-C ${{ env.ARTIFACT_DIR }} ${{ github.event.repository.name }}
rm ${{ env.ARTIFACT_DIR }}/${{ github.event.repository.name }}
- name: Add ${{ matrix.platform }} package to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
FILE_NAME="${{ github.event.repository.name }}-${{ env.TAG }}-${{ matrix.platform }}.tar.gz"
gh release upload ${{ env.TAG }} \
${{ env.ARTIFACT_DIR }}/${FILE_NAME}#${FILE_NAME}