-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from McGill-NLP/publish-pypi
Publish to PyPi via actions, update readme
- Loading branch information
Showing
5 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
This CLI script is used to update the version of the package. It is used by the | ||
CI/CD pipeline to update the version of the package when a new release is made. | ||
It uses argparse to parse the command line arguments, which are the new version | ||
and the path to the package's __init__.py file. | ||
""" | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Update the version of the package." | ||
) | ||
parser.add_argument( | ||
"--version", | ||
type=str, | ||
help="The new version of the package.", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--path", | ||
type=Path, | ||
help="The path to the package's version file.", | ||
default="instruct_qa/version.py", | ||
) | ||
args = parser.parse_args() | ||
|
||
with open(args.path, "w") as f: | ||
f.write(f"__version__ = \"{args.version}\"") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This workflow will upload a Python Package using Twine when a release is created | ||
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
|
||
name: Publish Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
publish-on-pypi: | ||
# Specifying a GitHub environment is optional, but strongly encouraged | ||
environment: release | ||
permissions: | ||
# IMPORTANT: this permission is mandatory for trusted publishing | ||
id-token: write | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Update version.py with release tag | ||
env: | ||
RELEASE_TAG: ${{ github.event.release.tag_name }} | ||
run: | | ||
python .github/scripts/update_version.py --version $RELEASE_TAG | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools twine wheel | ||
- name: Build package by running setup.py | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
- name: Publish package distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
__version__ = "0.0.1" | ||
|
||
# NOTE: Do not modify this manually. Version is automatically updated in | ||
# .github/scripts/update_version.py when .github/workflows/publish-python.yml | ||
# is run. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters