From 56888388998dfcb3aa20aba78a029b6110eb6eea Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 29 Jun 2023 10:11:17 +0200 Subject: [PATCH] Publish to pypi from main workflow Increase the distribution version number to be able to upload new package --- .github/workflows/ResInsightWithCache.yml | 58 +++++++++++++++++++---- GrpcInterface/Python/setup.py.cmake | 2 +- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ResInsightWithCache.yml b/.github/workflows/ResInsightWithCache.yml index 6a6dc03d2d..37dba8eb32 100644 --- a/.github/workflows/ResInsightWithCache.yml +++ b/.github/workflows/ResInsightWithCache.yml @@ -18,7 +18,7 @@ concurrency: cancel-in-progress: true jobs: - ResInsight-x64-buildcache: + build: runs-on: ${{ matrix.config.os }} strategy: fail-fast: false @@ -34,6 +34,7 @@ jobs: build-python-module: true, execute-unit-tests: true, unity-build: true, + publish-to-pypi: false, } - { name: "Ubuntu Latest gcc", @@ -45,6 +46,7 @@ jobs: build-python-module: true, execute-unit-tests: true, unity-build: false, + publish-to-pypi: true, } - { name: "Ubuntu Latest clang", @@ -56,6 +58,7 @@ jobs: build-python-module: true, execute-unit-tests: true, unity-build: false, + publish-to-pypi: false, } steps: - name: Checkout @@ -79,10 +82,9 @@ jobs: run: echo "${{ steps.python-path.outputs.PYTHON_EXECUTABLE }}" - name: Install dependencies - # Make sure protobuf version is compatible with grpc - https://github.com/OPM/ResInsight/issues/9304 run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install -r GrpcInterface/Python/requirements.txt - name: Use CMake uses: lukka/get-cmake@latest @@ -222,22 +224,62 @@ jobs: - name: Stats for buildcache run: ${{ github.workspace }}/buildcache/bin/buildcache -s - name: Run Unit Tests - if: matrix.config.execute-unit-tests == 'true' + if: matrix.config.execute-unit-tests shell: bash run: | cmakebuild/ApplicationExeCode/ResInsight --unittest - name: Run pytest - if: matrix.config.build-python-module == 'true' + if: matrix.config.build-python-module env: RESINSIGHT_EXECUTABLE: ${{ runner.workspace }}/ResInsight/cmakebuild/ApplicationExeCode/ResInsight run: | - cd GrpcInterface/Python/rips + cd GrpcInterface/Python + python setup.py sdist + cd rips ${{ steps.python-path.outputs.PYTHON_EXECUTABLE }} -m pytest --console - - name: Upload artifact - if: matrix.config.os == 'windows-latest' + - name: Upload python distribution folder + if: matrix.config.publish-to-pypi + uses: actions/upload-artifact@v3 + with: + name: python-distribution + path: GrpcInterface/Python/dist + + - name: Upload Windows install artifact + if: ${{contains( matrix.config.os, 'windows') }} uses: actions/upload-artifact@v3 with: name: ResInsight-${{ matrix.config.name }} path: ${{ runner.workspace }}/ResInsight/cmakebuild/install + + pypi-publish: + name: Upload release to PyPI + needs: build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/rips + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + + # If this is a tagged release + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + + steps: + - name: Download python distribution folder + uses: actions/download-artifact@v3 + with: + name: python-distribution + path: dist + + - name: Display structure of downloaded files + run: ls -R + + - name: Publish package distributions to TestPyPI + # https://docs.pypi.org/trusted-publishers/adding-a-publisher/ + uses: pypa/gh-action-pypi-publish@release/v1 + # uncomment the two lines below to publish to test PyPi + # with: + # repository-url: https://test.pypi.org/legacy/ + diff --git a/GrpcInterface/Python/setup.py.cmake b/GrpcInterface/Python/setup.py.cmake index 9f14dcab76..dc6d0a557c 100644 --- a/GrpcInterface/Python/setup.py.cmake +++ b/GrpcInterface/Python/setup.py.cmake @@ -6,7 +6,7 @@ with open('README.md') as f: with open('LICENSE') as f: license = f.read() -RIPS_DIST_VERSION = '1' +RIPS_DIST_VERSION = '2' setup( name='rips',