Repository navigation
66 lines (64 loc) · 2.99 KB
/
Copy pathpublish-crates.yml
File metadata and controls
66 lines (64 loc) · 2.99 KB
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
# Publishes docspring-cli to crates.io for a release (release.yml runs it after the binaries are built). It uses
# crates.io's trusted publishing, so there's no crates.io token here: crates.io trusts this repository's release.yml in
# the `release` environment, whose required reviewer approves each publish. A version crates.io already has is skipped
# (the first release was published from a maintainer's machine, before trusted publishing could be set up).
name: Publish to crates.io
on:
workflow_call:
inputs:
plan:
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Find the version
id: version
env:
PLAN: ${{ inputs.plan }}
run: |
version=$(jq -r '.releases[] | select(.app_name == "docspring-cli") | .app_version' <<< "$PLAN")
if [ -z "$version" ]; then
echo "The release plan has no docspring-cli release" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
# crates.io's API refuses requests without a User-Agent
if curl -fsS -o /dev/null -A "docspring-cli release (support@docspring.com)" \
"https://crates.io/api/v1/crates/docspring-cli/$version"; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "crates.io already has docspring-cli $version"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Install shiplist
if: steps.version.outputs.published == 'false'
run: |
curl -fsSL -o "$RUNNER_TEMP/shiplist.tar.gz" https://github.com/DocSpring/shiplist/releases/download/v0.1.0/shiplist-v0.1.0-x86_64-unknown-linux-musl.tar.gz
echo "800f0f149aefe68df1302d50a268f5f13fc9af6ba530d48fb49da8df76bbf5ac $RUNNER_TEMP/shiplist.tar.gz" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/shiplist.tar.gz" -C "$RUNNER_TEMP" --strip-components=1
# cargo publish packages the crate again, from the same commit, so it holds the same files
- name: Check the crate holds only the files .shiplist.yml keeps
if: steps.version.outputs.published == 'false'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
cargo package --locked --no-verify
"$RUNNER_TEMP/shiplist" verify package --archive "target/package/docspring-cli-$VERSION.crate" --root "docspring-cli-$VERSION"
- name: Get a crates.io token
if: steps.version.outputs.published == 'false'
id: auth
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
- name: Publish
if: steps.version.outputs.published == 'false'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked