-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (59 loc) · 2.18 KB
/
build.yml
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
name: Build
on:
push:
branches: [ main ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.21.x]
os: [linux, darwin, windows]
steps:
# Check out
- uses: actions/checkout@v4
# Prepare build
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Extract project version
id: project_version
run: echo "version=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)" >> $GITHUB_STATE
- name: Extract commit hash
id: git_commit
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Download dependencies
run: go mod tidy
# Build
- name: Build
run: |
env GOOS=${{ matrix.os }} GOARCH=amd64 go build -o colorexp-${{ matrix.os }}-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }} colorexp.go
- name: Upload artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: colorexp-${{ matrix.os }}-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}
path: colorexp-${{ matrix.os }}-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}
# Create a GitHub release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.version }}
release_name: Release ${{ env.version }}
draft: false
prerelease: false
# Upload release asset for each OS
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./colorexp-${{ matrix.os }}-amd64-${{ env.version }}-${{ env.sha }}
asset_name: colorexp-${{ matrix.os }}-amd64-${{ env.version }}-${{ env.sha }}
asset_content_type: application/octet-stream