-
Notifications
You must be signed in to change notification settings - Fork 3
164 lines (138 loc) · 4.57 KB
/
Copy pathrelease.yml
File metadata and controls
164 lines (138 loc) · 4.57 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# 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: Release build
on:
push:
tags:
- 'v*'
jobs:
Testing:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [amd64, arm64]
exclude:
- os: windows-latest
arch: arm64
runs-on: ${{ matrix.os }}
steps:
- name: CheckOut
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '>=1.22.0'
- name: Run tests with race detector
shell: bash
run: |
go test -race -timeout 5m ./...
Build:
runs-on: ${{ matrix.os }}
needs: Testing
strategy:
matrix:
include:
- os: ubuntu-latest, GOOS: linux, GOARCH: amd64
- os: ubuntu-latest, GOOS: linux, GOARCH: arm64
- os: windows-latest, GOOS: windows, GOARCH: amd64
- os: macos-latest, GOOS: darwin, GOARCH: amd64
- os: macos-latest, GOOS: darwin, GOARCH: arm64
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '>=1.22.0'
- name: Get latest tag
run: |
echo "LATEST_TAG=$(git tag | grep -v '^latest$' | sort -V | tail -n1)" >> $GITHUB_ENV
- name: Build binary
shell: bash
run: |
go build -ldflags="-X main.Version=${{ env.LATEST_TAG }}" -o ctl_device_${{ matrix.GOOS }}_${{ matrix.GOARCH }} ./cmd/ctl_device
- name: Upload binary to artifacts
uses: actions/upload-artifact@v4
with:
name: ctl_device_${{ matrix.GOOS }}_${{ matrix.GOARCH }}
path: ctl_device_${{ matrix.GOOS }}_${{ matrix.GOARCH }}
Release:
runs-on: ubuntu-latest
needs: [Testing, Build]
outputs:
UPLOAD_URL: ${{ steps.stepCreateRelease.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Get latest tag
run: |
echo "LATEST_TAG=$(git tag | grep -v '^latest$' | sort -V | tail -n1)" >> $GITHUB_ENV
- name: Bump version and push tag
id: tag-version
uses: mathieudutour/github-tag-action@v6.2
with:
tag_prefix: ""
custom_tag: ${{ env.LATEST_TAG }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate SHA256 checksums
run: |
cd ./artifacts
for f in ctl_device_*; do
sha256sum "$f" > "${f}.sha256"
done
cd ..
- name: Step GitHub release
id: stepCreateRelease
uses: ncipollo/release-action@v1
with:
skipIfReleaseExists: 'true'
tag: ${{ env.LATEST_TAG }}
name: ${{ env.LATEST_TAG }}
artifacts: ./artifacts/*
RemoveOldRelease:
runs-on: ubuntu-latest
needs: Release
steps:
- name: CheckOut
uses: actions/checkout@v6
- name: Set APP_VERSION env
run: |
APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) \
function get_pre_del_tag {
local v_str=$1
baseStr=$(echo $v_str | cut -d'.' -f1)
base=${baseStr//v/}
major=$(echo $v_str | cut -d'.' -f2)
minor=$(echo $v_str | cut -d'.' -f3)
if ((minor>0)); then
minor=$((minor-1))
else
minor=999
if ((major>0)); then
major=$((major-1))
else
major=999
if ((base>0)); then
base=$((base-1))
else
echo "Error: Version cannot be decremented."
exit 1
fi
fi
fi
pre_v_no="v${base}.${major}.${minor}"
echo $pre_v_no
}
APP_OLD_VERSION=$(get_pre_del_tag $(get_pre_del_tag $APP_VERSION))
echo "Old version to remove: ${APP_OLD_VERSION}"
echo APP_OLD_VERSION=${APP_OLD_VERSION} >> ${GITHUB_ENV}
- name: Remove Old Release
run: |
gh release delete ${{ env.APP_OLD_VERSION }} -y
git push origin --delete ${{ env.APP_OLD_VERSION }}
env:
GH_TOKEN: ${{ github.token }}