-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (115 loc) · 3.66 KB
/
go.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
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
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Build and release
run-name: <${{ github.ref_name }}> Build and release
on:
push:
tags:
- 'v*.*.*'
jobs:
context:
name: Dump context
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Exit if not on master branch
if: github.event.base_ref && endsWith(github.event.base_ref, 'master') == false
run: exit 1
- name: Write release version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- run: sudo apt-get update -y && sudo apt-get install tree zip -y
- name: Show directory tree before build
run: tree
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.5'
- name: Test
run: go test -v ./...
- name: Create artifacts directory
run: mkdir artifacts
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Build for different platforms
run: |
PLATFORMS=($(go tool dist list | grep -E '^windows|^linux/(amd64|arm|386)|^darwin'))
SUPPORTED_EXTENSIONS=$(python scripts/compute_supported_extensions.py)
LDFLAGS="-X 'main.supported_extensions=$SUPPORTED_EXTENSIONS' -X 'main.version=$VERSION'"
for PLATFORM in "${PLATFORMS[@]}"
do
arr=(${PLATFORM//\// })
echo "${arr[0]}/${arr[1]}"
GOOS=${arr[0]} GOARCH=${arr[1]} FLAGS=$LDFLAGS bash -c '
go build -o out/ -ldflags "$FLAGS" &&
echo "$LDFLAGS" &&
cp {LICENSE,README.md} out/ &&
zip -j artifacts/${{ github.event.repository.name }}_$GOOS-$GOARCH.zip out/*
rm -rf out/*'
done
- name: Show directory tree after build
run: tree
- name: Upload Build Artifact
uses: actions/[email protected]
with:
name: build-artifact
path: ./artifacts
if-no-files-found: error
release:
name: Github release
permissions:
contents: write
runs-on: ubuntu-latest
needs: build
steps:
- name: Write release version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Download Build Artifact
uses: actions/[email protected]
with:
name: build-artifact
path: ./artifacts
- name: Show directory tree before release
run: tree
- name: Create Git Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ./artifacts/*
fail_on_unmatched_files: true
body: |
This is the release for ${{ github.ref_name }}