-
Notifications
You must be signed in to change notification settings - Fork 27
86 lines (72 loc) · 2.19 KB
/
release.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: release
on:
workflow_dispatch:
inputs:
version:
type: choice
required: true
description: 'Version number to bump'
options:
- patch
- minor
- major
permissions:
contents: write
issues: write
pull-requests: write
jobs:
publish-dry-run:
name: "Runs cargo publish --dry-run"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: publish crate
run: cargo publish --dry-run
release:
name: Create Release
needs: publish-dry-run
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install `cargo-edit`
run: cargo install cargo-edit
- id: cargo-set-version
name: Set Version
run: cargo set-version --bump ${{ inputs.version }}
- name: Set Crate Version as Environment Variable
run: |
CARGO_TOML_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' Cargo.toml)
echo "CRATE_VERSION=$CARGO_TOML_VERSION" >> $GITHUB_ENV
- name: Create Commit
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "chore: bump version to v$CRATE_VERSION"
git push origin main --follow-tags
- name: Login to Crates.io
run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish crate
run: cargo publish
- name: Create Release
id: create_release
uses: actions/github-script@v5
with:
script: |
await github.request(`POST /repos/${{ github.repository }}/releases`, {
tag_name: "v${{ env.CRATE_VERSION }}",
generate_release_notes: true
});