-
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (84 loc) · 3.05 KB
/
Copy pathrelease.yml
File metadata and controls
99 lines (84 loc) · 3.05 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
name: Release
on:
push:
branches: ["main"]
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
jobs:
check-version:
name: Check Version & Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
created: ${{ steps.check_tag.outputs.created }}
steps:
- uses: actions/checkout@v6
- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Get version from Cargo.toml
id: get_version
run: |
# Use cargo metadata for robust version extraction
VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
echo "Detected version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
# Check if tag v{version} already exists in remote
if git ls-remote --exit-code --tags origin "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
echo "Tag v${{ steps.get_version.outputs.version }} already exists. Skipping release."
echo "created=false" >> $GITHUB_OUTPUT
else
echo "Tag v${{ steps.get_version.outputs.version }} does not exist. Proceeding with release."
echo "created=true" >> $GITHUB_OUTPUT
fi
build-and-release:
name: Build & Release (Windows)
needs: check-version
if: needs.check-version.outputs.created == 'true'
runs-on: windows-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc
- name: Cache cargo registry
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run Tests
run: cargo test --release --verbose
- name: Build Release Binary
run: cargo build --release --verbose
- name: Rename Binary
run: |
mv target/release/sed.exe target/release/sed-v${{ needs.check-version.outputs.version }}.exe
shell: bash
- name: Generate Checksum
run: |
cd target/release
sha256sum sed-v${{ needs.check-version.outputs.version }}.exe > sed-v${{ needs.check-version.outputs.version }}.exe.sha256
shell: bash
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.check-version.outputs.version }}
name: v${{ needs.check-version.outputs.version }}
files: |
target/release/sed-v${{ needs.check-version.outputs.version }}.exe
target/release/sed-v${{ needs.check-version.outputs.version }}.exe.sha256
generate_release_notes: true
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}