-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (76 loc) · 2.84 KB
/
bump-version.yml
File metadata and controls
87 lines (76 loc) · 2.84 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
# Source: https://github.com/joaomcteixeira/python-project-skeleton/blob/main/.github/workflows/version-bump-and-package.yml
# and https://github.community/t/trigger-workflow-only-on-pull-request-merge/17359/9
# taken and upgraded from:
# https://github.com/haddocking/pdb-tools/blob/f019d163d8f8cc5a0cba288e02f5a63a969719f6/.github/workflows/bump-version-on-push.yml
name: Bump version
# Bump version only when closed Pull Requests to main
on:
pull_request:
branches:
- main
types: [closed]
jobs:
bump-version:
runs-on: ubuntu-latest
if: "github.event.pull_request.merged == true &&
!startsWith(github.head_ref, 'SKIP')"
steps:
- uses: actions/checkout@v2
with:
# I setup a new token for my GitHub user and added that token
# to the secrets in the repository
# When I tried
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow
# I had some problems, they could be my fault, but yet, I felt using a
# dedicated token would be better and enough
token: ${{ secrets.CICD_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Setup Git
env:
GH_USER: ${{ github.actor }}
GH_TOKEN: ${{ secrets.CICD_TOKEN }}
PR_TARGET_BRANCH: ${{ github.base_ref }}
run: |
git config user.name "${GH_USER}"
git config user.email "${GH_USER}@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.CICD_TOKEN }}@github.com/$GITHUB_REPOSITORY
git checkout "${PR_TARGET_BRANCH}"
- name: Setup env variables
run: |
echo "SKIPBUMP=FALSE" >> $GITHUB_ENV
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install bump2version
# If a commit starts with [MAJOR] a new major verion upgrade will be
# triggered. Use with caution as Major upgrades denote backwards
# incompatibility. Yet I like it to be integrated in the CI
- name: Bump Major Version
env:
PR_SOURCE_BRANCH: ${{ github.head_ref }}
run: |
bump2version major
echo "SKIPBUMP=TRUE" >> $GITHUB_ENV
if: "startsWith(github.head_ref, 'MAJOR') ||
startsWith(github.head_ref, 'BREAK')"
- name: Bump Minor Version
env:
PR_SOURCE_BRANCH: ${{ github.head_ref }}
run: |
bump2version minor
echo "SKIPBUMP=TRUE" >> $GITHUB_ENV
if: "startsWith(github.head_ref, 'MINOR') ||
startsWith(github.head_ref, 'FEAT')"
# Default action
- name: Bump Patch Version
env:
PR_SOURCE_BRANCH: ${{ github.head_ref }}
run: |
bump2version patch
if: env.SKIPBUMP == 'FALSE'
- name: Commit version change to master
run: |
git push --follow-tags