-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (136 loc) · 4.62 KB
/
release.yml
File metadata and controls
154 lines (136 loc) · 4.62 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
# Build cross-platform binaries + Windows MSI, publish to GitHub Releases.
# Trigger: push a tag like v0.1.0, or run manually via workflow_dispatch.
name: Release
on:
push:
tags: ['v[0-9]+.[0-9]+.[0-9]+*']
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v0.1.0)'
required: true
type: string
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: forgeStat
jobs:
build:
name: Build ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux x86_64
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- name: macOS x86_64
target: x86_64-apple-darwin
os: macos-latest
- name: macOS ARM64
target: aarch64-apple-darwin
os: macos-latest
- name: Windows x86_64
target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
- name: Determine version tag
id: meta
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package tar.gz (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
staging="${{ env.BINARY_NAME }}-${{ steps.meta.outputs.tag }}-${{ matrix.target }}"
mkdir "$staging"
cp "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" "$staging/"
tar czf "$staging.tar.gz" "$staging"
- name: Package ZIP (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$staging = "${{ env.BINARY_NAME }}-${{ steps.meta.outputs.tag }}-${{ matrix.target }}"
New-Item -ItemType Directory -Path $staging | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" "$staging/"
Compress-Archive -Path "$staging/*" -DestinationPath "$staging.zip"
- name: Build MSI installer (Windows)
if: runner.os == 'Windows'
continue-on-error: true
shell: pwsh
run: |
cargo install cargo-wix
cargo wix --no-build --target ${{ matrix.target }} --output .
Get-ChildItem *.msi | ForEach-Object {
$newName = "${{ env.BINARY_NAME }}-${{ steps.meta.outputs.tag }}-${{ matrix.target }}.msi"
Rename-Item $_.FullName $newName
Write-Host "Created MSI: $newName"
}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.target }}
path: |
*.tar.gz
*.zip
*.msi
if-no-files-found: error
publish:
name: Publish GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Determine version tag
id: meta
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
path: dist/
pattern: release-*
merge-multiple: true
- name: Prepare release assets
shell: bash
run: |
cp scripts/install.sh dist/install.sh
cp scripts/install.ps1 dist/install.ps1
chmod +x dist/install.sh
(cd dist && sha256sum *.tar.gz *.zip *.msi 2>/dev/null > SHA256SUMS.txt) || true
echo "=== Release assets ==="
ls -lh dist/
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
tag="${{ steps.meta.outputs.tag }}"
if ! gh release view "$tag" &>/dev/null; then
gh release create "$tag" --title "forgeStat $tag" --generate-notes
fi
for f in dist/*; do
echo "Uploading $(basename "$f")..."
gh release upload "$tag" "$f" --clobber
done