-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (99 loc) · 2.93 KB
/
Copy pathrelease.yml
File metadata and controls
114 lines (99 loc) · 2.93 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
build:
name: Build and Release
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
suffix: ""
- goos: linux
goarch: arm64
suffix: ""
- goos: darwin
goarch: amd64
suffix: ""
- goos: darwin
goarch: arm64
suffix: ""
- goos: windows
goarch: amd64
suffix: ".exe"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Get version
id: version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION="dev-$(git rev-parse --short HEAD)"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Building version: $VERSION"
- name: Build binary
env:
CGO_ENABLED: 0
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
BINARY_NAME="deps-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }}"
go build -ldflags="-s -w -X main.version=${{ steps.version.outputs.version }}" -trimpath -o "$BINARY_NAME" *.go
# Create tarball for unix systems, zip for windows
if [[ "${{ matrix.goos }}" == "windows" ]]; then
zip "${BINARY_NAME%.exe}.zip" "$BINARY_NAME"
echo "ASSET=${BINARY_NAME%.exe}.zip" >> $GITHUB_ENV
else
tar -czf "${BINARY_NAME}.tar.gz" "$BINARY_NAME"
echo "ASSET=${BINARY_NAME}.tar.gz" >> $GITHUB_ENV
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: deps-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ env.ASSET }}
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Get version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
files: |
./artifacts/*/deps-*.tar.gz
./artifacts/*/deps-*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}