-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (84 loc) · 2.96 KB
/
pr-version-bump.yml
File metadata and controls
92 lines (84 loc) · 2.96 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
name: PR Version Bump
on:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
permissions:
contents: write
pull-requests: write
jobs:
bump-version:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Determine bump label
id: label
uses: actions/github-script@v7
with:
script: |
const labels = context.payload.pull_request.labels.map(l => l.name);
let bump = "patch";
if (labels.includes("release:major")) {
bump = "major";
} else if (labels.includes("release:minor")) {
bump = "minor";
} else if (labels.includes("release:patch")) {
bump = "patch";
} else {
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ["release:patch"]
});
} catch (error) {
if (error.status !== 422) {
throw error;
}
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: "release:patch",
color: "0e8a16",
description: "Patch version bump"
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ["release:patch"]
});
}
}
core.setOutput("bump", bump);
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- name: Fetch base branch
run: |
git fetch origin "${{ github.event.pull_request.base.ref }}"
- name: Bump setup.py version
id: bump
run: |
python .github/scripts/pr_bump_version.py \
--bump "${{ steps.label.outputs.bump }}" \
--base-ref "${{ github.event.pull_request.base.ref }}" \
--base-remote "origin"
- name: Commit and push version update
if: steps.bump.outputs.changed == 'true'
env:
NEW_VERSION: ${{ steps.bump.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add setup.py
git commit -m "chore: bump version to ${NEW_VERSION}"
git push origin "HEAD:${{ github.event.pull_request.head.ref }}"