@@ -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 :
0 commit comments