Skip to content

Commit 602498a

Browse files
Dewn5228SimaoMoreira5228
authored andcommitted
add GitHub Actions workflow for rust-analyzer release
1 parent 123f57b commit 602498a

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
name: Release rust-analyzer
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- scuffle-fork
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
env:
13+
CARGO_INCREMENTAL: 0
14+
CARGO_NET_RETRY: 10
15+
RUSTFLAGS: "-D warnings -W unreachable-pub"
16+
RUSTUP_MAX_RETRIES: 10
17+
FETCH_DEPTH: 0
18+
MACOSX_DEPLOYMENT_TARGET: 14.0
19+
ZIG_VERSION: 0.13.0
20+
ZIGBUILD_VERSION: 0.19.8
21+
22+
jobs:
23+
builds:
24+
strategy:
25+
matrix:
26+
include:
27+
- runner: ubuntu-24.04
28+
os: linux
29+
arch: x86_64
30+
- runner: ubuntu-24.04-arm
31+
os: linux
32+
arch: aarch64
33+
- runner: windows-2022
34+
os: windows
35+
arch: x86_64
36+
- runner: windows-11-arm
37+
os: windows
38+
arch: aarch64
39+
- runner: macos-15-intel
40+
os: darwin
41+
arch: x86_64
42+
- runner: macos-15
43+
os: darwin
44+
arch: aarch64
45+
46+
runs-on: ${{ matrix.runner }}
47+
env:
48+
NAME: "rust-analyzer-${{ matrix.os }}-${{ matrix.arch }}"
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
fetch-depth: ${{ env.FETCH_DEPTH }}
53+
54+
- name: Install zstd (Linux)
55+
if: ${{ runner.os == 'Linux' }}
56+
run: sudo apt-get update && sudo apt-get install -y zstd
57+
58+
- name: Install zstd (Windows)
59+
if: ${{ runner.os == 'Windows' }}
60+
uses: MinoruSekine/setup-scoop@v4.0.2
61+
with:
62+
buckets: main
63+
apps: zstd
64+
65+
- name: Install zstd (macOS)
66+
if: ${{ runner.os == 'macOS' }}
67+
run: brew install zstd
68+
69+
- name: Install Rust toolchain
70+
run: |
71+
rustup update --no-self-update stable
72+
rustup component add rust-src
73+
74+
- name: Build rust-analyzer
75+
run: cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release
76+
77+
- name: Generate archive
78+
run: |
79+
mkdir -p artifacts-archive
80+
BIN_NAME="rust-analyzer${{ runner.os == 'Windows' && '.exe' || '' }}"
81+
82+
mkdir -p "${NAME}"
83+
cp "target/release/${BIN_NAME}" "${NAME}/"
84+
85+
tar -cf - "${NAME}" | zstd --ultra -22 -o "artifacts-archive/${NAME}.tar.zst"
86+
87+
- name: Upload artifact
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: ${{ env.NAME }}
91+
path: artifacts-archive/${{ env.NAME }}.tar.zst
92+
93+
release:
94+
needs: builds
95+
runs-on: ubuntu-22.04
96+
permissions:
97+
contents: write
98+
env:
99+
TAG_NAME: commit-${{ github.sha }}
100+
steps:
101+
- name: Download artifacts
102+
uses: actions/download-artifact@v4
103+
with:
104+
path: ./artifacts
105+
106+
- name: Generate dotslash file
107+
run: |
108+
set -euo pipefail
109+
shopt -s globstar
110+
111+
BASE_URL="https://github.com/${{ github.repository }}/releases/download/${{ env.TAG_NAME }}/"
112+
113+
cat > rust-analyzer <<'EOF'
114+
#!/usr/bin/env dotslash
115+
116+
{
117+
"name": "rust-analyzer",
118+
"platforms": {
119+
EOF
120+
121+
for archive in ./artifacts/**/*.tar.zst; do
122+
FILE_NAME=$(basename "$archive")
123+
SHA=$(sha256sum "$archive" | awk '{print $1}')
124+
NAME="${FILE_NAME%.tar.zst}"
125+
126+
# Parse os and arch from name
127+
if [[ "$NAME" =~ rust-analyzer-([^-]+)-([^-]+) ]]; then
128+
OS="${BASH_REMATCH[1]}"
129+
ARCH="${BASH_REMATCH[2]}"
130+
131+
# Map to dotslash format
132+
case "$OS-$ARCH" in
133+
"linux-x86_64")
134+
PLATFORM="linux-x86_64"
135+
;;
136+
"linux-aarch64")
137+
PLATFORM="linux-aarch64"
138+
;;
139+
"darwin-x86_64")
140+
PLATFORM="macos-x86_64"
141+
;;
142+
"darwin-aarch64")
143+
PLATFORM="macos-aarch64"
144+
;;
145+
"windows-x86_64")
146+
PLATFORM="windows-x86_64"
147+
;;
148+
*)
149+
echo "Unknown platform: $OS-$ARCH"
150+
continue
151+
;;
152+
esac
153+
154+
cat >> rust-analyzer <<EOF
155+
"$PLATFORM": {
156+
"size": $(stat -c%s "$archive" 2>/dev/null || stat -f%z "$archive"),
157+
"hash": "sha256",
158+
"digest": "$SHA",
159+
"format": "tar.zst",
160+
"path": "$NAME/rust-analyzer",
161+
"providers": [
162+
{
163+
"url": "${BASE_URL}${FILE_NAME}"
164+
}
165+
]
166+
},
167+
EOF
168+
fi
169+
done
170+
171+
# Remove trailing comma and close JSON
172+
sed -i '$ s/,$//' rust-analyzer
173+
cat >> rust-analyzer <<'EOF'
174+
}
175+
}
176+
EOF
177+
178+
cat rust-analyzer
179+
180+
- name: Generate release body
181+
run: |
182+
set -euo pipefail
183+
shopt -s globstar
184+
185+
cat > release_body.txt <<EOF
186+
# rust-analyzer build for commit ${{ github.sha }}
187+
188+
## DotSlash Usage
189+
190+
Download the \`rust-analyzer\` dotslash file and make it executable:
191+
192+
\`\`\`bash
193+
curl -LO "${BASE_URL}rust-analyzer"
194+
chmod +x rust-analyzer
195+
./rust-analyzer --version
196+
\`\`\`
197+
198+
## Manual Download
199+
200+
Download the appropriate archive for your platform:
201+
202+
EOF
203+
204+
for archive in ./artifacts/**/*.tar.zst; do
205+
FILE_NAME=$(basename "$archive")
206+
SHA=$(sha256sum "$archive" | awk '{print $1}')
207+
208+
echo "- [\`$FILE_NAME\`](${BASE_URL}${FILE_NAME}) (sha256: \`$SHA\`)" >> release_body.txt
209+
done
210+
211+
cat release_body.txt
212+
env:
213+
BASE_URL: "https://github.com/${{ github.repository }}/releases/download/${{ env.TAG_NAME }}/"
214+
215+
- name: Create GitHub Release
216+
uses: softprops/action-gh-release@v2
217+
with:
218+
tag_name: ${{ env.TAG_NAME }}
219+
name: "rust-analyzer build for ${{ github.sha }}"
220+
body_path: release_body.txt
221+
files: |
222+
./artifacts/**/*.tar.zst
223+
rust-analyzer
224+
env:
225+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)