Skip to content

Commit 55fcfa1

Browse files
authored
Merge pull request #977 from ehuss/ci-publish
Publish via GitHub Actions
2 parents 40c8cf3 + 92008c4 commit 55fcfa1

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

.github/workflows/publish.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
git2:
6+
description: "Publish git2"
7+
type: boolean
8+
default: true
9+
git2_curl:
10+
description: "Publish git2-curl"
11+
type: boolean
12+
default: true
13+
libgit2_sys:
14+
description: "Publish libgit2-sys"
15+
type: boolean
16+
default: true
17+
18+
permissions:
19+
contents: write
20+
21+
jobs:
22+
publish:
23+
name: Publish to crates.io
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@master
27+
- name: Publish
28+
env:
29+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
30+
PUBLISH_GIT2: ${{ inputs.git2 }}
31+
PUBLISH_GIT2_CURL: ${{ inputs.git2_curl }}
32+
PUBLISH_LIBGIT2_SYS: ${{ inputs.libgit2_sys }}
33+
run: ./ci/publish.sh

CONTRIBUTING.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ Checklist for preparing for a release:
5252
- [`libgit2-sys/CHANGELOG.md`](https://github.com/rust-lang/git2-rs/blob/master/libgit2-sys/CHANGELOG.md)
5353
- [`git2-curl/CHANGELOG.md`](https://github.com/rust-lang/git2-rs/blob/master/git2-curl/CHANGELOG.md)
5454

55-
To publish the new release:
56-
57-
- In a fresh clone, make sure you run `git submodule update`.
58-
- For each updated package, run `cargo publish` (`libgit2-sys` then `git2` then `git2-curl`).
59-
- Set tags for each package that was update:
60-
- `git tag 0.16.1`
61-
- `git tag libgit2-sys-0.14.2+1.5.1`
62-
- `git tag git2-curl-0.17.0`
63-
- Push the tags (substitute the "origin" remote name if you are using a different name):
64-
- `git push origin 0.16.1`
65-
- `git push origin libgit2-sys-0.14.2+1.5.1`
66-
- `git push origin git2-curl-0.17.0`
55+
There is a GitHub workflow to handle publishing to crates.io and tagging the release. There are two different ways to run it:
56+
57+
- In the GitHub web UI:
58+
1. Go to <https://github.com/rust-lang/git2-rs/actions/workflows/publish.yml> (you can navigate here via the "Actions" tab at the top).
59+
2. Click the "Run workflow" drop-down on the right.
60+
3. Choose which crates to publish. It's OK to leave everything checked, it will skip if it is already published. Uncheck a crate if the version has been bumped in git, but you don't want to publish that particular one, yet.
61+
4. Click "Run workflow"
62+
- In the CLI:
63+
1. Run `gh workflow run publish.yml -R rust-lang/git2-rs`

ci/publish.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function publish {
6+
publish_this="$1"
7+
crate_name="$2"
8+
manifest="$3"
9+
10+
if [ "$publish_this" != "true" ]
11+
then
12+
echo "Skipping $crate_name, publish not requested."
13+
return
14+
fi
15+
16+
# Get the version from Cargo.toml
17+
version=`sed -n -E 's/^version = "(.*)"/\1/p' $manifest`
18+
19+
# Check crates.io if it is already published
20+
set +e
21+
output=`curl --fail --silent --head https://crates.io/api/v1/crates/$crate_name/$version/download`
22+
res="$?"
23+
set -e
24+
case $res in
25+
0)
26+
echo "${crate_name}@${version} appears to already be published"
27+
return
28+
;;
29+
22) ;;
30+
*)
31+
echo "Failed to check ${crate_name}@${version} res: $res"
32+
echo "$output"
33+
exit 1
34+
;;
35+
esac
36+
37+
cargo publish --manifest-path $manifest --no-verify
38+
39+
tag="${crate_name}-${version}"
40+
git tag $tag
41+
git push origin "$tag"
42+
}
43+
44+
publish $PUBLISH_LIBGIT2_SYS libgit2-sys libgit2-sys/Cargo.toml
45+
publish $PUBLISH_GIT2 git2 Cargo.toml
46+
publish $PUBLISH_GIT2_CURL git2-curl git2-curl/Cargo.toml

0 commit comments

Comments
 (0)