-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (115 loc) · 4.13 KB
/
Copy pathrelease.yml
File metadata and controls
139 lines (115 loc) · 4.13 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
name: Release
on:
push:
tags:
- 'v*' # Triggers on tags like v1.0.0, v1.1.0, etc.
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
validate-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate tag matches Cargo.toml version
run: |
# Extract version from Cargo.toml
CARGO_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
# Extract version from git tag (remove 'v' prefix)
TAG_VERSION=${GITHUB_REF_NAME#v}
echo "Cargo.toml version: $CARGO_VERSION"
echo "Git tag version: $TAG_VERSION"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "❌ Version mismatch!"
echo "Cargo.toml version: $CARGO_VERSION"
echo "Git tag version: $TAG_VERSION"
exit 1
fi
echo "✅ Versions match!"
create-release:
needs: validate-version
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.result }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/github-script@v8
with:
script: |
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: context.ref.replace('refs/tags/', ''),
name: `Release ${context.ref.replace('refs/tags/', '')}`,
body: `## Changes in ${context.ref.replace('refs/tags/', '')}
See [CHANGELOG.md](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/${context.ref.replace('refs/tags/', '')}/CHANGELOG.md) for details.
## Installation
Download the appropriate binary for your platform below, or build from source:
\`\`\`bash
cargo install --git https://github.com/${context.repo.owner}/${context.repo.repo} --tag ${context.ref.replace('refs/tags/', '')}
\`\`\``,
draft: false,
prerelease: false
});
return data.id;
build-and-upload:
needs: create-release
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: espn-ffl-linux-x86_64
- target: x86_64-apple-darwin
os: macos-latest
name: espn-ffl-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: espn-ffl-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: espn-ffl-windows-x86_64.exe
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build binary
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare binary (Unix)
if: matrix.os != 'windows-latest'
run: |
cp target/${{ matrix.target }}/release/espn-ffl ${{ matrix.name }}
chmod +x ${{ matrix.name }}
- name: Prepare binary (Windows)
if: matrix.os == 'windows-latest'
run: |
cp target/${{ matrix.target }}/release/espn-ffl.exe ${{ matrix.name }}
- name: Upload binary
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ needs.create-release.outputs.release_id }},
name: '${{ matrix.name }}',
data: fs.readFileSync('${{ matrix.name }}')
});