From 40712b6989d37b76fcb2e1cb2a9eb097b0d9e621 Mon Sep 17 00:00:00 2001 From: Li Chen Date: Tue, 18 Oct 2022 13:53:22 -0700 Subject: [PATCH] Deployment pipeline (#9) * Load ANTLR files based on dynamic runtime version * Add missing files * Added deploy-ast.yml * Incorporated a couple of jakelishman PR feedbacks * Added deploy action * Removed testpypi after testing --- .github/workflows/deploy-ast.yml | 62 ++++++++++++++++++++++++++++++++ README.md | 14 ++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/deploy-ast.yml diff --git a/.github/workflows/deploy-ast.yml b/.github/workflows/deploy-ast.yml new file mode 100644 index 0000000..f1ddd56 --- /dev/null +++ b/.github/workflows/deploy-ast.yml @@ -0,0 +1,62 @@ +name: Deploy Reference Python Package + +on: + push: + tags: + - 'v*' + +jobs: + build: + uses: ./.github/workflows/build-ast.yml + + deploy: + name: Deploy to PyPI + needs: build + runs-on: ubuntu-latest + + steps: + # There's deliberately no check-out step here, because we don't want the + # checkout anywhere near us complicating matters; we're just trying to + # ensure that the pre-built wheel works, and its version matches what we + # expect from the tag. + + - uses: actions/setup-python@v3 + with: + # The version checker uses 'importlib.metadata' which is Python 3.10+. + python-version: '3.10' + + - uses: actions/download-artifact@v3 + with: + name: openpulse-python-wheel + + - uses: actions/download-artifact@v3 + with: + name: openpulse-python-sdist + + - name: Verify package + run: | + set -e + python3 -mvenv .venv + source .venv/bin/activate + python3 -mpip install -U pip wheel + python3 -mpip install openpulse-*.whl + # Extract the version information from the end of the tag. + tag_version=${GITHUB_REF#refs/tags/v} + # We could get this from the wheel filename too, but it's easier to + # test with Python built-ins. + wheel_version=$(python3 -c 'from importlib.metadata import version; print(version("openpulse"))') + if [[ "$tag_version" != "$wheel_version" ]]; then + echo "Version mismatch: tag says '$tag_version', wheel says '$wheel_version'" >&2 + exit 1 + fi + # Last-ditch validity check that the wheel actually imports. + python3 -c 'import openpulse' + - name: Upload to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.OPENQASM_BOT_PYPI_TOKEN }} + run: | + set -e + source .venv/bin/activate + python3 -mpip install -U twine + twine upload openpulse-*.whl openpulse-*.tar.gz \ No newline at end of file diff --git a/README.md b/README.md index 6be2401..aa413b0 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,17 @@ Finally, you can change to the `source/openpulse` directory and run: ``` pytest . ``` + +## Deployment procedure + +The deployment is primarily managed by a GitHub Actions pipeline, triggered by a tag of the form `v`. +For example, for package version `0.4.0`, the tag should be `v0.4.0`. + +To deploy: + +1. create a PR that sets the version number of the package in `__init__.py` to what it should be. +2. once the PR has merged, tag the merge commit (for example, `git fetch origin; git tag -m "Python AST 0.4.0" v0.4.0 origin/main`). +3. push the tag to this repository (for example, `git push origin v0.4.0`). + +At this point, the deployment pipeline will take over and deploy the package to PyPI. +You should be able to see the progress [in the Actions tab of this repository](https://github.com/openqasm/openpulse/actions/workflows/deploy-ast.yml). \ No newline at end of file