diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml new file mode 100644 index 0000000..40bd65d --- /dev/null +++ b/.github/workflows/auto-tag.yml @@ -0,0 +1,59 @@ +# This is a basic workflow to help you get started with uploading to pypi automatically +# https://packaging.python.org/tutorials/packaging-projects/ +# +# Before running this workflow in your repository, you will need to set up Secrets in your repository settings: +# - Log in to your (test)PyPI account, go to your account -> your_project -> Publishing +# - Fill in the required fields +# - Create an API token for the repository and this workflow + +# - Go to your repository on GitHub, click on the "Settings" tab, and then "Secrets" +# - Add a new secret with the name PYPI_TOKEN and the value is your pypi token +# - Add a new secret with the name PYPI_TEST_TOKEN and the value is your test pypi token +# Then, define the name of your package and the python version you want to use in the env block below. + +# This workflow will then automatically build and upload your package to PyPI/TestPypi: +# - When a new commit is pushed to main, it will build and upload to TestPyPI to catch errors early +# - When a new release is created, it will build and upload to the real PyPI +--- + env: + PACKAGE_NAME: "fiat_toolbox" + PYTHON_VERSION: "3.10" + + name: Update version on main + on: + pull_request: + branches: + - main + workflow_dispatch: + + + jobs: + new-tag: # Install your build env and build your package + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Update version + env: + GH_TOKEN: ${{ github.token }} + run: | + export CURRENT_VERSION=$(grep "version" fiat_toolbox/__init__.py | cut -d= -f 2 | tr -d "\" ") + export CURRENT_MAJOR=$(echo $CURRENT_VERSION | cut -d'.' -f 1) + export CURRENT_MINOR=$(echo $CURRENT_VERSION | cut -d'.' -f 2) + export CURRENT_PATHCH=$(echo $CURRENT_VERSION | cut -d'.' -f 3) + export NEW_VERSION="$CURRENT_MAJOR.$CURRENT_MINOR.$((CURRENT_PATHCH + 1))" + + git config user.name "GitHub Actions Bot" + git config user.email "<>" + + git checkout main + sed -i "s/.*__version__.*/__version__ = \"$NEW_VERSION\"/" fiat_toolbox/__init__.py + git add fiat_toolbox + git commit -m "Bump version" + git push --set-upstream origin + git tag "v$NEW_VERSION" + git push origin tag "v$NEW_VERSION" + \ No newline at end of file diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index c54ea0a..773236f 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -21,29 +21,21 @@ env: name: Build and Upload to PyPI on: - push: - branches: - - main - tags: - - v* - pull_request: - branches: - - main - release: - types: - - published - workflow_dispatch: + workflow_run: + workflows: [Update version on main] + types: + - completed jobs: build-artifacts: # Install your build env and build your package runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: conda-incubator/setup-miniconda@v2 + - uses: conda-incubator/setup-miniconda@v3 name: Setup Miniconda with: auto-update-conda: true @@ -64,7 +56,7 @@ jobs: shell: bash -l {0} run: python -m build - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: releases path: dist @@ -76,9 +68,9 @@ jobs: run: shell: bash -l {0} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: releases path: dist @@ -87,7 +79,7 @@ jobs: ls -ltrh ls -ltrh dist - - uses: conda-incubator/setup-miniconda@v2 + - uses: conda-incubator/setup-miniconda@v3 name: Setup Miniconda with: auto-update-conda: true @@ -102,43 +94,19 @@ jobs: python -m pip install dist/*.whl python -c "import ${{ env.PACKAGE_NAME }}; print(f'{${{ env.PACKAGE_NAME }}}-{${{ env.PACKAGE_NAME }}.__version__}')" - - upload-to-test-pypi: - environment: release - permissions: - id-token: write - needs: test-built-dist - if: ${{ github.event_name == 'release' && !github.event.act }} - - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v3 - with: - name: releases - path: dist - - name: Publish package to TestPyPI - uses: pypa/gh-action-pypi-publish@v1.5.1 - with: - user: __token__ - password: ${{ secrets.TEST_PYPI_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - verbose: true - skip_existing: true - upload-to-pypi: environment: release permissions: id-token: write - needs: upload-to-test-pypi - if: ${{ github.event_name == 'release' && !github.event.act }} + needs: test-built-dist runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: releases path: dist - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@v1.5.1 + uses: pypa/gh-action-pypi-publish@v1.9.0 with: user: __token__ password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml new file mode 100644 index 0000000..d6c18a1 --- /dev/null +++ b/.github/workflows/publish-to-test-pypi.yml @@ -0,0 +1,120 @@ +# This is a basic workflow to help you get started with uploading to pypi automatically +# https://packaging.python.org/tutorials/packaging-projects/ +# +# Before running this workflow in your repository, you will need to set up Secrets in your repository settings: +# - Log in to your (test)PyPI account, go to your account -> your_project -> Publishing +# - Fill in the required fields +# - Create an API token for the repository and this workflow + +# - Go to your repository on GitHub, click on the "Settings" tab, and then "Secrets" +# - Add a new secret with the name PYPI_TOKEN and the value is your pypi token +# - Add a new secret with the name PYPI_TEST_TOKEN and the value is your test pypi token +# Then, define the name of your package and the python version you want to use in the env block below. + +# This workflow will then automatically build and upload your package to PyPI/TestPypi: +# - When a new commit is pushed to main, it will build and upload to TestPyPI to catch errors early +# - When a new release is created, it will build and upload to the real PyPI +--- +env: + PACKAGE_NAME: "fiat_toolbox" + PYTHON_VERSION: "3.10" + +name: Build and Upload to Test PyPI +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + + +jobs: + build-artifacts: # Install your build env and build your package + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: conda-incubator/setup-miniconda@v3 + name: Setup Miniconda + with: + auto-update-conda: true + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install GDAL + shell: bash -l {0} + run: conda install -c conda-forge gdal + + - name: Install dependencies and build tools + shell: bash -l {0} + run: | + python -m pip install --upgrade pip + python -m pip install . + python -m pip install build + + - name: Build package + shell: bash -l {0} + run: python -m build + + - uses: actions/upload-artifact@v4 + with: + name: releases + path: dist + + test-built-dist: # Install the built package and test it has been built correctly + needs: build-artifacts + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: releases + path: dist + - name: List contents of built dist + run: | + ls -ltrh + ls -ltrh dist + + - uses: conda-incubator/setup-miniconda@v3 + name: Setup Miniconda + with: + auto-update-conda: true + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install GDAL + shell: bash -l {0} + run: conda install -c conda-forge gdal + + - name: Verify the built dist/wheel is valid + run: | + python -m pip install dist/*.whl + python -c "import ${{ env.PACKAGE_NAME }}; print(f'{${{ env.PACKAGE_NAME }}}-{${{ env.PACKAGE_NAME }}.__version__}')" + + + upload-to-test-pypi: + environment: release + permissions: + id-token: write + needs: test-built-dist + + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: releases + path: dist + - name: Publish package to TestPyPI + uses: pypa/gh-action-pypi-publish@v1.9.0 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + verbose: true + skip_existing: true \ No newline at end of file