Skip to content

Commit 6e4debd

Browse files
committed
Improve publishing CI
1 parent e90e8c1 commit 6e4debd

File tree

1 file changed

+106
-28
lines changed

1 file changed

+106
-28
lines changed

.github/workflows/release-version.yml

Lines changed: 106 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,133 @@
1-
name: Publish to crates.io
1+
name: "Publish to crates.io"
22

33
on:
44
push:
55
branches:
66
- '!**'
77
tags:
8-
- '0.9.[0-9]+'
9-
- '0.10.[0-9]+'
8+
- '0.10.[0-9]+-?*'
109

1110
env:
1211
GDRUST_FEATURES: "gdnative/async,gdnative/serde"
1312

13+
# Crates to publish -- important, this doesn't work when there are spaces in any of the paths!
14+
GDRUST_CRATES: >
15+
impl/proc-macros
16+
gdnative-sys
17+
gdnative-derive
18+
gdnative-core
19+
bindings-generator
20+
gdnative-bindings
21+
gdnative-async
22+
gdnative
23+
1424
defaults:
1525
run:
1626
shell: bash
1727

1828
jobs:
19-
publish:
29+
validation:
2030
runs-on: ubuntu-latest
21-
environment: Deploy
2231
steps:
2332
- uses: actions/checkout@v2
2433

25-
- uses: actions-rs/toolchain@b2417cde72dcf67f306c0ae8e0828a81bf0b189f
34+
# sed: https://unix.stackexchange.com/a/589584
35+
- name: "Interpret tag version"
36+
run: |
37+
version=$(echo "$GITHUB_REF" | sed -n "s#refs/tags/\(.*\)#\1#p")
38+
[ -z "$version" ] && {
39+
printf "\nError: Failed to parse '$GITHUB_REF'.\n"
40+
exit 2
41+
}
42+
43+
echo "Published version: $version"
44+
echo "GDRUST_PUBLISHED_VERSION=$version" >> $GITHUB_ENV
45+
46+
- name: "Verify that Cargo.toml versions match ${{ env.GDRUST_PUBLISHED_VERSION }}"
47+
run: |
48+
echo "Checking crate versions..."
49+
50+
# Check if each Cargo.toml has that version
51+
IFS=' ' read -r -a publishedCrates <<< "$GDRUST_CRATES"
52+
for crate in "${publishedCrates[@]}"; do
53+
readVersion=$(grep -Po '^version = "\K[^"]*' "$crate/Cargo.toml")
54+
printf "* $crate -> $readVersion"
55+
56+
if [[ "$readVersion" != "$GDRUST_PUBLISHED_VERSION" ]]; then
57+
printf " ERROR\n"
58+
versionMismatch="1"
59+
else
60+
printf "\n"
61+
fi
62+
done
63+
64+
if [[ -n "$versionMismatch" ]]; then
65+
printf "\nError: At least one crate has a version mismatching the git tag.\n"
66+
exit 2
67+
else
68+
printf "\nAll versions OK.\n"
69+
fi
70+
71+
test:
72+
runs-on: ubuntu-latest
73+
needs: validation
74+
steps:
75+
- uses: actions/checkout@v2
76+
- uses: actions-rs/toolchain@v1
2677
with:
2778
profile: minimal
2879
toolchain: stable
29-
components: rustfmt, clippy
80+
override: true
81+
- name: "Compile tests"
82+
run: cargo test --workspace --features ${GDRUST_FEATURES} --no-run
83+
- name: "Test"
84+
run: cargo test --workspace --features ${GDRUST_FEATURES}
3085

31-
- name: "Sanity tests"
32-
run: |
33-
cargo fmt --all -- --check;
34-
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;
35-
cargo test --workspace --features ${GDRUST_FEATURES};
86+
clippy:
87+
runs-on: ubuntu-latest
88+
needs: validation
89+
steps:
90+
- uses: actions/checkout@v2
91+
- uses: actions-rs/toolchain@v1
92+
with:
93+
profile: minimal
94+
toolchain: stable
95+
override: true
96+
components: clippy
97+
- name: "Check clippy"
98+
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
99+
100+
rustfmt:
101+
runs-on: ubuntu-latest
102+
needs: validation
103+
steps:
104+
- uses: actions/checkout@v2
105+
- uses: actions-rs/toolchain@v1
106+
with:
107+
profile: minimal
108+
toolchain: stable
109+
override: true
110+
components: rustfmt
111+
- name: "Check rustfmt"
112+
run: cargo fmt --all -- --check
36113

37-
- name: "Publish to crates.io"
114+
publish:
115+
runs-on: ubuntu-latest
116+
environment: Deploy
117+
needs: [test, clippy, rustfmt]
118+
steps:
119+
# 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.
120+
# Sleep to leave crates.io and docs.rs some time to index the dependencies, before releasing dependents.
121+
- uses: actions/checkout@v2
122+
- name: "Execute crates.io publishing"
38123
env:
39124
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
40125
run: |
41-
(cd impl/proc-macros && cargo publish);
42-
sleep 1m;
43-
(cd gdnative-sys && cargo publish);
44-
sleep 1m;
45-
(cd gdnative-derive && cargo publish);
46-
sleep 1m;
47-
(cd gdnative-core && cargo publish);
48-
sleep 1m;
49-
(cd bindings-generator && cargo publish);
50-
sleep 1m;
51-
(cd gdnative-bindings && cargo publish);
52-
sleep 1m;
53-
(cd gdnative-async && cargo publish);
54-
sleep 1m;
55-
(cd gdnative && cargo publish);
126+
IFS=' ' read -r -a publishedCrates <<< "$GDRUST_CRATES"
127+
for crate in "${publishedCrates[@]}"; do
128+
(cd "$crate" && cargo publish) || {
129+
printf "\nError: Failed to publish $crate\n"
130+
exit 2
131+
}
132+
sleep 40s
133+
done

0 commit comments

Comments
 (0)