Skip to content

Commit 69287f2

Browse files
authored
Merge pull request #3156 from ehuss/publish-crates-io-if-unpublished
Change crates.io publish to be re-runnable
2 parents 2ea30c0 + c0d479f commit 69287f2

3 files changed

Lines changed: 72 additions & 18 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,3 @@ jobs:
4848
run: rustup update stable --no-self-update && rustup default stable
4949
- name: Deploy the User Guide to GitHub Pages using the gh-pages branch
5050
run: ci/publish-guide.sh
51-
publish:
52-
name: Publish to crates.io
53-
runs-on: ubuntu-latest
54-
permissions:
55-
# Required for OIDC token exchange
56-
id-token: write
57-
environment: publish
58-
steps:
59-
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
60-
- name: Install Rust (rustup)
61-
run: rustup update stable --no-self-update && rustup default stable
62-
- name: Authenticate with crates.io
63-
id: auth
64-
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5
65-
- name: Publish
66-
env:
67-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
68-
run: cargo publish --workspace --no-verify
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish to crates.io
2+
on:
3+
release:
4+
types: [created]
5+
workflow_dispatch:
6+
7+
defaults:
8+
run:
9+
shell: bash
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
publish:
16+
name: Publish to crates.io
17+
runs-on: ubuntu-latest
18+
permissions:
19+
# Required for OIDC token exchange
20+
id-token: write
21+
environment: publish
22+
steps:
23+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
24+
- name: Install Rust (rustup)
25+
run: rustup update stable --no-self-update && rustup default stable
26+
- name: Authenticate with crates.io
27+
id: auth
28+
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5
29+
- name: Publish
30+
env:
31+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
32+
run: ci/publish-crates-io.sh

ci/publish-crates-io.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function publish {
6+
crate_name="$1"
7+
manifest="$2"
8+
9+
# Get the version from Cargo.toml
10+
version=`sed -n -E 's/^version = "(.*)"/\1/p' $manifest`
11+
12+
# Check crates.io if it is already published
13+
set +e
14+
output=`curl --fail --silent --head --location https://static.crates.io/crates/$crate_name/$version/download`
15+
res="$?"
16+
set -e
17+
case $res in
18+
0)
19+
echo "${crate_name}@${version} appears to already be published"
20+
return
21+
;;
22+
22) ;;
23+
*)
24+
echo "Failed to check ${crate_name}@${version} res: $res"
25+
echo "$output"
26+
exit 1
27+
;;
28+
esac
29+
30+
cargo publish --manifest-path $manifest --no-verify
31+
}
32+
33+
publish mdbook-core crates/mdbook-core/Cargo.toml
34+
publish mdbook-markdown crates/mdbook-markdown/Cargo.toml
35+
publish mdbook-renderer crates/mdbook-renderer/Cargo.toml
36+
publish mdbook-html crates/mdbook-html/Cargo.toml
37+
publish mdbook-preprocessor crates/mdbook-preprocessor/Cargo.toml
38+
publish mdbook-summary crates/mdbook-summary/Cargo.toml
39+
publish mdbook-driver crates/mdbook-driver/Cargo.toml
40+
publish mdbook Cargo.toml

0 commit comments

Comments
 (0)