|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + # Trigger from rgb-lib repository |
| 5 | + repository_dispatch: |
| 6 | + types: [rgb-lib-release] |
| 7 | + |
| 8 | + # Manual trigger |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + rgb_lib_version: |
| 12 | + description: 'rgb-lib version to use (e.g., v0.3.0-beta.8)' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build (${{ matrix.platform }}) |
| 19 | + runs-on: ${{ matrix.runner }} |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + # Linux x64 |
| 25 | + - runner: ubuntu-latest |
| 26 | + platform: linux-x86_64 |
| 27 | + target: x86_64-unknown-linux-gnu |
| 28 | + # Linux ARM64 |
| 29 | + - runner: ubuntu-24.04-arm |
| 30 | + platform: linux-aarch64 |
| 31 | + target: aarch64-unknown-linux-gnu |
| 32 | + # macOS ARM64 (Apple Silicon) |
| 33 | + - runner: macos-latest |
| 34 | + platform: macosx-arm64 |
| 35 | + target: aarch64-apple-darwin |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout repository |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + submodules: recursive |
| 42 | + |
| 43 | + - name: Get rgb-lib version |
| 44 | + id: rgb_lib_version |
| 45 | + run: | |
| 46 | + if [ "${{ github.event_name }}" == "repository_dispatch" ]; then |
| 47 | + echo "version=${{ github.event.client_payload.version }}" >> $GITHUB_OUTPUT |
| 48 | + elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 49 | + echo "version=${{ inputs.rgb_lib_version }}" >> $GITHUB_OUTPUT |
| 50 | + fi |
| 51 | + shell: bash |
| 52 | + |
| 53 | + - name: Setup Python |
| 54 | + uses: actions/setup-python@v5 |
| 55 | + with: |
| 56 | + python-version: '3.11' |
| 57 | + |
| 58 | + - name: Setup Rust |
| 59 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 60 | + with: |
| 61 | + toolchain: stable |
| 62 | + target: ${{ matrix.target }} |
| 63 | + |
| 64 | + - name: Install Docker (Linux ARM64) |
| 65 | + if: matrix.platform == 'linux-aarch64' |
| 66 | + run: | |
| 67 | + sudo apt-get update |
| 68 | + sudo apt-get install -y docker.io |
| 69 | + sudo systemctl start docker |
| 70 | +
|
| 71 | + - name: Update rgb-lib submodule to target version |
| 72 | + run: | |
| 73 | + cd rgb-lib |
| 74 | + git fetch --all --tags |
| 75 | + git checkout ${{ steps.rgb_lib_version.outputs.version }} |
| 76 | + echo "Checked out rgb-lib version:" |
| 77 | + git log --oneline -1 |
| 78 | + cd .. |
| 79 | + shell: bash |
| 80 | + |
| 81 | + - name: Get version for Python package |
| 82 | + id: pyversion |
| 83 | + run: | |
| 84 | + VERSION="${{ steps.rgb_lib_version.outputs.version }}" |
| 85 | + # Remove 'v' prefix and convert to PEP 440 format |
| 86 | + # v0.3.0-beta.8 -> 0.3.0b8 |
| 87 | + PY_VERSION=$(echo "$VERSION" | sed 's/^v//' | sed 's/-beta\./b/' | sed 's/-alpha\./a/' | sed 's/-rc\./rc/') |
| 88 | + echo "version=$PY_VERSION" >> $GITHUB_OUTPUT |
| 89 | + echo "Python version: $PY_VERSION" |
| 90 | +
|
| 91 | + - name: Update version in pyproject.toml |
| 92 | + run: | |
| 93 | + VERSION="${{ steps.pyversion.outputs.version }}" |
| 94 | + sed -i.bak "s/^version = .*/version = \"$VERSION\"/" pyproject.toml |
| 95 | + cat pyproject.toml | grep "^version" |
| 96 | +
|
| 97 | + - name: Install Python dependencies |
| 98 | + run: | |
| 99 | + python -m pip install --upgrade pip |
| 100 | + pip install poetry build wheel |
| 101 | +
|
| 102 | + - name: Build wheel |
| 103 | + run: | |
| 104 | + export PLATFORM="${{ matrix.platform }}" |
| 105 | + python -m build --wheel |
| 106 | + env: |
| 107 | + PLATFORM: ${{ matrix.platform }} |
| 108 | + |
| 109 | + - name: List built wheels |
| 110 | + run: ls -la dist/ |
| 111 | + |
| 112 | + - name: Upload wheel artifact |
| 113 | + uses: actions/upload-artifact@v4 |
| 114 | + with: |
| 115 | + name: wheel-${{ matrix.platform }} |
| 116 | + path: dist/*.whl |
| 117 | + retention-days: 5 |
| 118 | + |
| 119 | + publish: |
| 120 | + name: Publish to PyPI |
| 121 | + needs: build |
| 122 | + if: always() && !cancelled() |
| 123 | + runs-on: ubuntu-latest |
| 124 | + |
| 125 | + steps: |
| 126 | + - name: Download all wheel artifacts |
| 127 | + uses: actions/download-artifact@v4 |
| 128 | + with: |
| 129 | + path: wheels |
| 130 | + pattern: wheel-* |
| 131 | + merge-multiple: true |
| 132 | + |
| 133 | + - name: List wheels |
| 134 | + run: ls -la wheels/ |
| 135 | + |
| 136 | + - name: Setup Python |
| 137 | + uses: actions/setup-python@v5 |
| 138 | + with: |
| 139 | + python-version: '3.11' |
| 140 | + |
| 141 | + - name: Install twine |
| 142 | + run: pip install twine |
| 143 | + |
| 144 | + - name: Publish to PyPI |
| 145 | + run: | |
| 146 | + twine upload wheels/*.whl --skip-existing || echo "Some packages may already exist, continuing..." |
| 147 | + env: |
| 148 | + TWINE_USERNAME: __token__ |
| 149 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 150 | + |
| 151 | + release: |
| 152 | + name: Create GitHub Release |
| 153 | + needs: [build, publish] |
| 154 | + if: always() && !cancelled() |
| 155 | + runs-on: ubuntu-latest |
| 156 | + permissions: |
| 157 | + contents: write |
| 158 | + |
| 159 | + steps: |
| 160 | + - name: Checkout repository |
| 161 | + uses: actions/checkout@v4 |
| 162 | + |
| 163 | + - name: Get version info |
| 164 | + id: version |
| 165 | + run: | |
| 166 | + if [ "${{ github.event_name }}" == "repository_dispatch" ]; then |
| 167 | + VERSION="${{ github.event.client_payload.version }}" |
| 168 | + else |
| 169 | + VERSION="${{ inputs.rgb_lib_version }}" |
| 170 | + fi |
| 171 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 172 | +
|
| 173 | + - name: Download all wheel artifacts |
| 174 | + uses: actions/download-artifact@v4 |
| 175 | + with: |
| 176 | + path: wheels |
| 177 | + pattern: wheel-* |
| 178 | + merge-multiple: true |
| 179 | + |
| 180 | + - name: Create Release |
| 181 | + uses: softprops/action-gh-release@v2 |
| 182 | + with: |
| 183 | + tag_name: ${{ steps.version.outputs.version }} |
| 184 | + name: Release ${{ steps.version.outputs.version }} |
| 185 | + body: | |
| 186 | + ## Python bindings for rgb-lib |
| 187 | + |
| 188 | + Based on rgb-lib ${{ steps.version.outputs.version }} |
| 189 | + |
| 190 | + ### Installation via pip (recommended) |
| 191 | + |
| 192 | + ```bash |
| 193 | + pip install rgb-lib |
| 194 | + ``` |
| 195 | + |
| 196 | + ### Platforms |
| 197 | + |
| 198 | + | Platform | Wheel | |
| 199 | + |----------|-------| |
| 200 | + | Linux x64 | `manylinux_2_34_x86_64` | |
| 201 | + | Linux ARM64 | `manylinux_2_34_aarch64` | |
| 202 | + | macOS ARM64 (Apple Silicon) | `macosx_12_0_arm64` | |
| 203 | + |
| 204 | + ### Changes |
| 205 | + |
| 206 | + See [rgb-lib release notes](https://github.com/UTEXO-Protocol/rgb-lib/releases/tag/${{ steps.version.outputs.version }}) |
| 207 | + draft: false |
| 208 | + prerelease: ${{ contains(steps.version.outputs.version, 'alpha') || contains(steps.version.outputs.version, 'beta') || contains(steps.version.outputs.version, 'rc') }} |
| 209 | + files: wheels/*.whl |
| 210 | + env: |
| 211 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 212 | + |
0 commit comments