diff --git a/.whitesource b/.whitesource new file mode 100644 index 0000000..0d7ea09 --- /dev/null +++ b/.whitesource @@ -0,0 +1,13 @@ +{ + "scanSettings": { + "baseBranches": [] + }, + "checkRunSettings": { + "vulnerableCheckRunConclusionLevel": "failure", + "displayMode": "diff" + }, + "issueSettings": { + "minSeverityLevel": "LOW", + "issueType": "DEPENDENCY" + } +} \ No newline at end of file diff --git a/EXAMPLE.yml b/EXAMPLE.yml new file mode 100644 index 0000000..ff51a67 --- /dev/null +++ b/EXAMPLE.yml @@ -0,0 +1,23 @@ +# This file must be in your GitHub repository workflows dir. +# e.g. .github/workflows/release.yml + +name: Upload to PyPI + +# This action will be triggered when you create a new GitHub tag +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: pypi-github-sync + uses: PabloLec/pypi-github-sync@v1.0.1 + with: + github_repo: PabloLec/recoverpy # Change these values + twine_username: ${{ secrets.TWINE_USERNAME }} + twine_password: ${{ secrets.TWINE_PASSWORD }} + verify_metadata: true + skip_existing: true + verbose: true diff --git a/README.md b/README.md index 45341ee..bb32fad 100644 --- a/README.md +++ b/README.md @@ -1 +1,71 @@ -# pypi-github-sync \ No newline at end of file +# pypi-github-sync [![GitHub release (latest by date)](https://img.shields.io/github/v/release/pablolec/pypi-github-sync)](https://github.com/PabloLec/pypi-github-sync/releases/) [![GitHub](https://img.shields.io/github/license/pablolec/pypi-github-sync)](https://github.com/PabloLec/pypi-github-sync/blob/main/LICENCE) + +This action allows you to upload your Python package to PyPI automatically using latest GitHub version tag as release version. + +## How does it work? + +Running a Docker container, this action will clone your repo, fetch its latest release tag, modify `setup.py` and/or `pyproject.toml`, build and finally push to PyPI. + +Also, with current procedure your GitHub repo remains untouched. That means the version parameter in your setup file will not be modified and its value does not matter. +You can leave a dummy value, for example: +``` Python +setup( + version="0.0.0", + ... +) +``` + + +## Usage + +In your GitHub repo, create a workflow file or append to an existing one. (e.g. `.github/workflows/release.yml`) + +Mandatory parameters are: +``` yaml +- name: pypi-github-sync + uses: PabloLec/pypi-github-sync@v1.0.1 + with: + github_repo: YOUR_USERNAME/YOUR_REPO + twine_username: ${{ secrets.TWINE_USERNAME }} + twine_password: ${{ secrets.TWINE_PASSWORD }} +``` + +You will need to change `YOUR_USERNAME` and `YOUR_REPO` values and set your PyPI username and password in your repository secrets ([See the docs for reference](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)). + +:arrow_right_hook: See [EXAMPLE.yml](EXAMPLE.yml) for a real world example. + +## Inputs + +#### `github_repo` *mandatory* + +Your github repository with format `USERNAME/REPO` as in URLs. For example this repo is `PabloLec/pypi-github-sync`. + +#### `twine_username` *mandatory* + +Your PyPI username, add `TWINE_USERNAME` to your [repository secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository). + +#### `twine_password` *mandatory* + +Your PyPI password, add `TWINE_PASSWORD` to your [repository secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository). + +#### `upload_repo` *optional* + +The repository used for package uploading. Defaults to main PyPI repo, you can use others like PyPI test repo with `https://test.pypi.org/legacy/`. + +#### `verify_metadata` *optional* + +Verify build metadata before publication, defaults to false. + +#### `skip_existing` *optional* + +Do not raise an error if version already exists on repo, defaults to false. + +#### `verbose` *optional* + +Verbose output for twine upload, defaults to false. + +## Contributing + +Any contribution is welcome. +To report a bug or offer your help, simply open a new [issue](https://github.com/PabloLec/pypi-github-sync/issues). +You can also open an issue if you want a new feature to be implemented. diff --git a/action.yml b/action.yml index 951fff5..594a93e 100644 --- a/action.yml +++ b/action.yml @@ -21,15 +21,15 @@ inputs: verify_metadata: description: Verify build metadata before publication, defaults to false required: false - defaults: false + default: false skip_existing: description: Do not raise an error if version already exists on repo, defaults to false required: false - defaults: false + default: false verbose: description: Verbose output for twine upload, defaults to false required: false - defaults: false + default: false runs: using: "docker" diff --git a/entrypoint.sh b/entrypoint.sh index 112deea..1c51456 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -33,28 +33,43 @@ echo "Cleaned version name: ${CLEAN_VER}" VERSION_REGEX='version=\"[^"]\+\"' VERSION_REPLACE="version=\"${CLEAN_VER}\"" +VERSION_REGEX_WITH_SPACE='version\ =\ \"[^"]\+\"' +VERSION_REPLACE_WITH_SPACE="version\ =\ \"${CLEAN_VER}\"" -sed -i -e "s/${VERSION_REGEX}/${VERSION_REPLACE}/g" setup.py +if [[ -e setup.py ]]; then + sed -i -e "s/${VERSION_REGEX}/${VERSION_REPLACE}/g" setup.py + sed -i -e "s/${VERSION_REGEX_WITH_SPACE}/${VERSION_REPLACE_WITH_SPACE}/g" setup.py +fi + +if [[ -e pyproject.toml ]]; then + sed -i -e "s/${VERSION_REGEX}/${VERSION_REPLACE}/g" pyproject.toml + sed -i -e "s/${VERSION_REGEX_WITH_SPACE}/${VERSION_REPLACE_WITH_SPACE}/g" pyproject.toml +fi echo "---------------- BUILD PACKAGE ----------------" -python setup.py sdist bdist_wheel +if [[ -e pyproject.toml ]]; then + pip install -q build + python -m build +elif [[ -e setup.py ]]; then + python setup.py sdist bdist_wheel +fi + +if [[ ${VERIFY_METADATA} != "false" ]] ; then + twine check dist/* +fi echo "---------------- PUBLISH PACKAGE ----------------" EXTRA_ARGS= -if [[ -z "${UPLOAD_REPO}" ]]; then +if [[ -n "${UPLOAD_REPO}" ]]; then EXTRA_ARGS="--repository-url ${UPLOAD_REPO} ${EXTRA_ARGS}" echo "-------- Using repository: ${UPLOAD_REPO}" fi -if [[ ${VERIFY_METADATA} != "false" ]] ; then - twine check dist/* -fi - if [[ ${SKIP_EXISTING} != "false" ]] ; then - EXTRA_ARGS=--skip-existing + EXTRA_ARGS="--skip-existing ${EXTRA_ARGS}" fi if [[ ${VERBOSE} != "false" ]] ; then