From f49919f25cd71892b6be5068440cc6d5f39d2b29 Mon Sep 17 00:00:00 2001 From: Kaya Celebi Date: Mon, 10 Apr 2023 23:49:18 -0400 Subject: [PATCH] Added action information and keys, minor touch ups --- .github/scripts/release.py | 53 +++++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 18 ++++++++++++ .github/workflows/release.yml | 12 ++++++++ README.md | 8 ++---- 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 .github/scripts/release.py create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/scripts/release.py b/.github/scripts/release.py new file mode 100644 index 0000000..f77bd96 --- /dev/null +++ b/.github/scripts/release.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +import json +import subprocess + + +def get_last_version() -> str: + """Return the version number of the last release.""" + json_string = ( + subprocess.run( + ["gh", "release", "view", "--json", "tagName"], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + .stdout.decode("utf8") + .strip() + ) + + return json.loads(json_string)["tagName"] + + +def bump_patch_number(version_number: str) -> str: + """Return a copy of `version_number` with the patch number incremented.""" + major, minor, patch = version_number.split(".") + if '-' in patch: + patch = patch.split('-')[0] + v = path.split('-')[1] + return f"{major}.{minor}.{int(patch) + 1}-{v}" + return f"{major}.{minor}.{int(patch) + 1}" + + +def create_new_patch_release(): + """Create a new patch release on GitHub.""" + try: + last_version_number = get_last_version() + except subprocess.CalledProcessError as err: + '''if err.stderr.decode("utf8").startswith("HTTP 404:"): + # The project doesn't have any releases yet. + new_version_number = "0.0.1" + else: + raise''' + new_version_number = "0.0.1" + else: + new_version_number = bump_patch_number(last_version_number) + + subprocess.run( + ["gh", "release", "create", "--generate-notes", new_version_number], + check=True, + ) + + +if __name__ == "__main__": + create_new_patch_release() \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f9d3501 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,18 @@ +name: Publish to PyPI.org +#on: workflow_dispatch +on: + release: + types: [published] +jobs: + pypi: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: python3 -m pip install --upgrade build && python3 -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bb8a831 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,12 @@ +name: Create a new patch release +on: workflow_dispatch +jobs: + github: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Create new patch release + run: .github/scripts/release.py + env: + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 8ccbdee..1156c0e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![kcelebi](https://circleci.com/gh/kcelebi/riscv-assembler.svg?style=svg)](https://circleci.com/gh/kcelebi/riscv-assembler) +[![kcelebi](https://circleci.com/gh/celebi-pkg/riscv-assembler.svg?style=svg)](https://circleci.com/gh/celebi-pkg/riscv-assembler) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![example](references/mdimg.png) @@ -16,8 +16,4 @@ The package can be installed using pip: If issues arise try: - $ python3 -m pip install riscv-assembler - -It's possible tha the ``bitstring`` dependency might not install correctly. If this occurs, you can simply pip install it separately: - - $ pip install bitstring + $ python3 -m pip install riscv-assembler \ No newline at end of file