diff --git a/.github/workflows/_python-wheels.yml b/.github/workflows/_python-wheels.yml index 5942fd2..d3a321d 100644 --- a/.github/workflows/_python-wheels.yml +++ b/.github/workflows/_python-wheels.yml @@ -1,11 +1,25 @@ # A reusable workflow for building cross-platform Python wheels -on: workflow_call +on: + workflow_call: + inputs: + publishToPyPI: + required: false + default: false + type: boolean + publishToTestPyPI: + required: false + default: false + type: boolean jobs: build-wheels: runs-on: ubuntu-latest timeout-minutes: 10 + strategy: + matrix: + os: [linux, macos, windows] + architecture: [x86_64, aarch64] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 @@ -16,8 +30,35 @@ jobs: run: python -m pip install ziglang==0.9.1 wheel==0.37.1 - name: Build wheels - run: python python/make_wheels.py + run: python python/make_wheels.py ${{ matrix.architecture }}-${{ matrix.os }} - uses: actions/upload-artifact@v2 with: + name: wheels path: ./wheelhouse/*.whl + + upload-wheels-to-pypi: + runs-on: ubuntu-latest + timeout-minutes: 5 + needs: [build-wheels] + if: inputs.publishToPyPI || inputs.publishToTestPyPI + steps: + - uses: actions/download-artifact@v2 + with: + name: wheels + path: dist + + - name: Publish package to PyPI + if: inputs.publishToPyPI + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} + + - name: Publish package to Test PyPI + if: inputs.publishToTestPyPI + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index cc6bdc9..bc1549c 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -6,39 +6,95 @@ on: version: required: true type: string + uploadRelease: + required: false + default: false + type: boolean jobs: build-for-release: runs-on: ubuntu-latest timeout-minutes: 10 + strategy: + matrix: + os: [linux, macos, windows] + architecture: [x86_64, aarch64] + include: + - os: wasm steps: - uses: actions/checkout@v2 - uses: goto-bus-stop/setup-zig@v1 with: version: 0.9.1 - - run: | - sudo apt-get update - sudo apt install -y libcurl4-openssl-dev - # Linux/Wasm - - run: zig build - - run: zip -j fastfec-linux-x86_64-${{ inputs.version }}.zip zig-out/bin/fastfec - - run: mv zig-out/lib/libfastfec.so libfastfec-linux-x86_64-${{ inputs.version }}.so - - run: zig build -Dtarget=aarch64-linux - - run: zip -j fastfec-linux-aarch64-${{ inputs.version }}.zip zig-out/bin/fastfec - - run: mv zig-out/lib/libfastfec.so libfastfec-linux-aarch64-${{ inputs.version }}.so - - run: zig build -Dwasm - - run: mv zig-out/lib/fastfec.wasm libfastfec-${{ inputs.version }}.wasm - # Mac - - run: zig build -Dtarget=x86_64-macos - - run: zip -j fastfec-macos-x86_64-${{ inputs.version }}.zip zig-out/bin/fastfec - - run: mv zig-out/lib/libfastfec.dylib libfastfec-macos-x86_64-${{ inputs.version }}.dylib - - run: zig build -Dtarget=aarch64-macos - - run: zip -j fastfec-macos-aarch64-${{ inputs.version }}.zip zig-out/bin/fastfec - - run: mv zig-out/lib/libfastfec.dylib libfastfec-macos-aarch64-${{ inputs.version }}.dylib - # Windows - - run: zig build -Dtarget=x86_64-windows - - run: zip -j fastfec-windows-x86_64-${{ inputs.version }}.zip zig-out/bin/fastfec.exe - - run: mv zig-out/lib/fastfec.dll libfastfec-windows-x86_64-${{ inputs.version }}.dll - - run: zig build -Dtarget=aarch64-windows - - run: zip -j fastfec-windows-aarch64-${{ inputs.version }}.zip zig-out/bin/fastfec.exe - - run: mv zig-out/lib/fastfec.dll libfastfec-windows-aarch64-${{ inputs.version }}.dll + - name: Get output paths + uses: kanga333/variable-mapper@master + id: map + with: + key: "${{ matrix.os }}" + map: | + { + "linux": { + "libExt": "so", + "libName": "libfastfec", + "exeExt": "" + }, + "mac": { + "libExt": "dylib", + "libName": "libfastfec", + "exeExt": "" + }, + "windows": { + "libExt": "dll", + "libName": "fastfec", + "exeExt": ".exe" + }, + "wasm": { + "libExt": "wasm", + "libName": "fastfec", + "exeExt": "" + } + } + export_to: output + - name: Build target + if: matrix.os != 'wasm' + run: zig build -Dtarget=${{ matrix.architecture }}-${{ matrix.os }} + - name: Build target (wasm) + if: matrix.os == 'wasm' + run: zig build -Dwasm + - name: Zip output executable + if: matrix.os != 'wasm' + run: zip -j fastfec-${{ matrix.os }}-${{ matrix.architecture }}-${{ inputs.version }}.zip zig-out/bin/fastfec${{ steps.map.outputs.exeExt }} + - name: Move output library + if: matrix.os != 'wasm' + run: mv zig-out/lib/${{ steps.map.outputs.libName }}.${{ steps.map.outputs.libExt }} libfastfec-${{ matrix.os }}-${{ matrix.architecture }}-${{ inputs.version }}.${{ steps.map.outputs.libExt }} + - name: Move output library (wasm) + if: matrix.os == 'wasm' + run: mv zig-out/lib/${{ steps.map.outputs.libName }}.${{ steps.map.outputs.libExt }} libfastfec-${{ inputs.version }}.${{ steps.map.outputs.libExt }} + - name: Upload artifacts + uses: actions/upload-artifact@v2 + if: matrix.os != 'wasm' + with: + path: | + fastfec-${{ matrix.os }}-${{ matrix.architecture }}-${{ inputs.version }}.zip + libfastfec-${{ matrix.os }}-${{ matrix.architecture }}-${{ inputs.version }}.${{ steps.map.outputs.libExt }} + - name: Upload artifacts (wasm) + uses: actions/upload-artifact@v2 + if: matrix.os == 'wasm' + with: + path: | + libfastfec-${{ inputs.version }}.${{ steps.map.outputs.libExt }} + - name: GitHub release + uses: softprops/action-gh-release@v1 + if: inputs.uploadRelease && matrix.os != 'wasm' + with: + tag_name: ${{ inputs.version }} + files: | + fastfec-${{ matrix.os }}-${{ matrix.architecture }}-${{ inputs.version }}.zip + libfastfec-${{ matrix.os }}-${{ matrix.architecture }}-${{ inputs.version }}.${{ steps.map.outputs.libExt }} + - name: GitHub release (wasm) + uses: softprops/action-gh-release@v1 + if: inputs.uploadRelease && matrix.os == 'wasm' + with: + tag_name: ${{ inputs.version }} + files: | + libfastfec-${{ inputs.version }}.${{ steps.map.outputs.libExt }} diff --git a/.github/workflows/beta-release.yml b/.github/workflows/beta-release.yml index 034de91..ee727d2 100644 --- a/.github/workflows/beta-release.yml +++ b/.github/workflows/beta-release.yml @@ -8,48 +8,14 @@ on: - develop jobs: - build-for-beta-release: + build-and-upload-beta-release: uses: ./.github/workflows/_release.yml with: version: latest + uploadRelease: true - upload-beta-release: - needs: [build-for-beta-release] - runs-on: ubuntu-latest - steps: - - uses: softprops/action-gh-release@v1 - with: - tag_name: latest - files: | - fastfec-linux-x86_64-latest.zip - libfastfec-linux-x86_64-latest.so - fastfec-linux-aarch64-latest.zip - libfastfec-linux-aarch64-latest.so - fastfec-macos-x86_64-latest.zip - libfastfec-macos-x86_64-latest.dylib - fastfec-macos-aarch64-latest.zip - libfastfec-macos-aarch64-latest.dylib - fastfec-windows-x86_64-latest.zip - libfastfec-windows-x86_64-latest.dll - fastfec-windows-aarch64-latest.zip - libfastfec-windows-aarch64-latest.dll - libfastfec-latest.wasm - - build-wheels-for-beta-release: + build-and-upload-beta-wheels: uses: ./.github/workflows/_python-wheels.yml - - upload-wheels-for-beta-release: - needs: [build-wheels-for-beta-release] - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v2 - with: - name: artifact - path: dist - - - name: Publish package to Test PyPI - uses: pypa/gh-action-pypi-publish@v1.4.2 - with: - user: __token__ - password: ${{ secrets.test_pypi_token }} - repository_url: https://test.pypi.org/legacy/ + with: + publishToTestPyPI: true + secrets: inherit diff --git a/.github/workflows/pr-release.yml b/.github/workflows/pr-release.yml index dacaed2..049f66f 100644 --- a/.github/workflows/pr-release.yml +++ b/.github/workflows/pr-release.yml @@ -8,31 +8,10 @@ on: - develop jobs: - build-for-pr-release: + build-pr-release: uses: ./.github/workflows/_release.yml with: version: latest - upload-pr-release: - needs: [build-for-pr-release] - runs-on: ubuntu-latest - steps: - - uses: actions/upload-artifact@v2 - with: - path: | - fastfec-linux-x86_64-latest.zip - libfastfec-linux-x86_64-latest.so - fastfec-linux-aarch64-latest.zip - libfastfec-linux-aarch64-latest.so - fastfec-macos-x86_64-latest.zip - libfastfec-macos-x86_64-latest.dylib - fastfec-macos-aarch64-latest.zip - libfastfec-macos-aarch64-latest.dylib - fastfec-windows-x86_64-latest.zip - libfastfec-windows-x86_64-latest.dll - fastfec-windows-aarch64-latest.zip - libfastfec-windows-aarch64-latest.dll - libfastfec-latest.wasm - - build-wheels-for-pr-release: + build-pr-wheels: uses: ./.github/workflows/_python-wheels.yml diff --git a/.github/workflows/stable-release.yml b/.github/workflows/stable-release.yml index 7bc3e5c..b5d22ff 100644 --- a/.github/workflows/stable-release.yml +++ b/.github/workflows/stable-release.yml @@ -8,49 +8,16 @@ on: - "*.*.*" jobs: - build-for-stable-release: + build-and-upload-stable-release: if: github.event.base_ref == 'refs/heads/main' uses: ./.github/workflows/_release.yml with: version: ${{ github.ref_name }} + uploadRelease: true - upload-stable-release: - needs: [build-for-stable-release] - runs-on: ubuntu-latest - steps: - - uses: softprops/action-gh-release@v1 - with: - files: | - fastfec-linux-x86_64-${{ github.ref_name }}.zip - libfastfec-linux-x86_64-${{ github.ref_name }}.so - fastfec-linux-aarch64-${{ github.ref_name }}.zip - libfastfec-linux-aarch64-${{ github.ref_name }}.so - fastfec-macos-x86_64-${{ github.ref_name }}.zip - libfastfec-macos-x86_64-${{ github.ref_name }}.dylib - fastfec-macos-aarch64-${{ github.ref_name }}.zip - libfastfec-macos-aarch64-${{ github.ref_name }}.dylib - fastfec-windows-x86_64-${{ github.ref_name }}.zip - libfastfec-windows-x86_64-${{ github.ref_name }}.dll - fastfec-windows-aarch64-${{ github.ref_name }}.zip - libfastfec-windows-aarch64-${{ github.ref_name }}.dll - libfastfec-${{ github.ref_name }}.wasm - - build-wheels-for-stable-release: + build-and-upload-stable-wheels: if: github.event.base_ref == 'refs/heads/main' uses: ./.github/workflows/_python-wheels.yml - - upload-wheels-for-stable-release: - if: github.event.base_ref == 'refs/heads/main' - needs: [build-wheels-for-stable-release] - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v2 - with: - name: artifact - path: dist - - - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@v1.4.2 - with: - user: __token__ - password: ${{ secrets.pypi_token }} + with: + publishToPyPI: true + secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7edcba3..b551be9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,36 +1,34 @@ name: Test on: [push] jobs: - test: + test-c: runs-on: ubuntu-latest - timeout-minutes: 10 - strategy: - matrix: - python-version: [3.8] + timeout-minutes: 5 steps: - uses: actions/checkout@v2 - uses: goto-bus-stop/setup-zig@v1 with: version: 0.9.1 - - name: Install system dependencies - run: | - sudo apt-get update - sudo apt install -y libcurl4-openssl-dev + - name: Run zig test + run: zig build test + + test-python: + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + matrix: + python-version: [3.8] + steps: + - uses: actions/checkout@v2 - name: Setup Python uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Run zig build - run: zig build - - name: Run zig test - run: zig build test - name: Ensure mappings are up-to-date run: python scripts/generate_mappings.py test - name: Install Python dependencies working-directory: python - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt + run: pip install -r requirements-dev.txt - name: Run Python Tests working-directory: python run: tox -e py diff --git a/VERSION b/VERSION index 7693c96..a192233 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.3 \ No newline at end of file +0.1.6 \ No newline at end of file diff --git a/python/make_wheels.py b/python/make_wheels.py index ba7dc70..aeb93f7 100644 --- a/python/make_wheels.py +++ b/python/make_wheels.py @@ -31,6 +31,10 @@ ("Windows", "aarch64-windows", "win_arm64"), ] +if len(sys.argv) == 2: + # If an arg is passed, filter the matrix for only the specified target + matrix = [row for row in matrix if row[1] == sys.argv[1].strip()] + CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) PARENT_DIR = os.path.dirname(CURRENT_DIR) SRC_DIR = os.path.join(CURRENT_DIR, "src", "fastfec") @@ -120,10 +124,6 @@ def write_wheel(out_dir, *, name, version, tag, metadata, description, contents) current_platform = platform.system() for target_platform, zig_target, wheel_platform in matrix: - # Only run on compatible platforms - if current_platform != target_platform: - continue - # Compile the executable for the target platform contents = base_contents.copy() # First clear the target directory of any stray files @@ -138,7 +138,6 @@ def write_wheel(out_dir, *, name, version, tag, metadata, description, contents) "build", "-Dlib-only=true", f"-Dtarget={zig_target}", - *sys.argv[1:], ], cwd=PARENT_DIR, )