|
| 1 | +name: Manual Python PyPI Release Publishing |
| 2 | + |
| 3 | +env: |
| 4 | + PROTOBUF_VERSION: 3.20.1 |
| 5 | + PROTOBUF_VARIANT: '-all' # Use '-all' prior to 22.0, '' after |
| 6 | + ABSEIL_VERSION: 20230802.1 |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + tag: |
| 12 | + description: 'Tag to publish' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-proto2-linux64: |
| 18 | + name: Build Proto2 Linux 64 |
| 19 | + |
| 20 | + runs-on: ubuntu-22.04 |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout OSI |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: ${{ format('refs/tags/{0}', inputs.tag) }} |
| 27 | + submodules: true |
| 28 | + |
| 29 | + - name: Check Build Setup |
| 30 | + run: | |
| 31 | + ( result=0 ; for f in *.proto ; do grep -wq "$f" CMakeLists.txt || { echo "Missing $f in CMakeLists.txt" && let "result++"; } ; done ; exit $result ) |
| 32 | + ( result=0 ; for f in *.proto ; do grep -q '"'$f'"' setup.py || { echo "Missing $f in setup.py" && let "result++"; } ; done ; exit $result ) |
| 33 | +
|
| 34 | + - name: Setup Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: '3.8' |
| 38 | + |
| 39 | + - name: Install Python Dependencies |
| 40 | + run: | |
| 41 | + python -m pip install --upgrade pip |
| 42 | + python -m pip install build |
| 43 | + python -m pip install -r requirements_tests.txt |
| 44 | +
|
| 45 | + - name: Install Doxygen |
| 46 | + run: sudo apt-get install doxygen graphviz |
| 47 | + |
| 48 | + - name: Cache Dependencies |
| 49 | + id: cache-depends |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + path: protobuf-${{ env.PROTOBUF_VERSION }} |
| 53 | + key: ${{ runner.os }}-v2-depends |
| 54 | + |
| 55 | + - name: Download ProtoBuf ${{ env.PROTOBUF_VERSION }} |
| 56 | + if: steps.cache-depends.outputs.cache-hit != 'true' |
| 57 | + run: curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v${{env.PROTOBUF_VERSION}}/protobuf${{env.PROTOBUF_VARIANT}}-${{env.PROTOBUF_VERSION}}.tar.gz && tar xzvf protobuf${{env.PROTOBUF_VARIANT}}-${{env.PROTOBUF_VERSION}}.tar.gz |
| 58 | + |
| 59 | + - name: Download Abseil ${{ env.ABSEIL_VERSION }} |
| 60 | + if: steps.cache-depends.outputs.cache-hit != 'true' && env.PROTOBUF_VARIANT == '' |
| 61 | + run: curl -OL https://github.com/abseil/abseil-cpp/archive/refs/tags/${{env.ABSEIL_VERSION}}.tar.gz && tar xzvf ${{env.ABSEIL_VERSION}}.tar.gz && rm -rf protobuf-${{env.PROTOBUF_VERSION}}/third_party/abseil-cpp && mv abseil-cpp-${{env.ABSEIL_VERSION}} protobuf-${{env.PROTOBUF_VERSION}}/third_party/abseil-cpp |
| 62 | + |
| 63 | + - name: Build ProtoBuf ${{ env.PROTOBUF_VERSION }} via autotools |
| 64 | + if: steps.cache-depends.outputs.cache-hit != 'true' && env.PROTOBUF_VARIANT == '-all' |
| 65 | + working-directory: protobuf-${{ env.PROTOBUF_VERSION }} |
| 66 | + run: ./configure DIST_LANG=cpp --prefix=/usr && make |
| 67 | + |
| 68 | + - name: Build ProtoBuf ${{ env.PROTOBUF_VERSION }} via cmake |
| 69 | + if: steps.cache-depends.outputs.cache-hit != 'true' && env.PROTOBUF_VARIANT == '' |
| 70 | + working-directory: protobuf-${{ env.PROTOBUF_VERSION }} |
| 71 | + run: cmake -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF . && cmake --build . --config Release -j 4 |
| 72 | + |
| 73 | + - name: Install ProtoBuf ${{ env.PROTOBUF_VERSION }} |
| 74 | + working-directory: protobuf-${{ env.PROTOBUF_VERSION }} |
| 75 | + run: sudo make install && sudo ldconfig |
| 76 | + |
| 77 | + - name: Install proto2cpp |
| 78 | + run: git clone --depth 1 https://github.com/OpenSimulationInterface/proto2cpp.git |
| 79 | + |
| 80 | + - name: Prepare C++ Build |
| 81 | + run: mkdir build |
| 82 | + |
| 83 | + - name: Get git Version |
| 84 | + id: get_version |
| 85 | + run: echo "VERSION=$(git describe --tags --always)" >> $GITHUB_OUTPUT |
| 86 | + |
| 87 | + - name: Prepare Documentation Build |
| 88 | + run: | |
| 89 | + sed -i 's/PROJECT_NUMBER\s*= @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@/PROJECT_NUMBER = master (${{ steps.get_version.outputs.VERSION }})/g' doxygen_config.cmake.in |
| 90 | + echo "EXCLUDE_PATTERNS = */osi3/* */protobuf-*/* */proto2cpp/* */flatbuffers/*" >> doxygen_config.cmake.in |
| 91 | + echo "GENERATE_TREEVIEW = YES" >> doxygen_config.cmake.in |
| 92 | +
|
| 93 | + - name: Configure C++ Build |
| 94 | + working-directory: build |
| 95 | + run: cmake -D FILTER_PROTO2CPP_PY_PATH=$GITHUB_WORKSPACE/proto2cpp ${{ env.PROTOBUF_VARIANT =='' && '-DCMAKE_CXX_STANDARD=17' }} .. |
| 96 | + |
| 97 | + - name: Build C++ |
| 98 | + working-directory: build |
| 99 | + run: cmake --build . --config Release -j 4 |
| 100 | + |
| 101 | + - name: Build Python |
| 102 | + run: python -m build |
| 103 | + |
| 104 | + - name: Install Python |
| 105 | + run: python -m pip install . |
| 106 | + |
| 107 | + - name: Run Python Tests |
| 108 | + run: python -m unittest discover tests |
| 109 | + |
| 110 | + - name: Upload Python Distribution |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: python-dist |
| 114 | + path: dist/ |
| 115 | + |
| 116 | + publish-python-dist: |
| 117 | + name: Publish Python Distribution |
| 118 | + |
| 119 | + runs-on: ubuntu-22.04 |
| 120 | + |
| 121 | + permissions: |
| 122 | + id-token: write |
| 123 | + |
| 124 | + needs: [build-proto2-linux64] |
| 125 | + |
| 126 | + steps: |
| 127 | + - name: Download Distribution |
| 128 | + uses: actions/download-artifact@v4 |
| 129 | + with: |
| 130 | + name: python-dist |
| 131 | + path: dist/ |
| 132 | + |
| 133 | + - name: Publish Snapshot Release on TestPyPI |
| 134 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 135 | + continue-on-error: true |
| 136 | + with: |
| 137 | + repository-url: https://test.pypi.org/legacy/ |
| 138 | + |
| 139 | + - name: Publish Full Release on PyPI |
| 140 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments