diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b756691b..d9532ac7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,56 +153,3 @@ jobs: if: ${{ needs.docker-build.result == 'success' }} - run: echo 'The triggering workflow failed (docker)' && false if: ${{ needs.docker-build.result != 'success' }} - - build-package: - name: Build distribution 📦 - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - name: Install pypa/build - run: >- - python3 -m - pip install - build - setuptools - wheel - twine - --user - - name: Bump package version with local extension - run: etc/ci/bump-package-version.sh ".dev$(date +%s)" - - name: Build a binary wheel and a source tarball - run: make dist PYTHON=python3 - - name: Store the distribution packages - uses: actions/upload-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - publish-to-testpypi: - name: Publish Python 🐍 distribution 📦 to TestPyPI - needs: - - build-package - runs-on: ubuntu-latest - - environment: - name: testpypi - url: https://test.pypi.org/p/coq-tools - - permissions: - id-token: write # IMPORTANT: mandatory for trusted publishing - - steps: - - name: Download all the dists - uses: actions/download-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 67fba1e0..db222737 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,12 +1,17 @@ -name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI +name: Publish Python 🐍 distribution 📦 to PyPI or TestPyPI on: release: types: [published] # Only publish to pip when we formally publish a release # For more on how to formally release on Github, read https://help.github.com/en/articles/creating-releases + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: jobs: - build: + build-distribution: name: Build distribution 📦 runs-on: ubuntu-latest @@ -25,6 +30,9 @@ jobs: wheel twine --user + - name: Bump package version with local extension + run: etc/ci/bump-package-version.sh ".dev$(date +%s)" + if: ${{ ! ( startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' ) }} - name: Build a binary wheel and a source tarball run: make dist PYTHON=python3 - name: Store the distribution packages @@ -33,12 +41,94 @@ jobs: name: python-package-distributions path: dist/ + build-standalone: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + name: Build standalone ⛏️ ${{ matrix.os }} ${{ (matrix.os == 'windows-latest' && '🪟') || (matrix.os == 'macos-latest' && '🍎') || (matrix.os == 'ubuntu-latest' && '🐧') }} + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install pyinstaller + run: >- + python3 -m + pip install + pyinstaller + - name: Build a standalone executable + run: make standalone + - name: Store the standalone packages + uses: actions/upload-artifact@v3 + with: + name: python-standalone-${{ matrix.os }} + path: dist/ + + collect-standalone: + name: Collect standalone ⛏️ + runs-on: ubuntu-latest + needs: + - build-standalone + + steps: + - uses: actions/checkout@v4 + - name: Download standalone ⛏️ Ubuntu + uses: actions/download-artifact@v3 + with: + name: python-standalone-ubuntu-latest + path: dist-ubuntu/ + - name: Download standalone ⛏️ Windows + uses: actions/download-artifact@v3 + with: + name: python-standalone-windows-latest + path: dist-windows/ + - name: Download standalone ⛏️ MacOS + uses: actions/download-artifact@v3 + with: + name: python-standalone-macos-latest + path: dist-macos/ + - run: | + mkdir -p dist + for os in ubuntu windows macos; do + pushd "dist-$os" + find . + rm -rf */_internal + for d in */; do + pushd "$d" + for i in *; do + echo "$i" + chmod +x "$i" + if [[ $i == *".exe" ]]; then + # If string ends with .exe, insert -os before .exe + mv "$i" "../../dist/${i/.exe/-${os}.exe}" + else + # Otherwise, just append -os + mv "$i" "../../dist/${i}-${os}" + fi + done + popd + done + popd + done + find dist/ + ls -la dist/ + tar -czvf standalone.tar.gz dist/ + - name: Store the standalone ⛏️ packages + uses: actions/upload-artifact@v3 + with: + name: python-standalone + path: standalone.tar.gz + publish-to-pypi: name: >- - Publish Python 🐍 distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + PiPI: Publish Python 🐍 distribution 📦 + if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' }} # only publish to PyPI on tag pushes needs: - - build + - build-distribution runs-on: ubuntu-latest environment: name: pypi @@ -55,12 +145,57 @@ jobs: - name: Publish distribution 📦 to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + publish-to-testpypi: + name: >- + TestPyPI: Publish Python 🐍 distribution 📦 + if: ${{ ! ( startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' ) }} # only publish to TestPyPI on non-tag pushes + needs: + - build-distribution + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/coq-tools + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + check-publish: + runs-on: ubuntu-latest + needs: + - publish-to-testpypi + - collect-standalone + if: ${{ always() && ! ( startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' ) }} + steps: + - run: echo 'The triggering workflow (publish-to-testpypi) passed' + if: ${{ needs.publish-to-testpypi.result == 'success' }} + - run: echo 'The triggering workflow (publish-to-testpypi) failed' && false + if: ${{ needs.publish-to-testpypi.result != 'success' }} + - run: echo 'The triggering workflow (collect-standalone) passed' + if: ${{ needs.collect-standalone.result == 'success' }} + - run: echo 'The triggering workflow (collect-standalone) failed' && false + if: ${{ needs.collect-standalone.result != 'success' }} + + github-release: name: >- Sign the Python 🐍 distribution 📦 with Sigstore and upload them to GitHub Release + if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' }} # only publish to PyPI on tag pushes needs: - publish-to-pypi + - collect-standalone runs-on: ubuntu-latest permissions: @@ -73,12 +208,20 @@ jobs: with: name: python-package-distributions path: dist/ + - name: Download standalone + uses: actions/download-artifact@v3 + with: + name: python-standalone + path: standalone.tar.gz + - name: Unpack standalone + run: tar -xzvf standalone.tar.gz - name: Sign the dists with Sigstore uses: sigstore/gh-action-sigstore-python@v2.1.0 with: inputs: >- - ./dist/*.tar.gz - ./dist/*.whl + ./dist/* + # ./dist/*.tar.gz + # ./dist/*.whl - name: Upload artifact signatures to GitHub Release env: GITHUB_TOKEN: ${{ github.token }} @@ -93,6 +236,7 @@ jobs: bump-package-version: name: Bump package version runs-on: ubuntu-latest + if: ${{ startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' }} # only publish to PyPI on tag pushes steps: - uses: actions/checkout@v4