-
Notifications
You must be signed in to change notification settings - Fork 7
44 lines (38 loc) · 1.09 KB
/
publish.yml
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
name: Publish to Crates.io
on:
push:
branches: [ main ]
paths: [ "Cargo.toml" ]
workflow_dispatch: {}
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Pulish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Cache Cargo
uses: Swatinem/[email protected]
- name: Define Tag and Publish to crates.io
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
TAG=v$(cargo metadata --no-deps --quiet | jq -r '.packages[0] | .version')
git fetch --tags
if [ $(git tag -l $TAG) ]
then
echo "Git tag $TAG already exists; skipping publishing to crates.io."
else
git config user.name "Add Tag from CI"
git config user.email ""
git tag $TAG
git push --tags
cargo login $CRATES_IO_TOKEN
cargo publish
fi