-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (101 loc) · 3.04 KB
/
release.yml
File metadata and controls
122 lines (101 loc) · 3.04 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Release
on:
push:
tags:
- "v*"
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: true
permissions: {
contents: read,
actions: write
}
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
jobs:
check-main-branch:
name: Verify tag from main branch
runs-on: ${{ vars.RUNS_ON }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Ensure main is fetched
run: git fetch origin main --depth=1
- name: Verify tag commit is on main
shell: bash
env:
REF: ${{ github.ref }}
run: |
set -euo pipefail
TAG_COMMIT=$(git rev-list -n 1 "$REF")
git rev-parse --verify origin/main >/dev/null
if ! git merge-base --is-ancestor "$TAG_COMMIT" origin/main; then
echo "Tag commit is not an ancestor of origin/main"
exit 1
fi
- name: Verify Cargo.toml version matches tag
shell: bash
env:
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
TAG_VERSION="${REF_NAME#v}"
FILE_VERSION=$(grep -E '^\s*version\s*=' Cargo.toml | head -n1 | cut -d '"' -f2)
if [ -z "$FILE_VERSION" ] || [ "$FILE_VERSION" != "$TAG_VERSION" ]; then
echo "Cargo.toml version must equal tag (without 'v')"
exit 1
fi
publish-crate:
needs: check-main-branch
runs-on: ${{ vars.RUNS_ON }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
publish-release:
needs: publish-crate
runs-on: ${{ vars.RUNS_ON }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Generate changelog
id: changelog
run: |
set -euo pipefail
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s" "$PREV_TAG"..HEAD)
else
CHANGELOG=$(git log --pretty=format:"- %s")
fi
{
echo "changelog<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create Release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
tag_name: ${{ github.ref_name }}
name: "${{ github.ref_name }}"
body: |
### Changes
${{ steps.changelog.outputs.changelog }}
### Links
• Crate: https://crates.io/crates/taskvisor
• Docs: https://docs.rs/taskvisor