diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 79fbb5f..a468389 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -4,7 +4,7 @@ name: release # Usage: # - Create a new tag with the version number in the format v*.*.* where * are integers: `git tag v1.2.3` -# - Push the tag to the repository: `git push --tags` +# - Push the tag to the repository: `git push origin tag v1.2.3` # Result: # - Check if the new version is greater than the latest version on PyPI @@ -16,33 +16,25 @@ name: release # Checklist for using this workflow up for a new project: # 1. In github settings: -# - Create an environment called `release` (GH_ENV_NAME) and setup the permissions (https://github.com///settings/environments) +# - Create an environment called `release` +# - Setup the permissions (https://github.com///settings/environments) +# - Add the following variables: +# - PACKAGE_NAME: the name of your package on pypi +# - PYTHON_VERSION: the version of Python you want to use # 2. On PyPi: # - Create the project and add a trusted publisher (https://pypi.org/manage/project//settings/publishing/ or https://pypi.org/manage/account/publishing if the project is not on pypi yet) # - Ensure the publisher is configured to use: -# - environment name: `release` (can be changed, but should be the one created in the github settings) # - the filename of this workflow yml (in this case: publish-to-pypi.yml) -# 3. In this file: -# - In the `env` section (~L45): -# - Update the name of your package (PACKAGE_NAME) -# - Update the version of Python you want to use (PYTHON_VERSION) -# - Update the name name of the environment you created in github settings (GH_ENV_NAME) - # - In the `setup_and_build` job: # - Update the the shell commands to install your package on: push: tags: + - v[0-9]+\.[0-9]+\.[0-9]+ # https://peps.python.org/pep-0440/ - - r"v[0-9]+\.[0-9]+\.[0-9]" - -env: - GH_ENV_NAME: "release" - PACKAGE_NAME: "cht_tiling" - PYTHON_VERSION: "3.10" jobs: details: @@ -58,7 +50,7 @@ jobs: run: | if [ "${{ github.ref_type }}" = "tag" ]; then TAG_NAME=${GITHUB_REF#refs/tags/} - NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}') + NEW_VERSION=$(echo $TAG_NAME | sed 's/^v//' | awk -F'-' '{print $1}') echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" echo "Version is $NEW_VERSION" @@ -75,7 +67,7 @@ jobs: - name: Fetch information from PyPI run: | response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}") - latest_previous_version=$(echo $response | jq --raw-output "select(.releases != null) | .releases | keys_unsorted | last") + latest_previous_version=$(echo $response | jq --raw-output "select(.releases != null) | .releases | keys_unsorted[]" | sort -V | tail -n 1) if [ -z "$latest_previous_version" ]; then echo "Package not found on PyPI." latest_previous_version="0.0.0" @@ -110,16 +102,17 @@ jobs: - name: Install Build tools shell: bash -el {0} run: | - conda run -n publish pip install --upgrade build pip setuptools + conda install -n publish pip setuptools wheel python-build - name: Install dependencies shell: bash -el {0} run: | + conda install -n publish gdal basemap cftime fiona netCDF4 pygeos pyproj rasterio rtree shapely --channel conda-forge conda run -n publish pip install . - name: Build source and wheel distribution run: | - conda run -n publish python -m build + conda run -n publish python -s -m build - name: Upload artifacts uses: actions/upload-artifact@v3 @@ -132,7 +125,8 @@ jobs: needs: [setup_and_build, details] runs-on: ubuntu-latest environment: - name: ${{ env.GH_ENV_NAME }} + name: release + permissions: id-token: write steps: