Skip to content

Commit

Permalink
automatically create tag based on __version__ (#3)
Browse files Browse the repository at this point in the history
Use GitHub action to automatically create tag based on `__version__`
  • Loading branch information
zhenghaven authored Oct 26, 2023
1 parent 4ce38d7 commit 8055690
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 40 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/on-new-tag.yaml
Original file line number Diff line number Diff line change
@@ -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} ]]
67 changes: 67 additions & 0 deletions .github/workflows/test-and-release.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
})
39 changes: 0 additions & 39 deletions .github/workflows/unittesting.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion GradescopeGrader/_Meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



__version__ = '0.1.0'
__version__ = '0.1.2'

PKG_AUTHOR = 'Haofan Zheng'
PKG_NAME = 'GradescopeGrader'
Expand Down
10 changes: 10 additions & 0 deletions GradescopeGrader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

0 comments on commit 8055690

Please sign in to comment.