Jelajahi Sumber

feat: modify build and release

Joao Andre 1 tahun lalu
induk
melakukan
f471fc7e79

+ 8 - 10
.github/workflows/build-and-release-dev.yml

@@ -91,6 +91,10 @@ jobs:
             ${{needs.fetch-versions.outputs.templates_VERSION}} \
             ${{ github.event.inputs.publish_on_pypi }}
 
+      - name: Copy tools
+        run: |
+          cp -r tools ${{ steps.set-variables.outputs.package_dir }}
+
       - name: Install dependencies
         run: |
           python -m pip install --upgrade pip
@@ -98,7 +102,8 @@ jobs:
 
       - name: Build package
         working-directory: ${{ steps.set-variables.outputs.package_dir }}
-        run: python setup.py build_py && python -m build
+        run: |
+          python setup.py build_py && python -m build
 
       - name: Create tag and release
         working-directory: ${{ steps.set-variables.outputs.package_dir }}
@@ -113,12 +118,8 @@ jobs:
           pip install ${{ steps.set-variables.outputs.tar_path }}
 
       - name: Publish to PyPI
-        if: ${{ github.event.inputs.publish_on_pypi == 'true' }}
-        working-directory: ${{ steps.set-variables.outputs.package_dir }}
+        if: github.event.inputs.publish_on_pypi == 'true'
         uses: pypa/gh-action-pypi-publish@release/v1
-        with:
-          user: __token__
-          password: ${{ secrets[format('PYPI_API_TOKEN_{0}', ${{ matrix.package }} )] }}
 
   build-and-release-taipy-dev:
     runs-on: ubuntu-latest
@@ -173,11 +174,8 @@ jobs:
           python tools/validate_taipy_install.py
 
       - name: Publish to PyPI
-        if: ${{ github.event.inputs.publish_on_pypi == 'true' }}
+        if: github.event.inputs.publish_on_pypi == 'true'
         uses: pypa/gh-action-pypi-publish@release/v1
-        with:
-          user: __token__
-          password: ${{ secrets.PYPI_API_TOKEN }}
 
       - name: Download packages
         run: |

+ 42 - 5
.github/workflows/publish.yml

@@ -48,22 +48,59 @@ jobs:
           sparse-checkout: taipy/${{ matrix.package }}
           sparse-checkout-cone-mode: false
 
+      - name: Checks if package is already on on Pypi
+        id: check-version
+        run: |
+          if curl https://pypi.org/simple/taipy-${{ matrix.package }} | grep -o ">taipy-${{ matrix.package }}-${{ github.event.inputs.version }}\.tar\.gz<"; then
+            echo "exists=true" >> $GITHUB_OUTPUT
+          else
+            echo "exists=false" >> $GITHUB_OUTPUT
+          fi
+
       - name: Download assets from tag
+        if: steps.check-version.outputs.exists == 'false'
         run: |
           gh release download ${{ github.event.inputs.version }}-${{ matrix.package }} --dir dist
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
-      - name: Test token
-        run: echo ${{ secrets[format('PYPI_API_TOKEN_{0}', matrix.package )] }}
+      - name: Publish to PyPI
+        if: steps.check-version.outputs.exists == 'false'
+        uses: pypa/gh-action-pypi-publish@release/v1
+
+  publish-main-package-to-pypi:
+    permissions:
+      id-token: write  # IMPORTANT: this permission is mandatory for trusted publishing
+    needs: [ test-package ]
+    timeout-minutes: 20
+    environment: publish
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Checks if package is already on on Pypi
+        id: check-version
+        run: |
+          if curl https://pypi.org/simple/taipy | grep -o ">taipy-${{ github.event.inputs.version }}\.tar\.gz<"; then
+            echo "exists=true" >> $GITHUB_OUTPUT
+          else
+            echo "exists=false" >> $GITHUB_OUTPUT
+          fi
+
+      - name: Download assets from tag
+        if: steps.check-version.outputs.exists == 'false'
+        run: |
+          gh release download ${{ github.event.inputs.version }} --dir dist
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Publish to PyPI
+        if: steps.check-version.outputs.exists == 'false'
         uses: pypa/gh-action-pypi-publish@release/v1
-        with:
-          verbose: true
+
 
   test-published-package:
-    needs: [publish-subpackages-to-pypi]
+    needs: [publish-main-package-to-pypi]
     timeout-minutes: 30
     strategy:
       matrix:

+ 12 - 3
tools/release/setup_version.py

@@ -1,3 +1,14 @@
+# Copyright 2021-2024 Avaiga Private Limited
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations under the License.
+
 import json
 import os
 import re
@@ -62,9 +73,7 @@ def extract_version(base_path: str) -> Version:
     return __load_version_from_path(base_path)
 
 
-def __setup_dev_version(
-    version: Version, _base_path: str, name: Optional[str] = None, bump_dev_version: bool = False
-) -> None:
+def __setup_dev_version(version: Version, _base_path: str, name: Optional[str] = None) -> None:
     version.validate_suffix()
 
     name = f"{name}_VERSION" if name else "VERSION"