-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Added a workflow and necessary support scripts/templates to enabl…
…e automated released via GitHub's workflow_dispatch trigger. (#29)
- Loading branch information
Showing
8 changed files
with
247 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
--- | ||
name: Create package release and publish binaries to pypi.org | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_level: | ||
type: choice | ||
required: true | ||
description: | | ||
Select the release level, | ||
patch for backward compatible minor changes and bug fixes, | ||
minor for backward compatible larger changes, | ||
major for non-backward compatible changes. | ||
options: [patch, minor, major] | ||
concurrency: | ||
group: pypi | ||
jobs: | ||
pypi-version: | ||
name: Update package version | ||
if: github.repository == 'tektronix/tm_devices' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
environment: package-release-gate | ||
permissions: | ||
id-token: write | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: x | ||
check-latest: true | ||
- name: Check for unreleased entries in the Changelog | ||
run: python scripts/check_unreleased_changelog_items.py | ||
- name: Copy Changelog to template directory | ||
run: cp CHANGELOG.md python_semantic_release_templates/temp_CHANGELOG_copy.md | ||
- name: Python Semantic Release | ||
id: release | ||
uses: python-semantic-release/[email protected] | ||
with: | ||
root_options: --verbose --strict | ||
force: ${{ inputs.release_level }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
outputs: | ||
built-version: ${{ steps.release.outputs.version }} | ||
pypi-build: | ||
name: Build package | ||
needs: [pypi-version] | ||
if: github.repository == 'tektronix/tm_devices' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Build package | ||
uses: hynek/[email protected] | ||
upload-testpypi: | ||
name: Upload package to TestPyPI | ||
needs: [pypi-build] | ||
if: github.repository == 'tektronix/tm_devices' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
environment: package-testpypi | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download built packages | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: Packages | ||
path: dist | ||
- name: Upload package to Test PyPI | ||
uses: pypa/[email protected] | ||
with: | ||
repository-url: https://test.pypi.org/legacy/ | ||
upload-pypi: | ||
name: Upload package to PyPI | ||
needs: [upload-testpypi] | ||
if: github.repository == 'tektronix/tm_devices' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
environment: package-release | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download built packages | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: Packages | ||
path: dist | ||
- name: Upload package to PyPI | ||
uses: pypa/[email protected] | ||
upload-github: | ||
name: Upload package to GitHub Release | ||
needs: [upload-pypi] | ||
if: github.repository == 'tektronix/tm_devices' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download built packages | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: Packages | ||
path: dist | ||
- name: Publish package distributions to GitHub Releases | ||
uses: python-semantic-release/upload-to-gh-release@main | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
pypi-install: | ||
name: Install package | ||
needs: | ||
- pypi-version | ||
- pypi-build | ||
- upload-testpypi | ||
- upload-pypi | ||
- upload-github | ||
if: github.repository == 'tektronix/tm_devices' && github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
index_urls: | ||
- '' | ||
- ' --index-url=https://test.pypi.org/simple/ --extra-index-url=https://pypi.org/simple' | ||
steps: | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: x | ||
check-latest: true | ||
- name: Test installing package | ||
# A retry is used to allow for some downtime before the package is installable | ||
uses: nick-fields/retry@v2 | ||
with: | ||
timeout_minutes: 2 | ||
max_attempts: 5 | ||
retry_wait_seconds: 30 | ||
warning_on_retry: false | ||
command: pip install${{ matrix.index_urls }} tm_devices==${{ needs.pypi-version.outputs.built-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{%- set latest_release_dict_entry = (context.history.released.items()|list)[0] %} | ||
{%- set latest_version_number = latest_release_dict_entry[0].as_tag() %} | ||
{%- set latest_version_date = latest_release_dict_entry[1].tagged_date.strftime("%Y-%m-%d") %} | ||
{%- set recently_merged_prs = {} %} | ||
{%- for type_, commits in latest_release_dict_entry[1]["elements"] | dictsort %} | ||
{%- for commit in commits %} | ||
{%- set pr_num = commit.commit.message.rstrip().rsplit("(#", 1)[-1].rsplit(")", 1)[0]|int %} | ||
{%- if pr_num %} | ||
{%- do recently_merged_prs.update({commit.commit.message.split("\n")[0].rsplit("(#", 1)[0]: pr_num}) %} | ||
{%- endif %} | ||
{%- endfor %} | ||
{%- endfor %} | ||
|
||
{%- set merged_prs_text_list = ["\n\n### Merged Pull Requests\n\n"] %} | ||
{%- for message, number in recently_merged_prs.items() %} | ||
{%- do merged_prs_text_list.append("- " ~ message ~ "([#" + number|string ~ "](" ~ number|string|pull_request_url ~ "))\n") %} | ||
{%- endfor %} | ||
{%- set merged_prs_text = (merged_prs_text_list|join).rstrip() %} | ||
|
||
|
||
{%- filter replace("## Unreleased", "## Unreleased\n\n______________________________________________________________________\n\n## " + latest_version_number + " (" + latest_version_date + ")" + merged_prs_text) %} | ||
{%- include "temp_CHANGELOG_copy.md" %} | ||
{% endfilter %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""This script will check for unreleased entries in the CHANGELOG.md file. | ||
It will exit with a non-zero exit code if there are no unreleased entries. | ||
""" | ||
import pathlib | ||
import re | ||
|
||
CHANGELOG_FILENAME = "CHANGELOG.md" | ||
|
||
|
||
def main() -> None: | ||
"""Check for entries in the Unreleased section of the CHANGELOG.md file. | ||
Raises: | ||
SystemExit: Indicates no new entries were found. | ||
""" | ||
found_entries = False | ||
with open( | ||
pathlib.Path(__file__).parent.parent / CHANGELOG_FILENAME, encoding="utf-8" | ||
) as changelog_file: | ||
tracking_unreleased = False | ||
tracking_entries = False | ||
for line in changelog_file: | ||
if line.startswith("___"): | ||
tracking_unreleased = False | ||
tracking_entries = False | ||
if line.startswith("## Unreleased"): | ||
tracking_unreleased = True | ||
if tracking_unreleased and line.startswith( | ||
( | ||
"### Added\n", | ||
"### Changed\n", | ||
"### Deprecated\n", | ||
"### Removed\n", | ||
"### Fixed\n", | ||
"### Security\n", | ||
) | ||
): | ||
tracking_entries = True | ||
if tracking_entries: | ||
found_entries = bool(re.match(r"^- \w+", line)) | ||
if found_entries: | ||
break | ||
|
||
if not found_entries: | ||
msg = f"No unreleased entries were found in {CHANGELOG_FILENAME}." | ||
raise SystemExit(msg) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |