-
Notifications
You must be signed in to change notification settings - Fork 5
215 lines (199 loc) · 7.76 KB
/
Copy pathsemver-checks.yml
File metadata and controls
215 lines (199 loc) · 7.76 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Semver checks
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
RUSTDOCFLAGS: '--deny warnings'
MINIMUM_SUPPORTED_RUST_VERSION: 1.85.0
RUST_CHANNEL: stable
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
branches:
- main
paths-ignore:
- CHANGELOG.md
workflow_dispatch:
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-branches:
runs-on: ubuntu-latest
steps:
- name: you can't run this action on 'main' branch
run: |
if [[ "$GITHUB_REF_NAME" = "main" ]]; then
exit 1
fi
env:
GITHUB_REF_NAME: ${{ github.ref_name }}
setup:
needs: check-branches
outputs:
currentVersion: ${{ steps.current.outputs.version }}
nextVersion: ${{ steps.next.outputs.version }}
nextStep: ${{ steps.nextStep.outputs.nextStep }}
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- name: Delete old cargo-semver-checks comments
continue-on-error: true
run: |
gh pr view "${{ github.event.number }}" --json comments --jq '.comments[] | select(.author.login == "github-actions") | .url' | grep -oE 'issuecomment-(.+)' | cut -d '-' -f2 > comments.txt
xargs -I % gh api -X DELETE "/repos/${GH_REPOSITORY}/issues/comments/%" < comments.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPOSITORY: ${{ github.repository }}
- name: Install Rust
run: |
rustup update --no-self-update ${RUST_CHANNEL}
rustup component add --toolchain ${RUST_CHANNEL} cargo
rustup default ${RUST_CHANNEL}
env:
RUST_CHANNEL: ${{ env.RUST_CHANNEL }}
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # ratchet:Swatinem/rust-cache@v2
- name: List the releases on GitHub
id: current
run: echo "version=$(git tag --sort=-creatordate | head -n 1)" >> "$GITHUB_OUTPUT"
- name: Get next version
id: next
run: echo "version=v$(cargo pkgid | cut -d '#' -f2)" >> "$GITHUB_OUTPUT"
- name: Compute next step
id: nextStep
if: ${{ steps.current.outputs.version == steps.next.outputs.version }}
run: |
if [[ "${VERSION}" == "${NEXT_VERSION}" ]]; then
echo "nextStep=compute" >> "$GITHUB_OUTPUT"
else
echo "nextStep=nope" >> "$GITHUB_OUTPUT"
fi
env:
VERSION: ${{ steps.current.outputs.version }}
NEXT_VERSION: ${{ steps.next.outputs.version }}
cargo-semver-checks:
needs: setup
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
if: ${{ needs.setup.outputs.nextStep != 'compute' }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
persist-credentials: false
- name: Install Rust
run: |
rustup update --no-self-update ${RUST_CHANNEL}
rustup component add --toolchain ${RUST_CHANNEL} cargo
rustup default ${RUST_CHANNEL}
env:
RUST_CHANNEL: ${{ env.RUST_CHANNEL }}
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # ratchet:Swatinem/rust-cache@v2
- name: Install cargo-semver-checks
run: cargo install cargo-semver-checks
- name: Show release type
id: semver
run: |
echo "release=$(bash ./.github/workflows/semver.sh diff ${VERSION} ${NEXT_VERSION})" >> "$GITHUB_OUTPUT"
env:
VERSION: ${{ needs.setup.outputs.currentVersion }}
NEXT_VERSION: ${{ needs.setup.outputs.nextVersion }}
- name: Prepare report.md
run: |
{
printf "> [!WARNING]"
printf "> According to \`cargo-semver-checks\`, the next release version doesn\'t respect semantic versioning."
printf '```bash'
} > ./report.md
- name: Run cargo semver-checks
id: check
run: |
printf "\`cargo-semver-checks\` has detected some issues: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n" > report.md
printf '```bash' >> report.md
cargo semver-checks --color never --baseline-rev "$NAME" --release-type "$RELEASE_TYPE" 2>&1 | tee -a report.md
if [[ "${PIPESTATUS[0]}" != "0" ]]; then
printf '```' >> report.md
exit 1
fi
continue-on-error: true
env:
VERSION: ${{ needs.setup.outputs.currentVersion }}
RELEASE_TYPE: ${{ steps.semver.outputs.release }}
- name: Publish semver-checks report
if: ${{ steps.check.outcome != 'success' }}
run: |
gh pr comment ${{ github.event.number }} --body-file ./report.md
exit 1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish semver-checks report
if: ${{ steps.check.outcome != 'success' }}
run: |
gh pr comment ${{ github.event.number }} --body-file ./report.md
exit 1
compute-next-version:
needs: setup
permissions:
pull-requests: write
contents: write
if: ${{ needs.setup.outputs.nextStep == 'compute' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- name: Install Rust
run: |
rustup update --no-self-update ${RUST_CHANNEL}
rustup component add --toolchain ${RUST_CHANNEL} cargo
rustup default ${RUST_CHANNEL}
env:
RUST_CHANNEL: ${{ env.RUST_CHANNEL }}
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # ratchet:Swatinem/rust-cache@v2
- name: Install cargo-semver-checks
run: cargo install cargo-semver-checks
- name: Determine the next version
id: bump
continue-on-error: true
run: |
b="major"
for t in patch minor; do
echo "Checking whether the next version is $t"
if cargo semver-checks --color never --baseline-rev "${CURRENT_VERSION}" --release-type "$t"; then
b="$t"
break
fi
done
echo $b
echo "bump=$b" >> "$GITHUB_OUTPUT"
env:
CURRENT_VERSION: ${{ needs.setup.outputs.currentVersion }}
- name: Comment the pull request
run: |
echo "::info title=Next version:: Last public version is '${VERSION}' but version of this branch is '${NEXT_VERSION}'."
{
printf "This pull request is not ready because version \`%s\` is already published." "${VERSION}"
printf "\nAccording to \`cargo-semver-checks\`, the next version should be \`v%s\`:" "$(bash .github/workflows/semver.sh bump $BUMP ${VERSION} | tr -d "\n")"
printf "\n"
echo '```shell'
printf "git checkout %s\n" "$branch"
echo "cargo release $BUMP --no-push --no-tag --no-publish --no-confirm --execute"
echo "git push"
echo '```'
} >> report.md
gh pr comment ${{ github.event.number }} --body-file ./report.md
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.setup.outputs.currentVersion }}
NEXT_VERSION: ${{ needs.setup.outputs.nextVersion }}
branch: '${{ toJSON(github.head_ref) }}'
BUMP: ${{ steps.bump.outputs.bump }}