diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b475ff8..3cf8d60 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,16 +35,72 @@ jobs: changelog changelog.md \ --snippets=.snippets \ --in-place - - name: Build package + - name: Extract latest version from changelog + run: | + changelog2version \ + --changelog_file changelog.md \ + --print \ + --debug \ + --pretty \ + --output changelog.json + - name: Update package.json file + run: | + upy-package \ + --setup_file setup.py \ + --package_changelog_file changelog.md \ + --package_file package.json \ + --pretty \ + --create + - name: Update version.py file run: | changelog2version \ --changelog_file changelog.md \ --version_file be_upy_blink/version.py \ --version_file_type py \ --debug + - name: Build package + run: | python setup.py sdist rm dist/*.orig # sdist call create non conform twine files *.orig, remove them + - name: Test built package + run: | + twine check dist/*.tar.gz + - name: Create release branch + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + LATEST_CHANGELOG_VERSION=$(jq -r '.info.version' changelog.json) + echo "LATEST_CHANGELOG_VERSION: ${LATEST_CHANGELOG_VERSION}" + echo "changelog.json file:" + cat changelog.json + DESIRED_BRANCH="release/${LATEST_CHANGELOG_VERSION}" + echo "DESIRED_BRANCH: ${DESIRED_BRANCH}" + git ls-remote \ + --exit-code \ + --heads \ + origin ${DESIRED_BRANCH} >/dev/null 2>&1 + EXIT_CODE=$? + echo "EXIT_CODE: ${EXIT_CODE}" + if [[ ${EXIT_CODE} == '0' ]]; then + echo "Git branch '${DESIRED_BRANCH}' exists on remote" + git checkout release/${LATEST_CHANGELOG_VERSION} + elif [[ ${EXIT_CODE} == '2' ]]; then + echo "Git branch '${DESIRED_BRANCH}' does not exist on remote" + git checkout -b release/${LATEST_CHANGELOG_VERSION} + fi + git diff > diff.log + echo "Diff in repo" + cat diff.log + if [[ $(git status --porcelain --untracked-files=no | wc -l) -gt 0 ]]; then + echo "changed files available" + git add package.json changelog.md be_upy_blink/version.py + git status + git commit -m "chore: files for release ${LATEST_CHANGELOG_VERSION}" + git push -u origin release/${LATEST_CHANGELOG_VERSION} + else + echo "nothing new to commit and push" + fi - name: Publish package uses: pypa/gh-action-pypi-publish@release/v1.13 with: diff --git a/.github/workflows/test-release.yaml b/.github/workflows/test-release.yaml index db54717..f29b4ea 100644 --- a/.github/workflows/test-release.yaml +++ b/.github/workflows/test-release.yaml @@ -32,7 +32,23 @@ jobs: changelog changelog.md \ --snippets=.snippets \ --in-place - - name: Build package + - name: Extract latest version from changelog + run: | + changelog2version \ + --changelog_file changelog.md \ + --print \ + --debug \ + --pretty \ + --output changelog.json + - name: Update package.json file + run: | + upy-package \ + --setup_file setup.py \ + --package_changelog_file changelog.md \ + --package_file package.json \ + --pretty \ + --create + - name: Update version.py file run: | changelog2version \ --changelog_file changelog.md \ @@ -40,11 +56,13 @@ jobs: --version_file_type py \ --additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \ --debug + - name: Build package + run: | python setup.py sdist - - name: Test built package + rm dist/*.orig # sdist call creates non twine conform "*.orig" files, remove them + - name: Test built package run: | - rm dist/*.orig twine check dist/*.tar.gz - name: Archive build package artifact uses: actions/upload-artifact@v7 diff --git a/.gitignore b/.gitignore index c96cd52..e1c82dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # snippets2changelog specific changelog.md changelog.md.new +changelog.json +latest-entry.json +latest_description.txt # custom, package specific ignores .DS_Store diff --git a/.snippets/28.md b/.snippets/28.md new file mode 100644 index 0000000..efec549 --- /dev/null +++ b/.snippets/28.md @@ -0,0 +1,13 @@ +## Create release branch after merge + + +This change creates a new release branch `release/` after a merge and adds the following files to it: +- `changelog.md` +- `package.json` +- `/version.py` + +This closes [#28](https://github.com/brainelectronics/micropython-package-template/issues/28) diff --git a/be_upy_blink/version.py b/be_upy_blink/version.py index 72192d3..0d18963 100644 --- a/be_upy_blink/version.py +++ b/be_upy_blink/version.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 -*- -__version_info__ = ("0", "12", "0") +__version_info__ = ("0", "13", "0") __version__ = '.'.join(__version_info__) diff --git a/package.json b/package.json index b244916..95b4121 100644 --- a/package.json +++ b/package.json @@ -14,5 +14,5 @@ ] ], "deps": [], - "version": "0.12.0" + "version": "0.13.0" } \ No newline at end of file diff --git a/requirements-deploy-lock.txt b/requirements-deploy-lock.txt index a033d89..6641473 100644 --- a/requirements-deploy-lock.txt +++ b/requirements-deploy-lock.txt @@ -4,6 +4,7 @@ cffi==2.0.0 changelog2version==0.12.1 charset-normalizer==3.4.7 cryptography==46.0.6 +deepdiff==6.7.1 docutils==0.22.4 gitdb==4.0.12 GitPython==3.1.46 @@ -19,8 +20,10 @@ keyring==25.7.0 markdown-it-py==4.0.0 MarkupSafe==3.0.3 mdurl==0.1.2 +mock==4.0.3 more-itertools==11.0.1 nh3==0.3.4 +ordered-set==4.1.0 packaging==26.0 pycparser==3.0 Pygments==2.20.0 @@ -32,6 +35,7 @@ rfc3986==2.0.0 rich==14.3.3 SecretStorage==3.5.0 semver==2.13.0 +setup2upypackage==0.5.0 smmap==5.0.3 snippets2changelog==1.7.0 twine==6.2.0 diff --git a/requirements-deploy.txt b/requirements-deploy.txt index 49232bc..453a489 100644 --- a/requirements-deploy.txt +++ b/requirements-deploy.txt @@ -4,3 +4,4 @@ twine>=6.2.0,<7 changelog2version>=0.12.1,<1 snippets2changelog>=1.6.0,<2 +setup2upypackage>=0.5.0,<1