name: Continuous Delivery on: workflow_dispatch: release: types: - created permissions: contents: read jobs: pre_flight_check: name: Preflight Checks uses: ./.github/workflows/ci.yml universal-wheel: name: Build Universal Wheel runs-on: ubuntu-latest needs: - pre_flight_check steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: Set up Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: python-version: '3' - name: Install CI Requirements run: | python -m pip install -r ci-requirements.txt --require-hashes - name: Build Wheel env: CHARSET_NORMALIZER_USE_MYPYC: '0' run: python -m build - name: Upload artifacts uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f with: name: dist-universal path: dist build-wheels: name: Build wheels on ${{ matrix.os }} ${{ matrix.qemu }} runs-on: ${{ matrix.os }} needs: pre_flight_check strategy: matrix: os: [ubuntu-latest, windows-latest, macos-14, windows-11-arm, ubuntu-24.04-arm] qemu: [ '' ] include: # Split ubuntu job for the sake of speed-up - os: ubuntu-latest qemu: ppc64le - os: ubuntu-latest qemu: riscv64 - os: ubuntu-latest qemu: s390x - os: ubuntu-latest qemu: armv7l steps: - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: submodules: true - name: Set up QEMU if: ${{ matrix.qemu }} uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 with: platforms: all id: qemu - name: Prepare emulation if: ${{ matrix.qemu }} run: | echo "CIBW_ARCHS_LINUX=${{ matrix.qemu }}" >> $GITHUB_ENV shell: bash - name: Setup Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 - name: Build wheels uses: pypa/cibuildwheel@ee02a1537ce3071a004a6b08c41e72f0fdc42d9a # v3.4.0 env: CIBW_BUILD_FRONTEND: build CIBW_ARCHS_MACOS: universal2 CIBW_ENVIRONMENT: CHARSET_NORMALIZER_USE_MYPYC='1' CIBW_TEST_REQUIRES: pytest CIBW_TEST_COMMAND: pytest -c {package} {package}/tests - name: Upload artifacts uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f with: name: dist-${{ matrix.os }}-${{ matrix.qemu }} path: ./wheelhouse/*.whl checksum: name: Compute hashes runs-on: ubuntu-latest needs: - build-wheels - universal-wheel outputs: hashes: ${{ steps.compute.outputs.hashes }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Download distributions uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c with: pattern: dist* merge-multiple: true path: dist - name: Collected dists run: | tree dist - name: Generate hashes id: compute # needs.checksum.outputs.hashes working-directory: ./dist run: echo "hashes=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT provenance: needs: checksum uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@f7dd8c54c2067bafc12ca7a55595d5ee9b75204a permissions: actions: read id-token: write contents: write with: base64-subjects: ${{ needs.checksum.outputs.hashes }} upload-assets: true compile-generator: true deploy: name: 🚀 Deploy to PyPi runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') permissions: id-token: write contents: write needs: - provenance environment: name: pypi url: https://pypi.org/project/charset-normalizer/ steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: Download distributions uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c with: pattern: dist* merge-multiple: true path: dist - name: Collected dists run: | tree dist - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 - name: Install Syft run: | curl -sSfL https://get.anchore.io/syft | sudo sh -s -- -b /usr/local/bin syft version - name: Generate SBOMs run: | set -euo pipefail shopt -s nullglob restore_from="" restore_to="" for pkg in dist/*.whl dist/*.tar.gz; do original_pkg="$pkg" original_base="$(basename -- "$original_pkg")" out="dist/${original_base}.cdx.json" if [[ "$original_pkg" == *.whl ]]; then zip_pkg="${original_pkg%.whl}.zip" zip_base="${original_base%.whl}.zip" stem="${original_base%.whl}" echo "Temporarily renaming ${original_base} -> ${zip_base}" mv -- "$original_pkg" "$zip_pkg" restore_from="$zip_pkg" restore_to="$original_pkg" echo "Generating SBOM for $original_base via $zip_base" syft "file:$zip_pkg" -o cyclonedx-json > "$out" tmp="$out.tmp" jq --arg stem "$stem" ' (. | .. | objects | select(has("name")) | .name) |= (if . == ($stem + ".zip") then $stem + ".whl" else . end) ' "$out" > "$tmp" && mv "$tmp" "$out" echo "Restoring ${zip_base} -> ${original_base}" mv -- "$zip_pkg" "$original_pkg" restore_from="" restore_to="" else echo "Generating SBOM for $original_base" syft "file:$original_pkg" -o cyclonedx-json > "$out" fi done - name: Upload dists to GitHub Release env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" run: | set -euo pipefail files=(dist/*) batch_size=50 max_retries=3 for (( i=0; i<${#files[@]}; i+=batch_size )); do batch=("${files[@]:i:batch_size}") echo "Uploading batch $((i/batch_size + 1)) (${#batch[@]} files)..." for (( attempt=1; attempt<=max_retries; attempt++ )); do if gh release upload ${{ github.ref_name }} "${batch[@]}" --repo ${{ github.repository }} --clobber; then break fi if (( attempt == max_retries )); then echo "Failed to upload batch after $max_retries attempts" exit 1 fi delay=$(( attempt * 15 )) echo "Upload failed (attempt $attempt/$max_retries). Retrying in ${delay}s..." sleep "$delay" done done