-
Notifications
You must be signed in to change notification settings - Fork 1
119 lines (110 loc) · 3.88 KB
/
reusable-bump-version.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
on:
workflow_call:
inputs:
email:
required: false
default: [email protected]
type: string
user:
required: false
default: tools-bot
type: string
secrets:
USER_TOKEN:
required: true
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.USER_TOKEN }}
- name: Query associated PR
id: get_associated_pr
uses: octokit/[email protected]
with:
query: |
query pr($owner:String!, $name:String!, $sha:String!) {
repository(owner:$owner, name:$name) {
commit: object(expression:$sha) {
... on Commit {
associatedPullRequests(first:1, orderBy:{field: UPDATED_AT, direction: DESC}){
edges{
node{
title
number
body
}
}
}
}
}
}
}
owner: ${{ github.repository_owner }}
name: ${{ github.event.repository.name }}
sha: ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.USER_TOKEN }}
- name: Get PR Number
env:
PR_DATA: ${{ steps.get_associated_pr.outputs.data }}
run: |
PR_NUMBER_QUERY='.repository.commit.associatedPullRequests.edges[0].node.number'
PR_NUMBER=$(jq --raw-output "${PR_NUMBER_QUERY}" <<< ${PR_DATA})
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
- name: Query PR labels
id: get_pr_labels
uses: octokit/[email protected]
with:
query: |
query labels($owner:String!, $name:String!, $pr:Int!) {
repository(owner:$owner, name:$name) {
pullRequest(number:$pr) {
labels(first:100) {
nodes {
name
}
}
}
}
}
owner: ${{ github.repository_owner }}
name: ${{ github.event.repository.name }}
pr: ${{ env.PR_NUMBER }}
env:
GITHUB_TOKEN: ${{ secrets.USER_TOKEN }}
- name: Get Bump Part
env:
LABELS_DATA: ${{ steps.get_pr_labels.outputs.data }}
run: |
LABEL_QUERY='.repository.pullRequest.labels.nodes[].name'
SELECT='select(. == "major" or . == "minor" or . == "patch" or . == "bumpless")'
PR_LABELS=$(jq --raw-output "${LABEL_QUERY} | ${SELECT}" <<< ${LABELS_DATA})
echo "BUMP_PART=$(echo ${PR_LABELS} | sort | head -1)" >> $GITHUB_ENV
- name: Get Tag Message
if: env.BUMP_PART != 'bumpless'
env:
PR_DATA: ${{ steps.get_associated_pr.outputs.data }}
run: |
PR_TITLE_QUERY='.repository.commit.associatedPullRequests.edges[0].node.title'
TAG_MSG=$(jq --raw-output "${PR_TITLE_QUERY}" <<< ${PR_DATA})
echo "TAG_MSG=${TAG_MSG}" >> $GITHUB_ENV
- uses: actions/setup-python@v5
if: env.BUMP_PART != 'bumpless'
with:
python-version: 3.x
- name: install python dependencies
if: env.BUMP_PART != 'bumpless'
run: |
python -m pip install --upgrade pip
python -m pip install bump2version
- name: Tag version
if: env.BUMP_PART != 'bumpless'
run: |
git config user.email ${{ inputs.email }}
git config user.name ${{ inputs.user }}
bump2version --current-version $(git describe --abbrev=0) --tag --tag-message "${TAG_MSG}" "${BUMP_PART}"
git push --tags
echo "Tagged version $(git describe --abbrev=0) and pushed back to repo"