Skip to content

Commit 292d33e

Browse files
authored
Allow publishing via a github action (#58)
1 parent 7f4612d commit 292d33e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Release new version
2+
3+
on:
4+
workflow_dispatch:
5+
secrets:
6+
CARGO_REGISTRY_TOKEN:
7+
required: true
8+
9+
env:
10+
RUST_BACKTRACE: 1
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
create-release:
15+
name: Create release
16+
runs-on: ubuntu-latest
17+
if: github.ref == 'refs/heads/main'
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
persist-credentials: true
23+
24+
- name: Install rust
25+
uses: actions-rs/toolchain@v1
26+
with:
27+
toolchain: stable
28+
profile: minimal
29+
override: true
30+
31+
- uses: Swatinem/rust-cache@v2
32+
33+
# Determine which version we're about to publish, so we can tag it appropriately.
34+
# If the tag already exists, then we've already published this version.
35+
- name: Determine current version
36+
id: version-check
37+
run: |
38+
# Fail on first error, on undefined variables, and on errors in pipes.
39+
set -euo pipefail
40+
export VERSION="$(cargo metadata --format-version 1 | \
41+
jq --arg crate_name tracing-tree --exit-status -r \
42+
'.packages[] | select(.name == $crate_name) | .version')"
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
if [[ "$(git tag -l "$VERSION")" != '' ]]; then
45+
echo "Aborting: Version $VERSION is already published, we found its tag in the repo."
46+
exit 1
47+
fi
48+
49+
# TODO: Replace this with the cargo-semver-checks v2 GitHub Action when it's stabilized:
50+
# https://github.com/obi1kenobi/cargo-semver-checks-action/pull/21
51+
- name: Semver-check
52+
run: |
53+
# Fail on first error, on undefined variables, and on errors in pipes.
54+
set -euo pipefail
55+
cargo install --locked cargo-semver-checks
56+
cargo semver-checks check-release
57+
58+
- name: Publish
59+
run: cargo publish
60+
env:
61+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
62+
63+
- name: Tag the version
64+
run: |
65+
# Fail on first error, on undefined variables, and on errors in pipes.
66+
set -euo pipefail
67+
git tag "${{ steps.version-check.outputs.version }}"
68+
git push origin "${{ steps.version-check.outputs.version }}"
69+
70+
- uses: taiki-e/create-gh-release-action@v1
71+
name: Create GitHub release
72+
with:
73+
branch: main
74+
ref: refs/tags/${{ steps.version-check.outputs.version }}
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)