Debian Codegraph @

.github/workflows/cd.yml

raw
1 name: Continuous Delivery
2
3 on:
4 workflow_dispatch:
5
6 release:
7 types:
8 - created
9
10 permissions:
11 contents: read
12
13 jobs:
14 pre_flight_check:
15 name: Preflight Checks
16 uses: ./.github/workflows/ci.yml
17
18 universal-wheel:
19 name: Build Universal Wheel
20 runs-on: ubuntu-latest
21 needs:
22 - pre_flight_check
23 steps:
24 - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25 with:
26 persist-credentials: false
27 - name: Set up Python
28 uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
29 with:
30 python-version: '3'
31 - name: Install CI Requirements
32 run: |
33 python -m pip install -r ci-requirements.txt --require-hashes
34 - name: Build Wheel
35 env:
36 CHARSET_NORMALIZER_USE_MYPYC: '0'
37 run: python -m build
38 - name: Upload artifacts
39 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
40 with:
41 name: dist-universal
42 path: dist
43
44 build-wheels:
45 name: Build wheels on ${{ matrix.os }} ${{ matrix.qemu }}
46 runs-on: ${{ matrix.os }}
47 needs: pre_flight_check
48 strategy:
49 matrix:
50 os: [ubuntu-latest, windows-latest, macos-14, windows-11-arm, ubuntu-24.04-arm]
51 qemu: [ '' ]
52 include:
53 # Split ubuntu job for the sake of speed-up
54 - os: ubuntu-latest
55 qemu: ppc64le
56 - os: ubuntu-latest
57 qemu: riscv64
58 - os: ubuntu-latest
59 qemu: s390x
60 - os: ubuntu-latest
61 qemu: armv7l
62 steps:
63 - name: Checkout
64 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
65 with:
66 submodules: true
67 - name: Set up QEMU
68 if: ${{ matrix.qemu }}
69 uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
70 with:
71 platforms: all
72 id: qemu
73 - name: Prepare emulation
74 if: ${{ matrix.qemu }}
75 run: |
76 echo "CIBW_ARCHS_LINUX=${{ matrix.qemu }}" >> $GITHUB_ENV
77 shell: bash
78 - name: Setup Python
79 uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
80 - name: Build wheels
81 uses: pypa/cibuildwheel@ee02a1537ce3071a004a6b08c41e72f0fdc42d9a # v3.4.0
82 env:
83 CIBW_BUILD_FRONTEND: build
84 CIBW_ARCHS_MACOS: universal2
85 CIBW_ENVIRONMENT: CHARSET_NORMALIZER_USE_MYPYC='1'
86 CIBW_TEST_REQUIRES: pytest
87 CIBW_TEST_COMMAND: pytest -c {package} {package}/tests
88 - name: Upload artifacts
89 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
90 with:
91 name: dist-${{ matrix.os }}-${{ matrix.qemu }}
92 path: ./wheelhouse/*.whl
93
94 checksum:
95 name: Compute hashes
96 runs-on: ubuntu-latest
97 needs:
98 - build-wheels
99 - universal-wheel
100 outputs:
101 hashes: ${{ steps.compute.outputs.hashes }}
102 steps:
103 - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
104 - name: Download distributions
105 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
106 with:
107 pattern: dist*
108 merge-multiple: true
109 path: dist
110 - name: Collected dists
111 run: |
112 tree dist
113 - name: Generate hashes
114 id: compute # needs.checksum.outputs.hashes
115 working-directory: ./dist
116 run: echo "hashes=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT
117
118 provenance:
119 needs: checksum
120 uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@f7dd8c54c2067bafc12ca7a55595d5ee9b75204a
121 permissions:
122 actions: read
123 id-token: write
124 contents: write
125 with:
126 base64-subjects: ${{ needs.checksum.outputs.hashes }}
127 upload-assets: true
128 compile-generator: true
129
130 deploy:
131 name: 🚀 Deploy to PyPi
132 runs-on: ubuntu-latest
133 if: startsWith(github.ref, 'refs/tags/')
134 permissions:
135 id-token: write
136 contents: write
137 needs:
138 - provenance
139 environment:
140 name: pypi
141 url: https://pypi.org/project/charset-normalizer/
142 steps:
143 - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
144 with:
145 persist-credentials: false
146 - name: Download distributions
147 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
148 with:
149 pattern: dist*
150 merge-multiple: true
151 path: dist
152 - name: Collected dists
153 run: |
154 tree dist
155 - name: Publish package distributions to PyPI
156 uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
157 - name: Install Syft
158 run: |
159 curl -sSfL https://get.anchore.io/syft | sudo sh -s -- -b /usr/local/bin
160 syft version
161 - name: Generate SBOMs
162 run: |
163 set -euo pipefail
164 shopt -s nullglob
165
166 restore_from=""
167 restore_to=""
168
169 for pkg in dist/*.whl dist/*.tar.gz; do
170 original_pkg="$pkg"
171 original_base="$(basename -- "$original_pkg")"
172 out="dist/${original_base}.cdx.json"
173
174 if [[ "$original_pkg" == *.whl ]]; then
175 zip_pkg="${original_pkg%.whl}.zip"
176 zip_base="${original_base%.whl}.zip"
177 stem="${original_base%.whl}"
178
179 echo "Temporarily renaming ${original_base} -> ${zip_base}"
180 mv -- "$original_pkg" "$zip_pkg"
181 restore_from="$zip_pkg"
182 restore_to="$original_pkg"
183
184 echo "Generating SBOM for $original_base via $zip_base"
185 syft "file:$zip_pkg" -o cyclonedx-json > "$out"
186
187 tmp="$out.tmp"
188 jq --arg stem "$stem" '
189 (. | .. | objects | select(has("name")) | .name)
190 |= (if . == ($stem + ".zip") then $stem + ".whl" else . end)
191 ' "$out" > "$tmp" && mv "$tmp" "$out"
192
193 echo "Restoring ${zip_base} -> ${original_base}"
194 mv -- "$zip_pkg" "$original_pkg"
195 restore_from=""
196 restore_to=""
197 else
198 echo "Generating SBOM for $original_base"
199 syft "file:$original_pkg" -o cyclonedx-json > "$out"
200 fi
201 done
202 - name: Upload dists to GitHub Release
203 env:
204 GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
205 run: |
206 set -euo pipefail
207
208 files=(dist/*)
209 batch_size=50
210 max_retries=3
211
212 for (( i=0; i<${#files[@]}; i+=batch_size )); do
213 batch=("${files[@]:i:batch_size}")
214 echo "Uploading batch $((i/batch_size + 1)) (${#batch[@]} files)..."
215
216 for (( attempt=1; attempt<=max_retries; attempt++ )); do
217 if gh release upload ${{ github.ref_name }} "${batch[@]}" --repo ${{ github.repository }} --clobber; then
218 break
219 fi
220
221 if (( attempt == max_retries )); then
222 echo "Failed to upload batch after $max_retries attempts"
223 exit 1
224 fi
225
226 delay=$(( attempt * 15 ))
227 echo "Upload failed (attempt $attempt/$max_retries). Retrying in ${delay}s..."
228 sleep "$delay"
229 done
230 done