|
| 1 | +name: Build PyHttrack |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + pull_request: |
| 9 | + branches: [main, master] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-linux: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - arch: x64 |
| 20 | + gnu_arch: x86_64 |
| 21 | + - arch: x86 |
| 22 | + gnu_arch: i686 |
| 23 | + - arch: arm64 |
| 24 | + gnu_arch: aarch64 |
| 25 | + - arch: armv7 |
| 26 | + gnu_arch: armv7l |
| 27 | + - arch: ppc64le |
| 28 | + gnu_arch: ppc64le |
| 29 | + - arch: s390x |
| 30 | + gnu_arch: s390x |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: '3.x' |
| 39 | + |
| 40 | + - name: Install wget |
| 41 | + run: sudo apt-get update && sudo apt-get install -y wget |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + pip install -r requirements.txt |
| 46 | + pip install pyinstaller |
| 47 | +
|
| 48 | + - name: Build binary for Linux |
| 49 | + run: | |
| 50 | + pyinstaller --onefile --name pyhttrack \ |
| 51 | + --add-data "web.json:." \ |
| 52 | + --hidden-import colorama \ |
| 53 | + --console \ |
| 54 | + pyhttrack.py |
| 55 | + mkdir -p build/pyhttrack-linux-${{ matrix.arch }} |
| 56 | + mv dist/pyhttrack build/pyhttrack-linux-${{ matrix.arch }}/ |
| 57 | + mkdir -p build/pyhttrack-linux-${{ matrix.arch }}/web |
| 58 | + cp README.md LICENSE build/pyhttrack-linux-${{ matrix.arch }}/ |
| 59 | + tar -czvf pyhttrack-linux-${{ matrix.arch }}.tar.gz -C build pyhttrack-linux-${{ matrix.arch }} |
| 60 | +
|
| 61 | + - name: Upload artifacts |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: pyhttrack-linux-${{ matrix.arch }} |
| 65 | + path: pyhttrack-linux-${{ matrix.arch }}.tar.gz |
| 66 | + |
| 67 | + build-windows: |
| 68 | + runs-on: windows-latest |
| 69 | + strategy: |
| 70 | + fail-fast: false |
| 71 | + matrix: |
| 72 | + include: |
| 73 | + - arch: x64 |
| 74 | + - arch: x86 |
| 75 | + steps: |
| 76 | + - name: Checkout repository |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Set up Python |
| 80 | + uses: actions/setup-python@v5 |
| 81 | + with: |
| 82 | + python-version: '3.x' |
| 83 | + |
| 84 | + - name: Install dependencies |
| 85 | + run: | |
| 86 | + pip install -r requirements.txt |
| 87 | + pip install pyinstaller |
| 88 | +
|
| 89 | + - name: Download wget binaries for Windows |
| 90 | + run: | |
| 91 | + $arch = "${{ matrix.arch }}" |
| 92 | + New-Item -ItemType Directory -Force -Path "wget\$arch" |
| 93 | + $url = switch ($arch) { |
| 94 | + "x64" { "https://github.com/KnugiHK/wget-on-windows/releases/download/v1.25.0/wget-gnutls-x64.exe" } |
| 95 | + "x86" { "https://github.com/KnugiHK/wget-on-windows/releases/download/v1.25.0/wget-gnutls-x86.exe" } |
| 96 | + } |
| 97 | + Invoke-WebRequest -Uri $url -OutFile "wget\$arch\wget.exe" |
| 98 | +
|
| 99 | + - name: Build binary for Windows |
| 100 | + run: | |
| 101 | + pyinstaller --onefile --name pyhttrack ` |
| 102 | + --add-data "wget;wget" ` |
| 103 | + --add-data "web.json;." ` |
| 104 | + --hidden-import colorama ` |
| 105 | + --console ` |
| 106 | + pyhttrack.py |
| 107 | + New-Item -ItemType Directory -Force -Path build\pyhttrack-windows-${{ matrix.arch }} |
| 108 | + Move-Item dist\pyhttrack.exe build\pyhttrack-windows-${{ matrix.arch }}\ |
| 109 | + New-Item -ItemType Directory -Force -Path build\pyhttrack-windows-${{ matrix.arch }}\web |
| 110 | + Copy-Item README.md build\pyhttrack-windows-${{ matrix.arch }}\ |
| 111 | + Copy-Item LICENSE build\pyhttrack-windows-${{ matrix.arch }}\ |
| 112 | + Compress-Archive -Path build\pyhttrack-windows-${{ matrix.arch }}\* -DestinationPath pyhttrack-windows-${{ matrix.arch }}.tar.gz |
| 113 | +
|
| 114 | + - name: Upload artifacts |
| 115 | + uses: actions/upload-artifact@v4 |
| 116 | + with: |
| 117 | + name: pyhttrack-windows-${{ matrix.arch }} |
| 118 | + path: pyhttrack-windows-${{ matrix.arch }}.tar.gz |
| 119 | + |
| 120 | + release: |
| 121 | + needs: [build-linux, build-windows] |
| 122 | + if: startsWith(github.ref, 'refs/tags/v') |
| 123 | + runs-on: ubuntu-latest |
| 124 | + permissions: |
| 125 | + contents: write |
| 126 | + steps: |
| 127 | + - name: Download all artifacts |
| 128 | + uses: actions/download-artifact@v4 |
| 129 | + with: |
| 130 | + path: artifacts |
| 131 | + |
| 132 | + - name: Create Release |
| 133 | + uses: softprops/action-gh-release@v1 |
| 134 | + with: |
| 135 | + files: artifacts/**/* |
| 136 | + generate_release_notes: true |
| 137 | + env: |
| 138 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments