| 1 |
name: Build Pacparser |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: [main] |
| 6 |
paths: |
| 7 |
- "src/**" |
| 8 |
- ".github/**" |
| 9 |
- Makefile |
| 10 |
- Dockerfile |
| 11 |
pull_request: |
| 12 |
release: |
| 13 |
types: [published] |
| 14 |
workflow_dispatch: |
| 15 |
inputs: |
| 16 |
tag: |
| 17 |
description: "Tag to run workflow for" |
| 18 |
required: true |
| 19 |
|
| 20 |
permissions: |
| 21 |
contents: read |
| 22 |
packages: write |
| 23 |
|
| 24 |
jobs: |
| 25 |
build: |
| 26 |
strategy: |
| 27 |
matrix: |
| 28 |
os: [ubuntu-latest, windows-latest, macos-latest] |
| 29 |
include: |
| 30 |
- os: ubuntu-latest |
| 31 |
os_suffix: "ubuntu-x86_64" |
| 32 |
- os: macos-latest |
| 33 |
os_suffix: "macos-arm64" |
| 34 |
- os: windows-latest |
| 35 |
os_suffix: "windows-x86_64" |
| 36 |
runs-on: ${{ matrix.os }} |
| 37 |
|
| 38 |
steps: |
| 39 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 40 |
if: ${{ !contains(github.event_name, 'workflow_dispatch') }} |
| 41 |
with: |
| 42 |
fetch-depth: 0 |
| 43 |
|
| 44 |
- name: Check out code for workflow_dispatch |
| 45 |
if: ${{ contains(github.event_name, 'workflow_dispatch') }} |
| 46 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 47 |
with: |
| 48 |
fetch-depth: 0 |
| 49 |
ref: ${{ github.event.inputs.tag }} |
| 50 |
|
| 51 |
- name: make non-windows |
| 52 |
if: ${{ matrix.os != 'windows-latest' }} |
| 53 |
run: make -C src |
| 54 |
|
| 55 |
- name: Run resolve_host tests (non-windows) |
| 56 |
if: ${{ matrix.os != 'windows-latest' }} |
| 57 |
run: | |
| 58 |
cd tests |
| 59 |
for test in test_resolve_host test_multi_ip test_buffer_safety test_edge_cases; do |
| 60 |
echo "=== Building $test ===" |
| 61 |
gcc -g -Wall -o $test ${test}.c || exit 1 |
| 62 |
echo "=== Running $test ===" |
| 63 |
./$test || exit 1 |
| 64 |
echo |
| 65 |
done |
| 66 |
|
| 67 |
- name: make windows |
| 68 |
if: ${{ matrix.os == 'windows-latest' }} |
| 69 |
run: make -C src -f Makefile.win32 |
| 70 |
|
| 71 |
- name: Run resolve_host tests (windows) |
| 72 |
if: ${{ matrix.os == 'windows-latest' }} |
| 73 |
run: | |
| 74 |
cd tests |
| 75 |
foreach ($test in @('test_resolve_host', 'test_multi_ip', 'test_buffer_safety', 'test_edge_cases')) { |
| 76 |
Write-Host "=== Building $test ===" |
| 77 |
gcc -g -Wall -o "$test.exe" "$test.c" -lws2_32 |
| 78 |
if ($LASTEXITCODE -ne 0) { exit 1 } |
| 79 |
Write-Host "=== Running $test ===" |
| 80 |
& ".\$test.exe" |
| 81 |
if ($LASTEXITCODE -ne 0) { exit 1 } |
| 82 |
Write-Host "" |
| 83 |
} |
| 84 |
|
| 85 |
- name: Get ref_name |
| 86 |
id: get_ref_name |
| 87 |
if: ${{ matrix.os != 'windows-latest' }} |
| 88 |
run: | |
| 89 |
if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 90 |
echo "ref_name=${{ github.base_ref }}" |
| 91 |
echo "ref_name=${{ github.base_ref }}" >> $GITHUB_OUTPUT || exit 1 |
| 92 |
else |
| 93 |
echo "ref_name=${{ github.ref_name }}" |
| 94 |
echo "ref_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT || exit 1 |
| 95 |
fi |
| 96 |
|
| 97 |
- name: make non-windows dist |
| 98 |
if: ${{ matrix.os != 'windows-latest' }} |
| 99 |
run: | |
| 100 |
DIST_OS_SUFFIX=${{ matrix.os_suffix }} make -C src dist |
| 101 |
ls -R src/*.zip |
| 102 |
|
| 103 |
- name: make windows dist |
| 104 |
if: ${{ matrix.os == 'windows-latest' }} |
| 105 |
run: | |
| 106 |
make -C src -f Makefile.win32 dist |
| 107 |
|
| 108 |
- name: Upload dist (non-windows) |
| 109 |
if: ${{ matrix.os != 'windows-latest' }} |
| 110 |
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 111 |
with: |
| 112 |
name: pacparser-dist-${{ matrix.os }} |
| 113 |
path: src/pacparser*.zip |
| 114 |
|
| 115 |
- name: Upload dist (windows) |
| 116 |
if: ${{ matrix.os == 'windows-latest' }} |
| 117 |
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 118 |
with: |
| 119 |
name: pacparser-dist-${{ matrix.os }} |
| 120 |
path: src/dist |
| 121 |
|
| 122 |
build-release-binaries: |
| 123 |
needs: build |
| 124 |
runs-on: ubuntu-latest |
| 125 |
steps: |
| 126 |
- name: Download ubuntu cloudprober binaries |
| 127 |
uses: actions/download-artifact@v8 |
| 128 |
with: |
| 129 |
pattern: pacparser-dist-* |
| 130 |
|
| 131 |
- name: Fix files |
| 132 |
run: | |
| 133 |
ls -R . |
| 134 |
mv pacparser-dist-*/*.zip . |
| 135 |
file=$(ls pacparser-*-ubuntu*.zip) |
| 136 |
name=${file/ubuntu/windows} |
| 137 |
name=${name/.zip/} |
| 138 |
mv pacparser-dist-windows-latest $name |
| 139 |
zip -r $name.zip $name |
| 140 |
|
| 141 |
- name: Upload pacparser release |
| 142 |
uses: actions/upload-artifact@v7 |
| 143 |
with: |
| 144 |
name: pacparser-release-binaries |
| 145 |
path: pacparser-*.zip |
| 146 |
|
| 147 |
python-module-build: |
| 148 |
strategy: |
| 149 |
matrix: |
| 150 |
os: [ubuntu-latest, windows-latest, macos-latest] |
| 151 |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] |
| 152 |
runs-on: ${{ matrix.os }} |
| 153 |
|
| 154 |
steps: |
| 155 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 156 |
if: ${{ !contains(github.event_name, 'workflow_dispatch') }} |
| 157 |
with: |
| 158 |
fetch-depth: 0 |
| 159 |
|
| 160 |
- name: Check out code for workflow_dispatch |
| 161 |
if: ${{ contains(github.event_name, 'workflow_dispatch') }} |
| 162 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 163 |
with: |
| 164 |
fetch-depth: 0 |
| 165 |
ref: ${{ github.event.inputs.tag }} |
| 166 |
|
| 167 |
- name: Set up Python |
| 168 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 169 |
with: |
| 170 |
python-version: ${{ matrix.python-version }} |
| 171 |
|
| 172 |
- name: Set up setuptools |
| 173 |
run: | |
| 174 |
python --version |
| 175 |
python -mpip install setuptools |
| 176 |
|
| 177 |
- name: make non-windows |
| 178 |
if: ${{ matrix.os != 'windows-latest' }} |
| 179 |
run: make -C src pymod-dist |
| 180 |
|
| 181 |
- name: make windows |
| 182 |
if: ${{ matrix.os == 'windows-latest' }} |
| 183 |
run: make -C src -f Makefile.win32 pymod-dist |
| 184 |
|
| 185 |
- name: Upload dist |
| 186 |
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 187 |
with: |
| 188 |
name: |
| 189 |
pacparser-python-${{ matrix.python-version }}-${{ matrix.os }}-dist |
| 190 |
path: src/pymod/pacparser-python* |
| 191 |
|
| 192 |
- name: Build wheel non-linux |
| 193 |
if: ${{ matrix.os != 'ubuntu-latest' }} |
| 194 |
run: | |
| 195 |
python -m pip install wheel |
| 196 |
cd src/pymod && python setup.py bdist_wheel |
| 197 |
|
| 198 |
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 |
| 199 |
id: src_changes |
| 200 |
with: |
| 201 |
filters: | |
| 202 |
changed: |
| 203 |
- 'src/**' |
| 204 |
|
| 205 |
- name: Publish package to PyPI (non-linux) |
| 206 |
if: | |
| 207 |
(matrix.os != 'ubuntu-latest') && |
| 208 |
(steps.src_changes.outputs.changed == 'true' || |
| 209 |
startsWith(github.event.inputs.tag, 'v') || startsWith(github.ref, |
| 210 |
'refs/tags/v')) && (github.event_name != 'pull_request') |
| 211 |
env: |
| 212 |
TWINE_USERNAME: __token__ |
| 213 |
TWINE_PASSWORD: ${{ secrets.PYPI }} |
| 214 |
run: | |
| 215 |
python -m pip install twine |
| 216 |
ls -R . |
| 217 |
twine upload src/pymod/dist/* |
| 218 |
|
| 219 |
build-linux-wheels: |
| 220 |
runs-on: ubuntu-latest |
| 221 |
|
| 222 |
steps: |
| 223 |
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 224 |
if: ${{ !contains(github.event_name, 'workflow_dispatch') }} |
| 225 |
with: |
| 226 |
fetch-depth: 0 |
| 227 |
|
| 228 |
- name: Check out code for workflow_dispatch |
| 229 |
if: ${{ contains(github.event_name, 'workflow_dispatch') }} |
| 230 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 231 |
with: |
| 232 |
fetch-depth: 0 |
| 233 |
ref: ${{ github.event.inputs.tag }} |
| 234 |
|
| 235 |
- name: Set env |
| 236 |
run: | |
| 237 |
echo "PACPARSER_VERSION=$(git describe --always --tags \ |
| 238 |
--candidate=100)" >> $GITHUB_ENV |
| 239 |
|
| 240 |
- name: Set up Python |
| 241 |
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 242 |
|
| 243 |
- name: Set up setuptools |
| 244 |
run: | |
| 245 |
python --version |
| 246 |
python -mpip install setuptools |
| 247 |
|
| 248 |
- name: make |
| 249 |
run: make -C src pymod |
| 250 |
|
| 251 |
- name: Build sdist |
| 252 |
run: cd src/pymod && python setup.py sdist |
| 253 |
|
| 254 |
- name: Install cibuildwheel and twine |
| 255 |
run: python -m pip install cibuildwheel twine |
| 256 |
|
| 257 |
- name: Build wheel using cibuildwheel |
| 258 |
run: | |
| 259 |
cd src/pymod && python setup.py clean --all |
| 260 |
cp -r ../quickjs ../pacparser.c ../pac_utils.h ../pacparser.h . |
| 261 |
python -m cibuildwheel --output-dir dist |
| 262 |
env: |
| 263 |
CIBW_BUILD: "cp{37,38,39,310,311,312}-manylinux*64" |
| 264 |
CIBW_ENVIRONMENT: "PACPARSER_VERSION=${{ env.PACPARSER_VERSION }}" |
| 265 |
CIBW_BEFORE_BUILD: >- |
| 266 |
cd {project} && |
| 267 |
make -C quickjs clean && |
| 268 |
make -C quickjs CFLAGS='-fPIC' && |
| 269 |
cc -g -Wall -DVERSION=$PACPARSER_VERSION -Iquickjs -fPIC -c pacparser.c -o pacparser.o && |
| 270 |
cp quickjs/libquickjs.a . |
| 271 |
|
| 272 |
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 |
| 273 |
id: src_changes |
| 274 |
with: |
| 275 |
filters: | |
| 276 |
changed: |
| 277 |
- 'src/**' |
| 278 |
|
| 279 |
- name: Publish package to PyPI |
| 280 |
if: | |
| 281 |
(startsWith(github.event.inputs.tag, 'v') || |
| 282 |
startsWith(github.ref,'refs/tags/v') || |
| 283 |
steps.src_changes.outputs.changed == 'true') && |
| 284 |
(github.event_name != 'pull_request') |
| 285 |
env: |
| 286 |
TWINE_USERNAME: __token__ |
| 287 |
TWINE_PASSWORD: ${{ secrets.PYPI }} |
| 288 |
run: | |
| 289 |
twine upload src/pymod/dist/* |
| 290 |
|
| 291 |
build_and_push_docker_multiarch: |
| 292 |
name: Build and push multiarch docker image |
| 293 |
if: | |
| 294 |
github.repository == 'manugarg/pacparser' && |
| 295 |
(github.ref == 'refs/heads/main' || startswith(github.ref, 'refs/heads/docker') || |
| 296 |
startsWith(github.ref, 'refs/tags/v')) |
| 297 |
runs-on: ubuntu-latest |
| 298 |
steps: |
| 299 |
- name: Check out code into the Go module directory |
| 300 |
if: ${{ !contains(github.event_name, 'workflow_dispatch') }} |
| 301 |
uses: actions/[email protected] |
| 302 |
with: |
| 303 |
fetch-depth: 0 |
| 304 |
|
| 305 |
- name: Check out code into the Go module directory |
| 306 |
if: ${{ contains(github.event_name, 'workflow_dispatch') }} |
| 307 |
uses: actions/[email protected] |
| 308 |
with: |
| 309 |
fetch-depth: 0 |
| 310 |
ref: ${{ github.event.inputs.tag }} |
| 311 |
|
| 312 |
- name: Set up QEMU |
| 313 |
uses: docker/setup-qemu-action@v4 |
| 314 |
|
| 315 |
- name: Set up Docker Buildx |
| 316 |
uses: docker/setup-buildx-action@v4 |
| 317 |
|
| 318 |
- name: Login to GHCR |
| 319 |
uses: docker/login-action@v4 |
| 320 |
with: |
| 321 |
registry: ghcr.io |
| 322 |
username: ${{ github.repository_owner }} |
| 323 |
password: ${{ secrets.GITHUB_TOKEN }} |
| 324 |
|
| 325 |
- name: Build and push release Docker Image (main-ghcr) |
| 326 |
run: make docker_multiarch DOCKER_IMAGE=ghcr.io/manugarg/pactester |