-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (192 loc) · 7.09 KB
/
release.yml
File metadata and controls
223 lines (192 loc) · 7.09 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
release:
if: startsWith(github.ref, 'refs/tags/v')
name: Release ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: sshdb-linux-x86_64
asset_name: sshdb-linux-x86_64.tar.gz
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: sshdb-macos-x86_64
asset_name: sshdb-macos-x86_64.tar.gz
- os: macos-14
target: aarch64-apple-darwin
artifact_name: sshdb-macos-aarch64
asset_name: sshdb-macos-aarch64.tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: sshdb-windows-x86_64
asset_name: sshdb-windows-x86_64.zip
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag and update Cargo.toml
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/v}
sed -i.bak "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml
rm Cargo.toml.bak
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }} --verbose
- name: Prepare release asset (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd target/${{ matrix.target }}/release
Compress-Archive -Path sshdb.exe -DestinationPath ${{ github.workspace }}/${{ matrix.asset_name }} -Force
- name: Prepare release asset (Unix)
if: matrix.os != 'windows-latest'
shell: bash
run: |
cd target/${{ matrix.target }}/release
tar czf ${{ github.workspace }}/${{ matrix.asset_name }} sshdb
- name: Upload release asset
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.asset_name }}
retention-days: 30
create-release:
if: startsWith(github.ref, 'refs/tags/v')
name: Create Release
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Extract version from tag
id: tag
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Install Rust toolchain (for git-cliff)
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Install git-cliff
run: |
cargo install --locked git-cliff
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Generate changelog from git history
run: git-cliff --config .gitcliff.toml --latest --output release-notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate checksums
run: |
find artifacts -type f \( -name "sshdb-*.tar.gz" -o -name "sshdb-*.zip" \) -print0 \
| sort -z \
| xargs -0 sha256sum > checksums.txt
- name: Generate Homebrew formula and push tap
if: "${{ env.HOMEBREW_TAP_TOKEN != '' }}"
env:
VERSION: ${{ steps.tag.outputs.VERSION }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
set -euo pipefail
TAR_URL="https://github.com/ruphy/sshdb/archive/refs/tags/v${VERSION}.tar.gz"
SHA256=$(curl -L "$TAR_URL" | shasum -a 256 | awk '{print $1}')
TAP_DIR=$(mktemp -d)
git config --global user.name "sshdb-release-bot"
git config --global user.email "sshdb-release-bot@users.noreply.github.com"
git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/ruphy/homebrew-sshdb" "${TAP_DIR}"
mkdir -p "${TAP_DIR}/Formula"
cat > "${TAP_DIR}/Formula/sshdb.rb" <<EOF
class Sshdb < Formula
desc "Keyboard-first SSH library and launcher TUI"
homepage "https://github.com/ruphy/sshdb"
url "${TAR_URL}"
sha256 "${SHA256}"
license "GPL-3.0-or-later"
depends_on "rust" => :build
def install
system "cargo", "install", *std_cargo_args
end
test do
system "#{bin}/sshdb", "--help"
end
end
EOF
cd "${TAP_DIR}"
git add Formula/sshdb.rb
if git diff --cached --quiet; then
echo "No changes to commit for tap."
else
git commit -m "sshdb ${VERSION}"
git push origin HEAD:main
fi
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: Release ${{ steps.tag.outputs.VERSION }}
body_path: release-notes.md
files: |
artifacts/*/sshdb-*.tar.gz
artifacts/*/sshdb-*.zip
checksums.txt
draft: false
prerelease: false
- name: Checkout main branch
run: |
git config --global user.name "sshdb-release-bot"
git config --global user.email "sshdb-release-bot@users.noreply.github.com"
git checkout main || git checkout master
- name: Update Cargo.toml with release version
run: |
VERSION="${{ steps.tag.outputs.VERSION }}"
sed -i.bak "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml
rm Cargo.toml.bak
git add Cargo.toml
git commit -m "chore: update version to ${VERSION} for release" || echo "No changes to commit"
- name: Bump Cargo.toml to dev version
run: |
VERSION="${{ steps.tag.outputs.VERSION }}"
sed -i.bak "s/^version = \".*\"/version = \"${VERSION}-dev\"/" Cargo.toml
rm Cargo.toml.bak
git add Cargo.toml
git commit -m "chore: bump version to ${VERSION}-dev" || echo "No changes to commit"
- name: Push version updates
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}
git push origin main || git push origin master