-
Notifications
You must be signed in to change notification settings - Fork 1
189 lines (167 loc) · 5.99 KB
/
go.yml
File metadata and controls
189 lines (167 loc) · 5.99 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Go
on:
push:
branches: [ "master" ]
workflow_dispatch:
inputs:
bump:
description: "Which part of the version to bump?"
required: false
default: "patch"
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
jobs:
determine-version:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.next_version.outputs.tag }}
current_tag: ${{ steps.current_tag.outputs.previous_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Current Tag
id: current_tag
run: |
current_tag=$(git describe --tags --abbrev=0 HEAD^)
echo "Current tag: $current_tag"
echo "current_tag=$current_tag" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Determine next version
id: next_version
uses: actions/github-script@v6
env:
BUMP: ${{ github.event.inputs.bump || 'patch' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const bump = process.env.BUMP || 'patch';
console.log(`Selected bump: ${bump}`);
const latest = await github.rest.repos.getLatestRelease({ owner, repo }).catch(() => null);
const currentVersion = latest ? latest.data.tag_name.replace(/^v/, '') : '0.0.0';
let [major, minor, patch] = currentVersion.split('.').map(Number);
switch (bump) {
case 'major':
major++;
minor = 0;
patch = 0;
break;
case 'minor':
minor++;
patch = 0;
break;
default:
patch++;
}
const nextVersion = `v${major}.${minor}.${patch}`;
console.log(`Next version: ${nextVersion}`);
core.setOutput('tag', nextVersion);
build:
runs-on: ubuntu-latest
needs: determine-version
strategy:
matrix:
include:
- os: linux
arch: amd64
extension: ""
- os: linux
arch: arm64
extension: ""
- os: darwin
arch: arm64
extension: ""
- os: windows
arch: amd64
extension: ".exe"
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Fetch dependencies
run: go mod download
- name: Build for ${{ matrix.os }}_${{ matrix.arch }}
run: |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -v -ldflags "-X 'github.com/urumo/k3sd/utils.Version=${{ needs.determine-version.outputs.tag }}'" -o k3sd${{ matrix.extension }} ./cli/main.go
file k3sd${{ matrix.extension }}
chmod +x k3sd${{ matrix.extension }}
tar -czvf k3sd-${{ matrix.os }}-${{ matrix.arch }}.tar.gz k3sd${{ matrix.extension }}
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: k3sd-${{ matrix.os }}-${{ matrix.arch }}
path: |
k3sd${{ matrix.extension }}
k3sd-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
release:
runs-on: ubuntu-latest
needs: [ determine-version, build ]
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.determine-version.outputs.tag }}
release_name: Release ${{ needs.determine-version.outputs.tag }}
draft: false
body: |
**Full Changelog**: https://github.com/urumo/k3sd/compare/${{ needs.determine-version.outputs.current_tag }}...${{ needs.determine-version.outputs.tag }}
prerelease: false
- name: Upload Linux AMD64 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: ./k3sd-linux-amd64/k3sd-linux-amd64.tar.gz
asset_name: k3sd-linux-amd64.tar.gz
asset_content_type: application/gzip
- name: Upload Linux ARM64 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: ./k3sd-linux-arm64/k3sd-linux-arm64.tar.gz
asset_name: k3sd-linux-arm64.tar.gz
asset_content_type: application/gzip
- name: Upload Darwin ARM64 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: ./k3sd-darwin-arm64/k3sd-darwin-arm64.tar.gz
asset_name: k3sd-darwin-arm64.tar.gz
asset_content_type: application/gzip
- name: Upload Windows AMD64 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: ./k3sd-windows-amd64/k3sd-windows-amd64.tar.gz
asset_name: k3sd-windows-amd64.tar.gz
asset_content_type: application/gzip
- name: Upload Binary Assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./k3sd-linux-amd64/k3sd
asset_name: k3sd-linux-amd64
asset_content_type: application/octet-stream