Skip to content

Commit e0f7d2e

Browse files
Merge pull request #29 from brainelectronics/feature/create-release-branch
Create release branch after merge
2 parents 93afb50 + f522636 commit e0f7d2e

File tree

8 files changed

+101
-6
lines changed

8 files changed

+101
-6
lines changed

.github/workflows/release.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,72 @@ jobs:
3535
changelog changelog.md \
3636
--snippets=.snippets \
3737
--in-place
38-
- name: Build package
38+
- name: Extract latest version from changelog
39+
run: |
40+
changelog2version \
41+
--changelog_file changelog.md \
42+
--print \
43+
--debug \
44+
--pretty \
45+
--output changelog.json
46+
- name: Update package.json file
47+
run: |
48+
upy-package \
49+
--setup_file setup.py \
50+
--package_changelog_file changelog.md \
51+
--package_file package.json \
52+
--pretty \
53+
--create
54+
- name: Update version.py file
3955
run: |
4056
changelog2version \
4157
--changelog_file changelog.md \
4258
--version_file be_upy_blink/version.py \
4359
--version_file_type py \
4460
--debug
61+
- name: Build package
62+
run: |
4563
python setup.py sdist
4664
rm dist/*.orig
4765
# sdist call create non conform twine files *.orig, remove them
66+
- name: Test built package
67+
run: |
68+
twine check dist/*.tar.gz
69+
- name: Create release branch
70+
run: |
71+
git config user.name "github-actions"
72+
git config user.email "github-actions@github.com"
73+
LATEST_CHANGELOG_VERSION=$(jq -r '.info.version' changelog.json)
74+
echo "LATEST_CHANGELOG_VERSION: ${LATEST_CHANGELOG_VERSION}"
75+
echo "changelog.json file:"
76+
cat changelog.json
77+
DESIRED_BRANCH="release/${LATEST_CHANGELOG_VERSION}"
78+
echo "DESIRED_BRANCH: ${DESIRED_BRANCH}"
79+
git ls-remote \
80+
--exit-code \
81+
--heads \
82+
origin ${DESIRED_BRANCH} >/dev/null 2>&1
83+
EXIT_CODE=$?
84+
echo "EXIT_CODE: ${EXIT_CODE}"
85+
if [[ ${EXIT_CODE} == '0' ]]; then
86+
echo "Git branch '${DESIRED_BRANCH}' exists on remote"
87+
git checkout release/${LATEST_CHANGELOG_VERSION}
88+
elif [[ ${EXIT_CODE} == '2' ]]; then
89+
echo "Git branch '${DESIRED_BRANCH}' does not exist on remote"
90+
git checkout -b release/${LATEST_CHANGELOG_VERSION}
91+
fi
92+
git diff > diff.log
93+
echo "Diff in repo"
94+
cat diff.log
95+
if [[ $(git status --porcelain --untracked-files=no | wc -l) -gt 0 ]]; then
96+
echo "changed files available"
97+
git add package.json changelog.md be_upy_blink/version.py
98+
git status
99+
git commit -m "chore: files for release ${LATEST_CHANGELOG_VERSION}"
100+
git push -u origin release/${LATEST_CHANGELOG_VERSION}
101+
else
102+
echo "nothing new to commit and push"
103+
fi
48104
- name: Publish package
49105
uses: pypa/gh-action-pypi-publish@release/v1.13
50106
with:

.github/workflows/test-release.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,37 @@ jobs:
3232
changelog changelog.md \
3333
--snippets=.snippets \
3434
--in-place
35-
- name: Build package
35+
- name: Extract latest version from changelog
36+
run: |
37+
changelog2version \
38+
--changelog_file changelog.md \
39+
--print \
40+
--debug \
41+
--pretty \
42+
--output changelog.json
43+
- name: Update package.json file
44+
run: |
45+
upy-package \
46+
--setup_file setup.py \
47+
--package_changelog_file changelog.md \
48+
--package_file package.json \
49+
--pretty \
50+
--create
51+
- name: Update version.py file
3652
run: |
3753
changelog2version \
3854
--changelog_file changelog.md \
3955
--version_file be_upy_blink/version.py \
4056
--version_file_type py \
4157
--additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \
4258
--debug
59+
- name: Build package
60+
run: |
4361
python setup.py sdist
44-
- name: Test built package
62+
rm dist/*.orig
4563
# sdist call creates non twine conform "*.orig" files, remove them
64+
- name: Test built package
4665
run: |
47-
rm dist/*.orig
4866
twine check dist/*.tar.gz
4967
- name: Archive build package artifact
5068
uses: actions/upload-artifact@v7

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# snippets2changelog specific
22
changelog.md
33
changelog.md.new
4+
changelog.json
5+
latest-entry.json
6+
latest_description.txt
47

58
# custom, package specific ignores
69
.DS_Store

.snippets/28.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Create release branch after merge
2+
<!--
3+
type: feature
4+
scope: all
5+
affected: all
6+
-->
7+
8+
This change creates a new release branch `release/<VERSION>` after a merge and adds the following files to it:
9+
- `changelog.md`
10+
- `package.json`
11+
- `<PACKAGE>/version.py`
12+
13+
This closes [#28](https://github.com/brainelectronics/micropython-package-template/issues/28)

be_upy_blink/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
22
# -*- coding: UTF-8 -*-
33

4-
__version_info__ = ("0", "12", "0")
4+
__version_info__ = ("0", "13", "0")
55
__version__ = '.'.join(__version_info__)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
]
1515
],
1616
"deps": [],
17-
"version": "0.12.0"
17+
"version": "0.13.0"
1818
}

requirements-deploy-lock.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cffi==2.0.0
44
changelog2version==0.12.1
55
charset-normalizer==3.4.7
66
cryptography==46.0.6
7+
deepdiff==6.7.1
78
docutils==0.22.4
89
gitdb==4.0.12
910
GitPython==3.1.46
@@ -19,8 +20,10 @@ keyring==25.7.0
1920
markdown-it-py==4.0.0
2021
MarkupSafe==3.0.3
2122
mdurl==0.1.2
23+
mock==4.0.3
2224
more-itertools==11.0.1
2325
nh3==0.3.4
26+
ordered-set==4.1.0
2427
packaging==26.0
2528
pycparser==3.0
2629
Pygments==2.20.0
@@ -32,6 +35,7 @@ rfc3986==2.0.0
3235
rich==14.3.3
3336
SecretStorage==3.5.0
3437
semver==2.13.0
38+
setup2upypackage==0.5.0
3539
smmap==5.0.3
3640
snippets2changelog==1.7.0
3741
twine==6.2.0

requirements-deploy.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
twine>=6.2.0,<7
55
changelog2version>=0.12.1,<1
66
snippets2changelog>=1.6.0,<2
7+
setup2upypackage>=0.5.0,<1

0 commit comments

Comments
 (0)