-
Notifications
You must be signed in to change notification settings - Fork 1
186 lines (158 loc) · 5.83 KB
/
build-and-release.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
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
name: Build and Release
on:
push:
branches: [main]
tags: ['v*']
# pull_request:
# branches: [main]
permissions:
contents: write
discussions: write
pull-requests: read
packages: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: stakpak
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: stakpak-linux-x86_64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: stakpak-darwin-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: stakpak-darwin-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: stakpak-windows-x86_64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Run tests
run: cargo test --target ${{ matrix.target }}
- name: Prepare binary
if: startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
cd target/${{ matrix.target }}/release
if [ "$RUNNER_OS" == "Windows" ]; then
7z a ../../../${{ matrix.artifact_name }}.zip ${{ env.BINARY_NAME }}.exe
else
tar czf ../../../${{ matrix.artifact_name }}.tar.gz ${{ env.BINARY_NAME }}
fi
- name: Upload artifact
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_name }}.*
retention-days: 1
release:
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
stakpak-linux-x86_64/stakpak-linux-x86_64.tar.gz
stakpak-darwin-x86_64/stakpak-darwin-x86_64.tar.gz
stakpak-darwin-aarch64/stakpak-darwin-aarch64.tar.gz
stakpak-windows-x86_64/stakpak-windows-x86_64.zip
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
needs: build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract tag version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }}
ghcr.io/${{ github.repository }}:latest
homebrew:
needs: release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: stakpak/homebrew-stakpak
token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
- name: Update Homebrew formula
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
run: |
VERSION=${GITHUB_REF#refs/tags/v}
curl -L "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/stakpak-darwin-x86_64.tar.gz" -o stakpak-darwin-x86_64.tar.gz
curl -L "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/stakpak-darwin-aarch64.tar.gz" -o stakpak-darwin-aarch64.tar.gz
curl -L "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/stakpak-linux-x86_64.tar.gz" -o stakpak-linux-x86_64.tar.gz
SHA256_DARWIN_X64=$(sha256sum stakpak-darwin-x86_64.tar.gz | cut -d ' ' -f 1)
SHA256_DARWIN_ARM=$(sha256sum stakpak-darwin-aarch64.tar.gz | cut -d ' ' -f 1)
SHA256_LINUX_X64=$(sha256sum stakpak-linux-x86_64.tar.gz | cut -d ' ' -f 1)
cat > stakpak.rb << EOF
class Stakpak < Formula
desc "Stakpak CLI tool"
homepage "https://github.com/stakpak/stakpak"
version "${VERSION}"
on_macos do
if Hardware::CPU.arm?
url "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/stakpak-darwin-aarch64.tar.gz"
sha256 "${SHA256_DARWIN_ARM}"
else
url "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/stakpak-darwin-x86_64.tar.gz"
sha256 "${SHA256_DARWIN_X64}"
end
end
on_linux do
url "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/stakpak-linux-x86_64.tar.gz"
sha256 "${SHA256_LINUX_X64}"
end
def install
bin.install "stakpak"
end
end
EOF
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add stakpak.rb
git commit -m "Update stakpak to v${VERSION}"
git push