|
| 1 | +name: Release |
| 2 | +# Requires CARGO_REGISTRY_TOKEN with publish access to both crates. |
| 3 | +# Push v<crate version> to publish; manual runs only validate. |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tags: ['v*'] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: release-${{ github.ref }} |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + release: |
| 19 | + runs-on: ubuntu-22.04 |
| 20 | + timeout-minutes: 45 |
| 21 | + permissions: |
| 22 | + contents: write |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + submodules: recursive |
| 27 | + - uses: dtolnay/rust-toolchain@stable |
| 28 | + - uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: '3.12' |
| 31 | + - name: Validate release versions |
| 32 | + env: |
| 33 | + RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }} |
| 34 | + run: | |
| 35 | + python - <<'PY' |
| 36 | + import os, pathlib, re, tomllib |
| 37 | + crates = [tomllib.loads(pathlib.Path(f'crates/{name}/Cargo.toml').read_text()) for name in ('cnativeapi', 'nativeapi')] |
| 38 | + version = crates[0]['package']['version'] |
| 39 | + assert re.fullmatch(r'\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?', version), version |
| 40 | + assert crates[1]['package']['version'] == version, 'Crate versions must match' |
| 41 | + assert crates[1]['dependencies']['cnativeapi']['version'] == version, 'Update the cnativeapi dependency version' |
| 42 | + tag = os.environ['RELEASE_TAG'] |
| 43 | + assert not tag or tag == f'v{version}', 'Tag does not match crate versions' |
| 44 | + PY |
| 45 | + - name: Install native dependencies |
| 46 | + run: sudo apt-get update && sudo apt-get install -y cmake pkg-config libgtk-3-dev libx11-dev libxi-dev |
| 47 | + - uses: Swatinem/rust-cache@v2 |
| 48 | + - name: Test release sources |
| 49 | + run: cargo test --workspace --release --locked |
| 50 | + - name: Verify packaged native sources build outside the checkout |
| 51 | + run: cargo package -p cnativeapi --locked |
| 52 | + - name: Publish crates in dependency order |
| 53 | + if: github.event_name == 'push' && github.ref_type == 'tag' |
| 54 | + env: |
| 55 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 56 | + run: | |
| 57 | + test -n "$CARGO_REGISTRY_TOKEN" |
| 58 | + cargo publish -p cnativeapi --locked |
| 59 | + cargo publish -p nativeapi --locked |
| 60 | + - uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: crates |
| 63 | + path: target/package/*.crate |
| 64 | + if-no-files-found: error |
| 65 | + - name: Create GitHub Release |
| 66 | + if: github.event_name == 'push' && github.ref_type == 'tag' |
| 67 | + env: |
| 68 | + GH_TOKEN: ${{ github.token }} |
| 69 | + RELEASE_TAG: ${{ github.ref_name }} |
| 70 | + run: | |
| 71 | + args=() |
| 72 | + if [[ "$RELEASE_TAG" == *-* ]]; then args+=(--prerelease); fi |
| 73 | + gh release create "$RELEASE_TAG" target/package/*.crate --verify-tag --generate-notes "${args[@]}" |
0 commit comments