-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (151 loc) · 5.47 KB
/
release.yml
File metadata and controls
173 lines (151 loc) · 5.47 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Release
on:
workflow_dispatch:
inputs:
release_notes:
description: "Release notes"
required: false
default: "New release"
publish_to_crates_io:
description: "Publish to crates.io"
required: true
default: true
type: boolean
jobs:
release:
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.get_next_release.outputs.next_release }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.update_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Get next release number
id: get_next_release
run: |
# Get the latest tag or start with 0 if no tags exist
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0")
latest_num=${latest_tag#v}
next_num=$((latest_num + 1))
echo "next_release=v$next_num" >> $GITHUB_OUTPUT
- name: Update version in Cargo.toml
id: update_version
run: |
# Extract version without 'v' prefix for semantic versioning
version="${{ steps.get_next_release.outputs.next_release }}"
version_number="${version#v}"
# Format as proper semantic version x.0.0
semver_version="$version_number.0.0"
# Update version in Cargo.toml
sed -i "s/^version = \".*\"/version = \"$semver_version\"/" Cargo.toml
echo "version=$semver_version" >> $GITHUB_OUTPUT
# Configure git for commit
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Commit the version change
git add Cargo.toml
git commit -m "Bump version to $semver_version for release"
# Use RELEASE_TOKEN for push
git remote set-url origin https://x-access-token:${{ secrets.RELEASE_TOKEN }}@github.com/${{ github.repository }}
git push
- name: Get binary name from Cargo.toml
id: get_binary_name
run: |
binary_name=$(grep -m 1 "name" Cargo.toml | cut -d '"' -f 2)
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
tag_name: ${{ steps.get_next_release.outputs.next_release }}
release_name: Release ${{ steps.get_next_release.outputs.next_release }}
body: ${{ github.event.inputs.release_notes }}
draft: false
prerelease: false
publish-to-crates-io:
needs: release
if: ${{ github.event.inputs.publish_to_crates_io == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main # Ensure we have the latest commit with version update
token: ${{ secrets.RELEASE_TOKEN }}
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Login to crates.io
uses: actions-rs/cargo@v1
with:
command: login
args: ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: --allow-dirty
build-and-upload:
needs: release
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: linux-amd64
binary_extension: ""
- os: macos-latest
target: x86_64-apple-darwin
name: macos-intel
binary_extension: ""
- os: macos-latest
target: aarch64-apple-darwin
name: macos-arm
binary_extension: ""
- os: windows-latest
target: x86_64-pc-windows-msvc
name: windows-amd64
binary_extension: ".exe"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main # Ensure we have the latest commit with version update
token: ${{ secrets.RELEASE_TOKEN }}
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Get binary name from Cargo.toml
id: get_binary_name
run: |
binary_name=$(grep -m 1 "name" Cargo.toml | cut -d '"' -f 2)
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
shell: bash
- name: Build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./target/${{ matrix.target }}/release/${{ steps.get_binary_name.outputs.binary_name }}${{ matrix.binary_extension }}
asset_name: ${{ steps.get_binary_name.outputs.binary_name }}-${{ needs.release.outputs.release_tag }}-${{ matrix.name }}${{ matrix.binary_extension }}
asset_content_type: application/octet-stream