-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (118 loc) · 4.46 KB
/
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Automated Version Management
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
push:
branches:
- main
jobs:
preview-bump:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
name: "Preview version bump"
steps:
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Preview version bump
id: preview
run: |
# Perform the actual version bump
cz bump --yes --increment PATCH
# Debug: Print the contents of version.py
echo "Contents of version.py after bump:"
cat version.py
# Extract the new version from version.py
NEW_VERSION=$(python -c "exec(open('version.py').read()); print(__version__)")
echo "Extracted new version: $NEW_VERSION"
# Set the new version as an environment variable
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
- name: Find existing comment
id: find_comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const comment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('When merged, this PR will bump the version to:'));
return { id: comment ? comment.id : null };
- name: Comment PR
if: steps.find_comment.outputs.id == null
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `When merged, this PR will bump the version to: ${process.env.new_version}`
})
- name: Update PR Comment
if: steps.find_comment.outputs.id != null
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: steps.find_comment.outputs.id,
body: `When merged, this PR will bump the version to: ${process.env.new_version}`
})
bump-version:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: "Bump version and create changelog"
steps:
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Bump version
id: bump
run: |
# Perform the actual version bump
cz bump --increment PATCH --yes
# Debug: Print the contents of version.py
echo "Contents of version.py after bump:"
cat version.py
# Extract the new version from version.py
NEW_VERSION=$(python -c "exec(open('version.py').read()); print(__version__)")
echo "Extracted new version: $NEW_VERSION"
# Set the new version as an environment variable
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
- name: Print Version
run: echo "Bumped to version ${{ env.new_version }}"