-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (129 loc) · 4.72 KB
/
release.yml
File metadata and controls
152 lines (129 loc) · 4.72 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goos: [darwin, linux]
goarch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${{ steps.version.outputs.VERSION }}
COMMIT=$(git rev-parse --short HEAD)
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.buildDate=${BUILD_DATE}" \
-o devstrap_${{ matrix.goos }}_${{ matrix.goarch }} .
- name: Create tarball
run: |
VERSION=${{ steps.version.outputs.VERSION }}
ARCHIVE=devstrap_${VERSION#v}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
tar -czf ${ARCHIVE} devstrap_${{ matrix.goos }}_${{ matrix.goarch }}
echo "ARCHIVE=${ARCHIVE}" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: devstrap_${{ matrix.goos }}_${{ matrix.goarch }}
path: devstrap_*.tar.gz
release:
name: Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: List artifacts
run: ls -la artifacts/
- name: Generate checksums
run: |
cd artifacts
shasum -a 256 *.tar.gz > checksums.txt
cat checksums.txt
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Generate Homebrew formula
run: |
VERSION=${{ steps.version.outputs.VERSION }}
VERSION_NUM=${VERSION#v}
# Get checksums
DARWIN_AMD64_SHA=$(grep darwin_amd64 artifacts/checksums.txt | awk '{print $1}')
DARWIN_ARM64_SHA=$(grep darwin_arm64 artifacts/checksums.txt | awk '{print $1}')
LINUX_AMD64_SHA=$(grep linux_amd64 artifacts/checksums.txt | awk '{print $1}')
LINUX_ARM64_SHA=$(grep linux_arm64 artifacts/checksums.txt | awk '{print $1}')
cat > artifacts/devstrap.rb << EOF
# Homebrew formula for devstrap
# Generated automatically by GitHub Actions
class Devstrap < Formula
desc "Developer environment automation tool"
homepage "https://github.com/codoworks/devstrap"
version "${VERSION_NUM}"
license "MIT"
on_macos do
if Hardware::CPU.arm?
url "https://github.com/codoworks/devstrap/releases/download/${VERSION}/devstrap_${VERSION_NUM}_darwin_arm64.tar.gz"
sha256 "${DARWIN_ARM64_SHA}"
else
url "https://github.com/codoworks/devstrap/releases/download/${VERSION}/devstrap_${VERSION_NUM}_darwin_amd64.tar.gz"
sha256 "${DARWIN_AMD64_SHA}"
end
end
on_linux do
if Hardware::CPU.arm?
url "https://github.com/codoworks/devstrap/releases/download/${VERSION}/devstrap_${VERSION_NUM}_linux_arm64.tar.gz"
sha256 "${LINUX_ARM64_SHA}"
else
url "https://github.com/codoworks/devstrap/releases/download/${VERSION}/devstrap_${VERSION_NUM}_linux_amd64.tar.gz"
sha256 "${LINUX_AMD64_SHA}"
end
end
def install
bin.install "devstrap_#{OS.kernel_name.downcase}_#{Hardware::CPU.arch}" => "devstrap"
end
test do
system "#{bin}/devstrap", "--help"
end
end
EOF
echo "Generated Homebrew formula:"
cat artifacts/devstrap.rb
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/*.tar.gz
artifacts/checksums.txt
artifacts/devstrap.rb
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}