Skip to content

Commit a132763

Browse files
authored
Create release.yml
1 parent f13c7ec commit a132763

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Rust Release
2+
3+
on:
4+
release:
5+
types: [created] # Trigger when a new GitHub release is created
6+
7+
jobs:
8+
build:
9+
name: Build Rust Binaries
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
include:
15+
- os: ubuntu-latest
16+
target: x86_64-unknown-linux-gnu
17+
artifact: myapp-linux
18+
- os: macos-latest
19+
target: x86_64-apple-darwin
20+
artifact: myapp-macos
21+
- os: windows-latest
22+
target: x86_64-pc-windows-msvc
23+
artifact: myapp-windows.exe
24+
25+
steps:
26+
- name: Checkout Repository
27+
uses: actions/checkout@v4
28+
29+
- name: Install Rust Toolchain
30+
uses: dtolnay/rust-toolchain@stable
31+
with:
32+
targets: ${{ matrix.target }}
33+
34+
- name: Build Release Binary
35+
run: cargo build --release --target ${{ matrix.target }}
36+
37+
- name: Rename Binary
38+
run: |
39+
mkdir artifacts
40+
if [ "${{ runner.os }}" == "Windows" ]; then
41+
mv target/${{ matrix.target }}/release/myapp.exe artifacts/${{ matrix.artifact }}
42+
else
43+
mv target/${{ matrix.target }}/release/myapp artifacts/${{ matrix.artifact }}
44+
fi
45+
shell: bash
46+
47+
- name: Upload Binary
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: ${{ matrix.artifact }}
51+
path: artifacts/${{ matrix.artifact }}
52+
53+
release:
54+
name: Upload to GitHub Release
55+
needs: build
56+
runs-on: ubuntu-latest
57+
permissions:
58+
contents: write
59+
60+
steps:
61+
- name: Download All Binaries
62+
uses: actions/download-artifact@v4
63+
with:
64+
path: artifacts
65+
66+
- name: Display Downloaded Files
67+
run: ls -R artifacts
68+
69+
- name: Upload Binaries to GitHub Release
70+
uses: softprops/action-gh-release@v2
71+
with:
72+
files: artifacts/**/*
73+
fail_on_unmatched_files: true
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)