chore: release v2.0.0-beta.59 #44
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| permissions: | |
| contents: write | |
| id-token: write | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| # Check if native binaries are cached, build only if needed | |
| prepare-native: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| native-hash: ${{ steps.hash.outputs.hash }} | |
| cache-hit: ${{ steps.cache-check.outputs.cache-hit }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Calculate native source hash | |
| id: hash | |
| run: | | |
| HASH=$(find native/src native/Cargo.toml native/Cargo.lock native/build.rs -type f -exec sha256sum {} \; 2>/dev/null | sort | sha256sum | cut -d' ' -f1) | |
| echo "hash=$HASH" >> $GITHUB_OUTPUT | |
| echo "Native source hash: $HASH" | |
| - name: Check cache for pre-built binaries | |
| id: cache-check | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: native-binaries-flat | |
| key: native-${{ steps.hash.outputs.hash }} | |
| lookup-only: true | |
| # Build native modules only if not cached | |
| build-native: | |
| needs: prepare-native | |
| if: needs.prepare-native.outputs.cache-hit != 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: pnpm/action-setup@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| cache: pnpm | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools (Linux ARM64) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| - run: pnpm install | |
| - name: Build native module | |
| run: | | |
| cd native | |
| pnpm napi build --platform --release --target ${{ matrix.target }} | |
| env: | |
| CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bindings-${{ matrix.target }} | |
| path: native/*.node | |
| if-no-files-found: error | |
| # Collect freshly built binaries and cache them | |
| cache-new-binaries: | |
| needs: [prepare-native, build-native] | |
| if: needs.prepare-native.outputs.cache-hit != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: native-binaries | |
| - name: Flatten directory structure | |
| run: | | |
| mkdir -p native-binaries-flat | |
| find native-binaries -name "*.node" -exec cp {} native-binaries-flat/ \; | |
| ls -la native-binaries-flat/ | |
| - name: Cache native binaries for future releases | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: native-binaries-flat | |
| key: native-${{ needs.prepare-native.outputs.native-hash }} | |
| # Publish platform-specific npm packages (only if native code changed) | |
| publish-native: | |
| needs: [prepare-native, build-native, cache-new-binaries] | |
| # Only run if native code changed (cache miss means we built new binaries) | |
| if: always() && !failure() && !cancelled() && needs.prepare-native.outputs.cache-hit != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: pnpm/action-setup@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: pnpm | |
| - run: pnpm install | |
| # Try to restore from cache first | |
| - name: Restore cached binaries | |
| id: cache-restore | |
| if: needs.prepare-native.outputs.cache-hit == 'true' | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: native-binaries-flat | |
| key: native-${{ needs.prepare-native.outputs.native-hash }} | |
| - name: Copy cached binaries to native/ | |
| if: steps.cache-restore.outputs.cache-hit == 'true' | |
| run: | | |
| cp native-binaries-flat/*.node native/ | |
| ls -la native/*.node | |
| # Or download freshly built artifacts | |
| - name: Download build artifacts | |
| if: needs.prepare-native.outputs.cache-hit != 'true' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: native/artifacts | |
| - name: Move artifacts to native/ | |
| if: needs.prepare-native.outputs.cache-hit != 'true' | |
| run: | | |
| cd native | |
| for dir in artifacts/bindings-*; do | |
| cp "$dir"/*.node . 2>/dev/null || true | |
| done | |
| ls -la *.node | |
| - name: Update native package version | |
| run: | | |
| VERSION="${{ github.ref_name }}" | |
| VERSION="${VERSION#v}" | |
| cd native | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.version = '$VERSION'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Create npm packages | |
| run: | | |
| cd native | |
| pnpm napi create-npm-dirs | |
| ls -la npm/ | |
| - name: Copy binaries to npm packages | |
| run: | | |
| cd native | |
| for node_file in *.node; do | |
| platform=$(echo "$node_file" | sed 's/graphql-lint\.//' | sed 's/\.node//') | |
| target_dir="npm/$platform" | |
| if [ -d "$target_dir" ]; then | |
| cp "$node_file" "$target_dir/" | |
| echo "Copied $node_file to $target_dir/" | |
| else | |
| echo "Warning: $target_dir not found for $node_file" | |
| fi | |
| done | |
| - name: Add repository to platform packages | |
| run: | | |
| cd native | |
| for pkg in npm/*/package.json; do | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('$pkg', 'utf8')); | |
| pkg.repository = { | |
| type: 'git', | |
| url: 'https://github.com/productdevbook/nitro-graphql' | |
| }; | |
| fs.writeFileSync('$pkg', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| done | |
| - name: Determine npm tag | |
| id: npm-tag | |
| run: | | |
| if [[ "${{ github.ref_name }}" == *"-beta"* ]] || [[ "${{ github.ref_name }}" == *"-rc"* ]] || [[ "${{ github.ref_name }}" == *"-alpha"* ]]; then | |
| echo "tag=beta" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish platform packages | |
| run: | | |
| cd native | |
| for pkg in npm/*/; do | |
| if [ -f "$pkg/package.json" ]; then | |
| echo "Publishing $pkg" | |
| cd "$pkg" | |
| pnpm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} --no-git-checks || true | |
| cd ../.. | |
| fi | |
| done | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # Publish main package | |
| release: | |
| needs: [prepare-native, publish-native] | |
| # Always run (publish-native might be skipped if native code unchanged) | |
| if: always() && !failure() && !cancelled() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: pnpm | |
| - run: pnpm install | |
| - name: Determine native package version | |
| id: native-version | |
| run: | | |
| RELEASE_VERSION="${{ github.ref_name }}" | |
| RELEASE_VERSION="${RELEASE_VERSION#v}" | |
| # Determine npm tag based on release version | |
| if [[ "$RELEASE_VERSION" == *"-beta"* ]] || [[ "$RELEASE_VERSION" == *"-rc"* ]] || [[ "$RELEASE_VERSION" == *"-alpha"* ]]; then | |
| NPM_TAG="beta" | |
| else | |
| NPM_TAG="latest" | |
| fi | |
| # If native code changed, use current release version | |
| # If not changed, get published version from appropriate npm tag | |
| if [ "${{ needs.prepare-native.outputs.cache-hit }}" == "true" ]; then | |
| echo "Native code unchanged, fetching published version from @${NPM_TAG} tag..." | |
| NATIVE_VERSION=$(npm view nitro-graphql-linux-x64-gnu@${NPM_TAG} version 2>/dev/null || echo "$RELEASE_VERSION") | |
| echo "Using existing native version: $NATIVE_VERSION" | |
| else | |
| echo "Native code changed, using release version: $RELEASE_VERSION" | |
| NATIVE_VERSION="$RELEASE_VERSION" | |
| fi | |
| echo "version=$NATIVE_VERSION" >> $GITHUB_OUTPUT | |
| - name: Add native package dependencies | |
| run: | | |
| NATIVE_VERSION="${{ steps.native-version.outputs.version }}" | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.optionalDependencies = { | |
| 'nitro-graphql-darwin-arm64': '$NATIVE_VERSION', | |
| 'nitro-graphql-darwin-x64': '$NATIVE_VERSION', | |
| 'nitro-graphql-linux-x64-gnu': '$NATIVE_VERSION', | |
| 'nitro-graphql-linux-arm64-gnu': '$NATIVE_VERSION', | |
| 'nitro-graphql-win32-x64-msvc': '$NATIVE_VERSION' | |
| }; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| echo "optionalDependencies set to version: $NATIVE_VERSION" | |
| cat package.json | grep -A 6 optionalDependencies | |
| - run: pnpm tsdown | |
| - name: Determine npm tag | |
| id: npm-tag | |
| run: | | |
| if [[ "${{ github.ref_name }}" == *"-beta"* ]] || [[ "${{ github.ref_name }}" == *"-rc"* ]] || [[ "${{ github.ref_name }}" == *"-alpha"* ]]; then | |
| echo "tag=beta" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to npm | |
| run: pnpm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Get previous tag | |
| id: prev-tag | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| run: | | |
| if [ -n "${{ steps.prev-tag.outputs.tag }}" ]; then | |
| pnpm dlx changelogithub --from ${{ steps.prev-tag.outputs.tag }} | |
| else | |
| pnpm dlx changelogithub | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| run: | | |
| echo "## Release Complete 🚀" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Native Version:** ${{ steps.native-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.prepare-native.outputs.cache-hit }}" == "true" ]; then | |
| echo "**Native Build:** ⏭️ Skipped (unchanged, using cached)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "**Native Build:** ✅ Built & Published" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "**Cache Key:** \`native-${{ needs.prepare-native.outputs.native-hash }}\`" >> $GITHUB_STEP_SUMMARY |