-
Notifications
You must be signed in to change notification settings - Fork 319
45 lines (36 loc) · 1.69 KB
/
Copy pathpublish.yaml
File metadata and controls
45 lines (36 loc) · 1.69 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
name: Publish
on: workflow_dispatch
jobs:
cargo-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.version_tag }}
- name: Fetch tags
run: git fetch --prune --unshallow --tags
- name: Install linux build requirements
run: sudo apt-get update && sudo apt-get install --yes --no-install-recommends libasound2-dev pkg-config
- name: Publish and tag
run: |
echo "Current git commit is $(git rev-list -n 1 HEAD)."
VERSION="$(yq '.package.version' Cargo.toml)"
echo "Project version from Cargo.toml is $VERSION"
if ! (echo "$VERSION" | grep --quiet "^[0-9]\{1,2\}\.[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\?$"); then
echo "The version format does not look like a release version, not publishing the crate."
exit 1
fi
VERSION_TAG="v$VERSION"
if git tag | grep --quiet "^$VERSION_TAG$"; then
echo "Tag $VERSION_TAG already exists at $(git rev-list -n 1 $VERSION_TAG), not publishing the crate."
exit 1
fi
cargo publish --token "${{ secrets.CRATESIO_TOKEN }}"
echo "Tagging current version with $VERSION_TAG ..."
# The bot name and email is taken from here https://github.com/actions/checkout/pull/1707
# see also https://api.github.com/users/github-actions%5Bbot%5D
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag --annotate "$VERSION_TAG" --message "Release version $VERSION_TAG"
git push origin "$VERSION_TAG"