-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (124 loc) · 3.92 KB
/
go-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
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
name: Build and Release
on:
push:
branches:
- master
tags:
- 'v*.*.*' # Match version tags, e.g., v1.0.0
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
include:
- goos: linux
goarch: amd64
dir: rune
extension: "-linux-amd64"
- goos: linux
goarch: arm64
dir: rune
extension: "-linux-arm64"
- goos: windows
goarch: amd64
dir: rune
extension: "-windows-amd64.exe"
- goos: windows
goarch: arm64
dir: rune
extension: "-windows-arm64.exe"
- goos: darwin
goarch: amd64
dir: rune
extension: "-darwin-amd64"
- goos: darwin
goarch: arm64
dir: rune
extension: "-darwin-arm64"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '^1.22'
cache: false
- name: Install dependencies
run: go mod tidy
- name: Build
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.dir }}/rune${{ matrix.extension }} ./rune
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: rune-${{ matrix.goos }}-${{ matrix.goarch }}
path: rune
- name: Log Upload Artifacts
run: |
echo "Uploaded artifacts:"
ls -l rune/
release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: List Downloaded Artifacts
run: |
echo "Listing contents of the artifacts directory:"
ls -R artifacts
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
name: Release ${{ github.ref_name }}
body: Release of version ${{ github.ref_name }}
draft: false
prerelease: false
- name: Upload Release Assets
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs').promises;
const path = require('path');
const artifacts = [
'artifacts/rune-linux-amd64/rune-linux-amd64',
'artifacts/rune-linux-arm64/rune-linux-arm64',
'artifacts/rune-windows-amd64/rune-windows-amd64.exe',
'artifacts/rune-windows-arm64/rune-windows-arm64.exe',
'artifacts/rune-darwin-amd64/rune-darwin-amd64',
'artifacts/rune-darwin-arm64/rune-darwin-arm64'
];
for (const artifact of artifacts) {
try {
const data = await fs.readFile(artifact);
const fileName = path.basename(artifact);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.create_release.outputs.id }},
name: fileName,
data: data
});
console.log(`Uploaded ${fileName}`);
} catch (error) {
console.error(`Error uploading ${artifact}: ${error.message}`);
}
}