-
-
Notifications
You must be signed in to change notification settings - Fork 142
134 lines (112 loc) · 5.15 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
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
123
124
125
126
127
128
129
130
131
132
133
134
name: Release and publish
on:
workflow_dispatch:
pull_request_target:
types:
- closed
permissions:
contents: write
pull-requests: write
jobs:
prepare:
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
version: ${{ steps.version-label.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Actions Auto Build"
- name: Get current version
id: version-label
run: |
VERSION=$(grep version Cargo.toml | head -n 1 | cut -d'"' -f2)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Get previous version
id: previous-version-label
run: |
PREVIOUS_VERSION=$(gh api "/repos/${{ github.repository }}/tags?per_page=1" | jq -r '.[] | .name?')
echo "previous_version=${PREVIOUS_VERSION}" >> $GITHUB_OUTPUT
- name: Generate Release Notes
id: generate-release-notes
run: |
generate() {
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases/generate-notes \
-f tag_name='v${{ steps.version-label.outputs.version }}' \
-f previous_tag='v${{ steps.previous-version-label.outputs.previous_version }}' \
| jq -r ".body"
}
echo "changelog<<EOF"$'\n'"$(generate)"$'\n'EOF >> $GITHUB_OUTPUT
- name: Update changelog.txt
run: |
echo "# [v${{ steps.version-label.outputs.version }}] - `date +%d-%m-%Y`" >> changelog.txt.tmp
echo "${{steps.generate-release-notes.outputs.changelog}}" >> changelog.txt.tmp
echo '-n' >> changelog.txt
cat changelog.txt >> changelog.txt.tmp
mv changelog.txt.tmp changelog.txt
- name: Update README
run: |
cargo run --example update-readme
- name: Commit Changelog and README
run: git add -f changelog.txt README.md
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
commit-message: "[skip test] update changelog"
title: "[skip test] Release v${{ steps.version-label.outputs.version }}"
body: >
This is an automated PR to build the latest changelog. Upon merging,
a new release will be created and published to crates.io.<br/>
Due to security considerations, PRs created by GitHub Actions cannot
be merged automatically. Please review the changes and merge the PR.<br/>
If you require the test suites to run, you can close the PR and reopen it to trigger
those workflows.
delete-branch: true
labels: release
branch: "release/v${{ steps.version-label.outputs.version }}"
- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
release:
if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'release')) }}
runs-on: ubuntu-latest
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Actions Auto Build"
- name: Get current version
id: version-label
run: |
VERSION=$(grep version Cargo.toml | head -n 1 | cut -d'"' -f2)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Create tag
run: |
git tag -a v${{ steps.version-label.outputs.version }} -m "Release v${{ steps.version-label.outputs.version }}"
git push origin --tags
- name: Login to Crates.io
run: cargo login ${CRATES_IO_TOKEN}
- name: Publish GitHub release
run: |
gh release create v${{ steps.version-label.outputs.version }} --generate-notes
- name: Publish crate
run: cargo publish