From 549d22f6a60380ca892cb6671a68ce8ca4ba122c Mon Sep 17 00:00:00 2001 From: Haofan Zheng Date: Wed, 28 Feb 2024 01:29:00 -0800 Subject: [PATCH] Added github action scripts to create tag automatically --- .github/workflows/test-and-release.yaml | 58 +++++++++++++++++++++++++ PyEthHelper/__main__.py | 5 +++ setup.py | 4 +- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test-and-release.yaml diff --git a/.github/workflows/test-and-release.yaml b/.github/workflows/test-and-release.yaml new file mode 100644 index 0000000..9e5e243 --- /dev/null +++ b/.github/workflows/test-and-release.yaml @@ -0,0 +1,58 @@ +name: test_and_release + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + create_tag: + permissions: + contents: write + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python-version: [ 3.11 ] + + name: A job to test the functionalities of the code + 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: Installing this repo as a Python package + run: | + python3 -m pip install ${{ github.workspace }} + + - name: Installing GitHubApiHelper + run: | + python3 -m pip install git+https://github.com/zhenghaven/GitHubApiHelper.git@v0.1.2 + + - 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 PyEthHelper --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/PyEthHelper/__main__.py b/PyEthHelper/__main__.py index 2e4493c..4dc00a1 100644 --- a/PyEthHelper/__main__.py +++ b/PyEthHelper/__main__.py @@ -13,6 +13,7 @@ from web3 import Web3 +from . import _Meta from .EthContractHelper import ( LoadContract, DeployContract, @@ -27,6 +28,10 @@ def main(): description='Deploy contracts to Ethereum blockchain', prog='', ) + argParser.add_argument( + '--version', + action='version', version=f'{_Meta.__version__}', + ) argParser.add_argument( '--config', '-c', type=str, default='project_conf.json', required=False, help='Path to the project configuration file' diff --git a/setup.py b/setup.py index 4c1c707..55b6d57 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( name = PyEthHelper._Meta.PKG_NAME, version = PyEthHelper._Meta.__version__, - packages = find_packages(where='.', exclude=['main.py']), + packages = find_packages(where='.', exclude=['setup.py']), url = 'https://github.com/lsd-ucsc/PyEthHelper', license = PyEthHelper._Meta.PKG_LICENSE, author = PyEthHelper._Meta.PKG_AUTHOR, @@ -28,6 +28,6 @@ ] }, install_requires=[ - 'web3>=6.2.0', + 'web3==6.2.0', ], )