From 8055690a638e34342fcc6e00f930aba4c02e63d7 Mon Sep 17 00:00:00 2001 From: Haofan Zheng Date: Thu, 26 Oct 2023 02:53:17 -0700 Subject: [PATCH] automatically create tag based on __version__ (#3) Use GitHub action to automatically create tag based on `__version__` --- .github/workflows/on-new-tag.yaml | 27 ++++++++++ .github/workflows/test-and-release.yaml | 67 +++++++++++++++++++++++++ .github/workflows/unittesting.yaml | 39 -------------- GradescopeGrader/_Meta.py | 2 +- GradescopeGrader/__main__.py | 10 ++++ 5 files changed, 105 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/on-new-tag.yaml create mode 100644 .github/workflows/test-and-release.yaml delete mode 100644 .github/workflows/unittesting.yaml diff --git a/.github/workflows/on-new-tag.yaml b/.github/workflows/on-new-tag.yaml new file mode 100644 index 0000000..2082ea2 --- /dev/null +++ b/.github/workflows/on-new-tag.yaml @@ -0,0 +1,27 @@ +name: on_new_tag + +on: + push: + tags: + - '*' + +jobs: + check_ver: + runs-on: ubuntu-22.04 + strategy: + matrix: + python-version: [ 3.11 ] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Installing Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Check tag matches version + run: | + [[ $(python3 -m GradescopeGrader version) == ${GITHUB_REF#refs/tags/v} ]] + diff --git a/.github/workflows/test-and-release.yaml b/.github/workflows/test-and-release.yaml new file mode 100644 index 0000000..bd998e1 --- /dev/null +++ b/.github/workflows/test-and-release.yaml @@ -0,0 +1,67 @@ +name: test_and_release + + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + + +jobs: + test_and_release: + name: Unit Testing and then Release + + strategy: + matrix: + os: [ ubuntu-22.04 ] + python-version: [ 3.11 ] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Installing Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Run Unit Testing + working-directory: ${{ github.workspace }} + run: | + python3 runtests.py + + - name: Test setup.py + working-directory: ${{ github.workspace }} + run: | + python3 -m pip install ${{ github.workspace }} + + - name: Installing GitHubApiHelper + run: | + python3 -m pip install git+https://github.com/zhenghaven/GitHubApiHelper.git@v0.1.1 + + - name: Get latest version + id: latest_ver + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python3 -m GitHubApiHelper --auth-token \ + api_tags_latest_ver \ + --repo ${{ github.repository }} \ + -l $(python3 -m GradescopeGrader version) \ + --github-out + + - name: Create tag + if: ${{ startsWith(github.ref, 'refs/heads/main') && steps.latest_ver.outputs.remote != steps.latest_ver.outputs.all }} + uses: actions/github-script@v6 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ steps.latest_ver.outputs.allV }}', + sha: context.sha + }) + diff --git a/.github/workflows/unittesting.yaml b/.github/workflows/unittesting.yaml deleted file mode 100644 index 646f844..0000000 --- a/.github/workflows/unittesting.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Run Unit Tests - - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - - -jobs: - unittest: - name: Unit Testing - - strategy: - matrix: - os: [ ubuntu-22.04 ] - python-version: [ 3.11 ] - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Installing Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Run Unit Testing - working-directory: ${{ github.workspace }} - run: | - python3 runtests.py - - - name: Test setup.py - working-directory: ${{ github.workspace }} - run: | - python3 -m pip install . diff --git a/GradescopeGrader/_Meta.py b/GradescopeGrader/_Meta.py index a0d56d7..0c8fa59 100644 --- a/GradescopeGrader/_Meta.py +++ b/GradescopeGrader/_Meta.py @@ -9,7 +9,7 @@ -__version__ = '0.1.0' +__version__ = '0.1.2' PKG_AUTHOR = 'Haofan Zheng' PKG_NAME = 'GradescopeGrader' diff --git a/GradescopeGrader/__main__.py b/GradescopeGrader/__main__.py index 5563989..1c4a80d 100644 --- a/GradescopeGrader/__main__.py +++ b/GradescopeGrader/__main__.py @@ -27,6 +27,10 @@ def main(): help='operation to perform', required=True, ) + opParser.add_parser( + 'version', + help='print version and exit', + ) args = argParser.parse_args() @@ -36,6 +40,12 @@ def main(): format='%(asctime)s %(name)s[%(levelname)s]: %(message)s', ) + if args.operation == 'version': + from ._Meta import __version__ + print(__version__) + else: + raise NotImplementedError('unknown operation {}'.format(args.operation)) + if __name__ == '__main__': main()