-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (161 loc) · 5.67 KB
/
rust.yml
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
174
175
176
177
178
179
180
name: Rust
on:
push:
branches:
- master
env:
CARGO_TERM_COLOR: always
jobs:
trigger:
uses: ./.github/workflows/build.yml
check_tag:
needs: trigger
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from Cargo.toml
id: extract_version
run: |
version=$(cargo pkgid | cut -d# -f2 | cut -d: -f2)
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "::notice ::Version from Cargo.toml $version"
- name: Check if version is a Git tag
uses: mukunku/[email protected]
id: check_git_tag
with:
tag: '${{ steps.extract_version.outputs.version }}'
outputs:
version: ${{ steps.extract_version.outputs.version }}
exists: ${{ steps.check_git_tag.outputs.exists }}
tag:
if: ${{ needs.check_tag.outputs.exists == 'false' && github.ref == 'refs/heads/master' }}
needs: check_tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create tag
id: tagging
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git tag -a ${{ needs.check_tag.outputs.version }} -m "${{ needs.check_tag.outputs.version }}"
git push origin ${{ needs.check_tag.outputs.version }}
echo "::notice ::Created ${{ needs.check_tag.outputs.version }} tag"
echo "created=true" >> $GITHUB_OUTPUT
- name: Get Repository Name
id: repository
run: echo "name=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT
outputs:
created: ${{ steps.tagging.outputs.created }}
version: ${{ needs.check_tag.outputs.version }}
executable: ${{ steps.repository.outputs.name }}
release:
if: ${{ github.ref == 'refs/heads/master' && needs.tag.outputs.created == 'true'}}
needs: tag
runs-on: ${{ matrix.os }}
strategy:
matrix:
name: [
linux,
windows
]
include:
- name: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl
exec: target/x86_64-unknown-linux-musl/release/${{ needs.tag.outputs.executable }}
archive: x86_64-unknown-linux-musl.tgz
- name: windows
os: windows-latest
target: x86_64-pc-windows-msvc
exec: target/x86_64-pc-windows-msvc/release/${{ needs.tag.outputs.executable }}.exe
archive: x86_64-pc-windows-msvc.zip
steps:
- uses: actions/checkout@v4
- name: Install toolchain
uses: actions-rs/[email protected]
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Build ${{ matrix.target }} executable
id: build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Collect ${{ matrix.target }} executable
run: |
cp ${{ matrix.exec }} .
- name: Create ${{ matrix.target }} artifact
run: |
tar cvfz ${{ needs.tag.outputs.executable }}-${{ matrix.archive }} ${{ needs.tag.outputs.executable }}
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Create ${{ matrix.platform.file }} artifact
run: Compress-Archive -Path ${{ needs.tag.outputs.executable }}.exe -Destination ${{ needs.tag.outputs.executable }}-${{ matrix.archive }}
if: ${{ matrix.os == 'windows-latest' }}
- name: Upload ${{ matrix.platform.file }} artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.target }}
path: ${{ needs.tag.outputs.executable }}-${{ matrix.archive }}
- name: Print message
run: echo "::notice ::Created binary for ${{ matrix.target }}"
outputs:
version: ${{ needs.tag.outputs.version }}
publish:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cargo-bins/cargo-binstall@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install binaries required
run: cargo binstall -y --force rsign2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download files
uses: actions/download-artifact@v4
- run: find ./artifacts-* -type f \( -name "*.tgz" -o -name "*.zip" \)
- name: Sign artifacts
run: |
ls -l
.github/scripts/sign.sh Cargo.toml "$(find ./artifacts-* -type f \( -name "*.tgz" -o -name "*.zip" \))"
ls -l ./artifacts-*/*
ls -l minisign.pub
- name: Release
uses: softprops/action-gh-release@v2
with:
name: ${{ needs.release.outputs.version }}
tag_name: ${{ needs.release.outputs.version }}
files: |
./minisign.pub
./artifacts-*/*.tgz
./artifacts-*/*.tgz.sig
./artifacts-*/*.zip
./artifacts-*/*.zip.sig
- name: Print message
run: echo "::notice ::Created ${{ needs.release.outputs.version }} release"
cargo-publish:
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cargo publish --token ${CRATES_TOKEN}
env:
CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}