-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (132 loc) · 4.24 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
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@v3
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@v3
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 }}
file-name: release
- name: windows
os: windows-latest
target: x86_64-pc-windows-msvc
exec: target/x86_64-pc-windows-msvc/release/${{ needs.tag.outputs.executable }}.exe
file-name: release
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/[email protected]
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}
- name: Build
id: build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Upload file
uses: actions/[email protected]
with:
name: ${{ matrix.file-name }}
path: ${{ matrix.exec }}
- 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:
- name: Download files
uses: actions/[email protected]
- run: find
- name: Release
uses: softprops/action-gh-release@v1
with:
name: ${{ needs.release.outputs.version }}
tag_name: ${{ needs.release.outputs.version }}
files: ./release/*
- 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@v3
- name: Install stable toolchain
uses: actions-rs/[email protected]
with:
profile: minimal
toolchain: stable
override: true
- run: cargo publish --token ${CRATES_TOKEN}
env:
CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}