|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + draft: |
| 7 | + description: 'Create GitHub Release as draft' |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + linux: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + target: [x86_64, aarch64] |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: 3.x |
| 26 | + - name: Build wheels |
| 27 | + uses: PyO3/maturin-action@v1 |
| 28 | + with: |
| 29 | + target: ${{ matrix.target }} |
| 30 | + args: --release --out dist |
| 31 | + manylinux: auto |
| 32 | + - uses: actions/upload-artifact@v4 |
| 33 | + with: |
| 34 | + name: wheels-linux-${{ matrix.target }} |
| 35 | + path: dist |
| 36 | + |
| 37 | + windows: |
| 38 | + runs-on: windows-latest |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + - uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: 3.x |
| 44 | + - name: Build wheels |
| 45 | + uses: PyO3/maturin-action@v1 |
| 46 | + with: |
| 47 | + target: x64 |
| 48 | + args: --release --out dist |
| 49 | + - uses: actions/upload-artifact@v4 |
| 50 | + with: |
| 51 | + name: wheels-windows-x64 |
| 52 | + path: dist |
| 53 | + |
| 54 | + macos: |
| 55 | + runs-on: macos-latest |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + - uses: actions/setup-python@v5 |
| 59 | + with: |
| 60 | + python-version: 3.x |
| 61 | + - name: Build wheels |
| 62 | + uses: PyO3/maturin-action@v1 |
| 63 | + with: |
| 64 | + target: aarch64 |
| 65 | + args: --release --out dist |
| 66 | + - uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: wheels-macos-aarch64 |
| 69 | + path: dist |
| 70 | + |
| 71 | + sdist: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + - name: Build sdist |
| 76 | + uses: PyO3/maturin-action@v1 |
| 77 | + with: |
| 78 | + command: sdist |
| 79 | + args: --out dist |
| 80 | + - uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: wheels-sdist |
| 83 | + path: dist |
| 84 | + |
| 85 | + publish-pypi: |
| 86 | + runs-on: ubuntu-latest |
| 87 | + needs: [linux, windows, macos, sdist] |
| 88 | + environment: |
| 89 | + name: pypi |
| 90 | + url: https://pypi.org/p/cflib2 |
| 91 | + permissions: |
| 92 | + id-token: write |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v4 |
| 95 | + with: |
| 96 | + fetch-depth: 0 |
| 97 | + |
| 98 | + - name: Verify commit is on main |
| 99 | + run: | |
| 100 | + git fetch origin main |
| 101 | + if ! git merge-base --is-ancestor HEAD origin/main; then |
| 102 | + echo "This workflow can only be run on a commit that is on the main branch." |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: Check version consistency between git tag and Cargo.toml |
| 107 | + run: | |
| 108 | + TAG_VERSION=$(git describe --tags --exact-match HEAD) |
| 109 | + CARGO_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version') |
| 110 | + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then |
| 111 | + echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)" |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | +
|
| 115 | + - uses: actions/download-artifact@v4 |
| 116 | + |
| 117 | + - name: Publish to PyPI |
| 118 | + uses: PyO3/maturin-action@v1 |
| 119 | + with: |
| 120 | + command: upload |
| 121 | + args: --non-interactive --skip-existing wheels-*/* |
| 122 | + |
| 123 | + github-release: |
| 124 | + runs-on: ubuntu-latest |
| 125 | + needs: publish-pypi |
| 126 | + permissions: |
| 127 | + contents: write |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v4 |
| 130 | + with: |
| 131 | + fetch-depth: 0 |
| 132 | + |
| 133 | + - uses: actions/download-artifact@v4 |
| 134 | + |
| 135 | + - name: Create GitHub Release |
| 136 | + uses: softprops/action-gh-release@v2 |
| 137 | + with: |
| 138 | + tag_name: ${{ github.ref_name }} |
| 139 | + draft: ${{ github.event.inputs.draft }} |
| 140 | + files: wheels-*/* |
0 commit comments