136 lines (121 loc) · 4.03 KB
/
release-version.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
name: "Publish to crates.io"
on:
push:
branches:
- '!**'
tags:
- '0.10.[0-9]+-?*'
env:
# Note: used for test and clippy, not for publish
GDRUST_FEATURES: "gdnative/async,gdnative/serde,gdnative_bindings_generator/debug"
# Crates to publish -- important, this doesn't work when there are spaces in any of the paths!
GDRUST_CRATES: >
impl/proc-macros
gdnative-sys
gdnative-derive
gdnative-core
bindings-generator
gdnative-bindings
gdnative-async
gdnative
defaults:
run:
shell: bash
jobs:
validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# sed: https://unix.stackexchange.com/a/589584
- name: "Interpret tag version"
run: |
version=$(echo "$GITHUB_REF" | sed -n "s#refs/tags/\(.*\)#\1#p")
[ -z "$version" ] && {
printf "\nError: Failed to parse '$GITHUB_REF'.\n"
exit 2
}
echo "Published version: $version"
echo "GDRUST_PUBLISHED_VERSION=$version" >> $GITHUB_ENV
- name: "Verify that Cargo.toml versions match ${{ env.GDRUST_PUBLISHED_VERSION }}"
run: |
echo "Checking crate versions..."
# Check if each Cargo.toml has that version
IFS=' ' read -r -a publishedCrates <<< "$GDRUST_CRATES"
for crate in "${publishedCrates[@]}"; do
readVersion=$(grep -Po '^version = "\K[^"]*' "$crate/Cargo.toml")
printf "* $crate -> $readVersion"
if [[ "$readVersion" != "$GDRUST_PUBLISHED_VERSION" ]]; then
printf " ERROR\n"
versionMismatch="1"
else
printf "\n"
fi
done
if [[ -n "$versionMismatch" ]]; then
printf "\nError: At least one crate has a version mismatching the git tag.\n"
exit 2
else
printf "\nAll versions OK.\n"
fi
test:
runs-on: ubuntu-latest
needs: validation
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: "Compile tests"
run: cargo test --workspace --features ${GDRUST_FEATURES} --no-run
- name: "Test"
run: cargo test --workspace --features ${GDRUST_FEATURES}
clippy:
runs-on: ubuntu-latest
needs: validation
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: "Check clippy"
run: cargo clippy --workspace --features ${GDRUST_FEATURES} -- -D clippy::style -D clippy::complexity -D clippy::perf -D clippy::dbg_macro -D clippy::todo -D clippy::unimplemented
rustfmt:
runs-on: ubuntu-latest
needs: validation
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: "Check rustfmt"
run: cargo fmt --all -- --check
publish:
runs-on: ubuntu-latest
environment: Deploy
needs: [test, clippy, rustfmt]
steps:
# Note: we cannot dry-run the publishing, since crates depend on each other, and dry-run will fail if they aren't yet on crates.io.
# Sleep to leave crates.io and docs.rs some time to index the dependencies, before releasing dependents.
- uses: actions/checkout@v2
- name: "Execute crates.io publishing"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
run: |
IFS=' ' read -r -a publishedCrates <<< "$GDRUST_CRATES"
for crate in "${publishedCrates[@]}"; do
echo "Publish $crate..."
(cd "$crate" && cargo publish) || {
printf "\nError: Failed to publish $crate\n"
exit 2
}
echo "Wait..."
sleep 40s
done