-
Notifications
You must be signed in to change notification settings - Fork 14
39 lines (35 loc) · 1.17 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
name: Publish to crates.io
on:
push:
branches:
- master
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
# If it's a tag, publish as is
cargo publish
elif [[ "${{ github.ref }}" == refs/heads/master ]]; then
# If it's a push to master, publish as a pre-release version
VERSION=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*?)"/\1/')
COMMIT_HASH=$(git rev-parse --short HEAD)
NEW_VERSION="${VERSION}-pre.${COMMIT_HASH}"
sed -i "s/^version = \".*\"/version = \"${NEW_VERSION}\"/" Cargo.toml
CARGO_REGISTRY_TOKEN=${{ secrets.CRATES_IO_TOKEN }} cargo publish --allow-dirty
else
echo "Not publishing: not a push to master or a tag"
fi