-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (96 loc) · 2.85 KB
/
release.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
on:
push:
tags:
- "*/v*.*.*"
name: "Release"
jobs:
crate-info:
name: "Extract crate info"
runs-on: "ubuntu-latest"
outputs:
crate: ${{ steps.derive.outputs.crate }}
version: ${{ steps.derive.outputs.version }}
steps:
- id: "derive"
name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "crate=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "version=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
# Just in case we accidentally release something not on master.
commit-branch-check:
name: "Check commit branch"
runs-on: "ubuntu-latest"
needs:
- "crate-info"
steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
with:
fetch-depth: 0
- name: "Check if commit is on master"
run: |
COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }})
GREP_OUTPUT=$(git log origin/master --format=%H | grep "$COMMIT_HASH")
if [ -z "$GREP_OUTPUT" ]; then
echo "Cannot release commits not on the master branch"
exit 1
fi
crate-version-check:
name: "Check crate version"
runs-on: "ubuntu-latest"
needs:
- "crate-info"
steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
- name: "Check against Cargo.toml"
run: |
cd ${{ needs.crate-info.outputs.crate }}
GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${{ needs.crate-info.outputs.version }}\"$")
if [ -z "$GREP_OUTPUT" ]; then
echo "Crate version mismatch"
exit 1
fi
build:
name: "Build for ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
needs:
- "crate-info"
strategy:
matrix:
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"
steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
- name: "Setup stable toolchain"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
profile: "minimal"
override: true
- name: "Build crate"
run: |
cargo build --package ${{ needs.crate-info.outputs.crate }} --all-targets
crates-io-release:
name: "Release to crates.io"
runs-on: "ubuntu-latest"
needs:
- "crate-info"
- "commit-branch-check"
- "crate-version-check"
- "build"
steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
- name: "Login to crates.io"
run: |
cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
- name: "Publish crate"
run: |
cargo publish --package ${{ needs.crate-info.outputs.crate }}