|
| 1 | +name: Release |
| 2 | +run-name: Release ${{ github.ref_name }} |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: release |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + CARGO_TERM_COLOR: always |
| 18 | + |
| 19 | +jobs: |
| 20 | + # ── Validate tag ───────────────────────────────────────────────────────────── |
| 21 | + validate-version: |
| 22 | + name: Validate Version Tag |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + version: ${{ steps.version.outputs.version }} |
| 26 | + is_full_release: ${{ steps.version.outputs.is_full_release }} |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v6 |
| 29 | + |
| 30 | + - name: Install Rust |
| 31 | + uses: dtolnay/rust-toolchain@stable |
| 32 | + |
| 33 | + - name: Validate tag against Cargo.toml |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + TAG="${GITHUB_REF_NAME}" |
| 37 | + TAG_VERSION="${TAG#v}" |
| 38 | +
|
| 39 | + CARGO_VERSION=$(cargo metadata --no-deps --format-version=1 \ |
| 40 | + | jq -r '.packages[] | select(.name == "nodedb-lite") | .version') |
| 41 | + CARGO_BASE=$(echo "$CARGO_VERSION" | grep -oP '^\d+\.\d+\.\d+') |
| 42 | +
|
| 43 | + echo "Tag version: $TAG_VERSION" |
| 44 | + echo "Cargo.toml version: $CARGO_VERSION" |
| 45 | + echo "Cargo.toml base: $CARGO_BASE" |
| 46 | +
|
| 47 | + if [[ ! "$TAG_VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)(-[a-zA-Z]+\.[0-9]+)?$ ]]; then |
| 48 | + echo "::error::Invalid tag format '$TAG'. Expected: vX.Y.Z or vX.Y.Z-label.N" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + TAG_BASE="${BASH_REMATCH[1]}" |
| 53 | +
|
| 54 | + if [[ "$TAG_BASE" != "$CARGO_BASE" ]]; then |
| 55 | + echo "::error::Base version mismatch! Tag '$TAG_BASE' != Cargo.toml '$CARGO_BASE'" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + # Full release = no hyphen suffix (v0.1.0, not v0.1.0-beta.1) |
| 60 | + if [[ "$TAG_VERSION" == *-* ]]; then |
| 61 | + echo "is_full_release=false" >> "$GITHUB_OUTPUT" |
| 62 | + else |
| 63 | + echo "is_full_release=true" >> "$GITHUB_OUTPUT" |
| 64 | + fi |
| 65 | +
|
| 66 | + echo "version=$TAG_VERSION" >> "$GITHUB_OUTPUT" |
| 67 | +
|
| 68 | + # ── CI gate ────────────────────────────────────────────────────────────────── |
| 69 | + ci: |
| 70 | + name: CI Gate |
| 71 | + needs: validate-version |
| 72 | + uses: ./.github/workflows/ci.yml |
| 73 | + |
| 74 | + # ── WASM gate ──────────────────────────────────────────────────────────────── |
| 75 | + wasm: |
| 76 | + name: WASM Gate |
| 77 | + needs: validate-version |
| 78 | + uses: ./.github/workflows/wasm.yml |
| 79 | + |
| 80 | + # ── Publish crates to crates.io ────────────────────────────────────────────── |
| 81 | + # Requires secret: CARGO_REGISTRY_TOKEN |
| 82 | + # Tier 1: nodedb-lite (no internal Lite deps). |
| 83 | + # Tier 2: nodedb-lite-ffi, nodedb-lite-wasm (both depend on nodedb-lite). |
| 84 | + # is_published / wait_for polling mirrors the nodedb workspace pattern so |
| 85 | + # a re-run after a failed publish never double-publishes an already-indexed |
| 86 | + # crate. |
| 87 | + publish-crates: |
| 88 | + name: Publish to crates.io |
| 89 | + needs: [validate-version, ci, wasm] |
| 90 | + runs-on: ubuntu-latest |
| 91 | + environment: crates.io |
| 92 | + permissions: |
| 93 | + contents: read |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v6 |
| 96 | + |
| 97 | + - name: Install Rust |
| 98 | + uses: dtolnay/rust-toolchain@stable |
| 99 | + |
| 100 | + - name: Install system deps |
| 101 | + run: | |
| 102 | + sudo apt-get update |
| 103 | + sudo apt-get install -y --no-install-recommends \ |
| 104 | + cmake clang libclang-dev pkg-config protobuf-compiler perl |
| 105 | +
|
| 106 | + - name: Set version from tag |
| 107 | + run: | |
| 108 | + VERSION="${{ needs.validate-version.outputs.version }}" |
| 109 | + CURRENT=$(cargo metadata --no-deps --format-version=1 \ |
| 110 | + | jq -r '.packages[] | select(.name == "nodedb-lite") | .version') |
| 111 | + if [[ "$VERSION" != "$CURRENT" ]]; then |
| 112 | + sed -i "0,/^version = \".*\"/s//version = \"$VERSION\"/" Cargo.toml |
| 113 | +
|
| 114 | + # For pre-release versions, pin internal dep requirements so |
| 115 | + # semver "0.1.0" doesn't fail to match "0.1.0-beta.1". |
| 116 | + if [[ "$VERSION" == *-* ]]; then |
| 117 | + sed -i -E 's/(nodedb-lite = \{ [^}]*version = )"[^"]*"/\1"='"$VERSION"'"/' Cargo.toml |
| 118 | + echo "Updated internal dep versions to =$VERSION" |
| 119 | + fi |
| 120 | +
|
| 121 | + echo "Updated workspace version: $CURRENT -> $VERSION" |
| 122 | + else |
| 123 | + echo "Version already matches, no change needed" |
| 124 | + fi |
| 125 | +
|
| 126 | + - name: Publish crates |
| 127 | + env: |
| 128 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 129 | + run: | |
| 130 | + TIER1="nodedb-lite" |
| 131 | + TIER2="nodedb-lite-ffi nodedb-lite-wasm" |
| 132 | +
|
| 133 | + is_published() { |
| 134 | + curl -sf \ |
| 135 | + -H "User-Agent: nodedb-lite-ci (github.com/NodeDB-Lab/nodedb-lite)" \ |
| 136 | + "https://crates.io/api/v1/crates/$1/$2" > /dev/null 2>&1 |
| 137 | + } |
| 138 | +
|
| 139 | + wait_for() { |
| 140 | + local crate="$1" version="$2" |
| 141 | + echo -n " Waiting for $crate@$version..." |
| 142 | + for i in $(seq 1 30); do |
| 143 | + if is_published "$crate" "$version"; then |
| 144 | + echo " ready" |
| 145 | + return 0 |
| 146 | + fi |
| 147 | + sleep 5 |
| 148 | + done |
| 149 | + echo " timed out!" |
| 150 | + return 1 |
| 151 | + } |
| 152 | +
|
| 153 | + publish_tier() { |
| 154 | + local tier_name="$1"; shift |
| 155 | + local crates=("$@") |
| 156 | + local need_wait=() |
| 157 | +
|
| 158 | + echo "::group::Tier: $tier_name" |
| 159 | + for crate in "${crates[@]}"; do |
| 160 | + VERSION=$(cargo metadata --no-deps --format-version=1 \ |
| 161 | + | jq -r --arg name "$crate" '.packages[] | select(.name == $name) | .version') |
| 162 | + if is_published "$crate" "$VERSION"; then |
| 163 | + echo " $crate@$VERSION already published — skipping" |
| 164 | + else |
| 165 | + echo " Publishing $crate@$VERSION..." |
| 166 | + cargo publish -p "$crate" --allow-dirty --no-verify |
| 167 | + need_wait+=("$crate:$VERSION") |
| 168 | + fi |
| 169 | + done |
| 170 | +
|
| 171 | + for entry in "${need_wait[@]}"; do |
| 172 | + wait_for "${entry%%:*}" "${entry##*:}" |
| 173 | + done |
| 174 | + echo "::endgroup::" |
| 175 | + } |
| 176 | +
|
| 177 | + publish_tier "1 (no internal Lite deps)" $TIER1 |
| 178 | + publish_tier "2 (depends on nodedb-lite)" $TIER2 |
| 179 | +
|
| 180 | + # ── Publish npm package ────────────────────────────────────────────────────── |
| 181 | + # Requires secret: NPM_TOKEN |
| 182 | + publish-npm: |
| 183 | + name: Publish to npm |
| 184 | + needs: [validate-version, ci, wasm, publish-crates] |
| 185 | + runs-on: ubuntu-latest |
| 186 | + environment: npm |
| 187 | + permissions: |
| 188 | + contents: read |
| 189 | + steps: |
| 190 | + - uses: actions/checkout@v6 |
| 191 | + |
| 192 | + - name: Install Rust |
| 193 | + uses: dtolnay/rust-toolchain@stable |
| 194 | + with: |
| 195 | + targets: wasm32-unknown-unknown |
| 196 | + |
| 197 | + - name: Install wasm-pack |
| 198 | + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh |
| 199 | + |
| 200 | + - uses: actions/setup-node@v4 |
| 201 | + with: |
| 202 | + node-version: 20 |
| 203 | + registry-url: https://registry.npmjs.org |
| 204 | + |
| 205 | + - name: Build WASM release |
| 206 | + run: wasm-pack build --target web --release nodedb-lite-wasm |
| 207 | + |
| 208 | + - name: Rewrite pkg/package.json metadata |
| 209 | + working-directory: nodedb-lite-wasm/pkg |
| 210 | + run: | |
| 211 | + node -e " |
| 212 | + const fs = require('fs'); |
| 213 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); |
| 214 | + pkg.name = '@nodedb/lite'; |
| 215 | + pkg.version = '${{ needs.validate-version.outputs.version }}'; |
| 216 | + pkg.license = 'Apache-2.0'; |
| 217 | + pkg.repository = { type: 'git', url: 'https://github.com/NodeDB-Lab/nodedb-lite' }; |
| 218 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); |
| 219 | + " |
| 220 | +
|
| 221 | + - name: Publish to npm |
| 222 | + working-directory: nodedb-lite-wasm/pkg |
| 223 | + env: |
| 224 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 225 | + run: | |
| 226 | + if [[ "${{ needs.validate-version.outputs.is_full_release }}" == "true" ]]; then |
| 227 | + npm publish --access public |
| 228 | + else |
| 229 | + npm publish --access public --tag beta |
| 230 | + fi |
| 231 | +
|
| 232 | + # ── Create GitHub Release ───────────────────────────────────────────────────── |
| 233 | + github-release: |
| 234 | + name: Create GitHub Release |
| 235 | + needs: [validate-version, publish-crates, publish-npm] |
| 236 | + runs-on: ubuntu-latest |
| 237 | + permissions: |
| 238 | + contents: write |
| 239 | + steps: |
| 240 | + - uses: actions/checkout@v6 |
| 241 | + |
| 242 | + - name: Create GitHub Release |
| 243 | + uses: softprops/action-gh-release@v2 |
| 244 | + with: |
| 245 | + tag_name: v${{ needs.validate-version.outputs.version }} |
| 246 | + name: NodeDB Lite ${{ needs.validate-version.outputs.version }} |
| 247 | + generate_release_notes: true |
| 248 | + draft: false |
| 249 | + prerelease: ${{ contains(needs.validate-version.outputs.version, '-') }} |
0 commit comments