diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e94447d2..32c300b2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -66,25 +66,9 @@ jobs: echo "Stable release (manual retry): $VERSION" else IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" - BASE_PATCH=$((PATCH + 1)) + DEV_PATCH=$((PATCH + 1)) SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) - - # Query npm for the highest dev patch number published so far - LATEST_DEV=$(npm view "@optave/codegraph" versions --json 2>/dev/null \ - | node -e " - const versions = JSON.parse(require('fs').readFileSync(0,'utf8')); - const prefix = '${MAJOR}.${MINOR}.'; - let maxPatch = ${BASE_PATCH} - 1; - for (const v of (Array.isArray(versions) ? versions : [versions])) { - if (v.startsWith(prefix) && v.includes('-dev.')) { - const patch = parseInt(v.split('.')[2], 10); - if (patch > maxPatch) maxPatch = patch; - } - } - console.log(maxPatch + 1); - " 2>/dev/null) || LATEST_DEV="$BASE_PATCH" - - VERSION="${MAJOR}.${MINOR}.${LATEST_DEV}-dev.${SHORT_SHA}" + VERSION="${MAJOR}.${MINOR}.${DEV_PATCH}-dev.${SHORT_SHA}" NPM_TAG="dev" echo "Dev release: $VERSION" fi @@ -152,7 +136,158 @@ jobs: path: crates/codegraph-core/*.node if-no-files-found: error + # ── Dev builds: GitHub pre-release with tarballs ── + + publish-dev: + if: github.event_name == 'push' + needs: [compute-version, build-native] + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "22" + + - run: npm install + + - name: Set version + env: + VERSION: ${{ needs.compute-version.outputs.version }} + run: | + npm version "$VERSION" --no-git-tag-version --allow-same-version + node scripts/sync-native-versions.js + echo "Packaging version $VERSION" + + - name: Disable prepublishOnly + run: npm pkg delete scripts.prepublishOnly + + - name: Download native artifacts + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/artifacts/ + + - name: Pack main package + run: npm pack + + - name: Pack platform packages + env: + VERSION: ${{ needs.compute-version.outputs.version }} + shell: bash + run: | + declare -A PACKAGES=( + ["linux-x64"]="@optave/codegraph-linux-x64-gnu" + ["darwin-arm64"]="@optave/codegraph-darwin-arm64" + ["darwin-x64"]="@optave/codegraph-darwin-x64" + ["win32-x64"]="@optave/codegraph-win32-x64-msvc" + ) + + ARTIFACTS="${RUNNER_TEMP}/artifacts" + PKG_DIR="${RUNNER_TEMP}/pkg" + + for artifact_dir in "${ARTIFACTS}"/native-*/; do + platform=$(basename "$artifact_dir" | sed 's/^native-//') + pkg_name=${PACKAGES[$platform]} + node_os=${platform%%-*} + node_arch=${platform##*-} + + mkdir -p "${PKG_DIR}/$platform" + cp "$artifact_dir"/*.node "${PKG_DIR}/$platform/codegraph-core.node" + + cat > "${PKG_DIR}/$platform/package.json" <&1) || { + echo "::warning::Failed to list releases for pruning: ${TAGS}" + exit 0 + } + + OLD_TAGS=$(echo "$TAGS" | jq -r ' + [ .[] | select(.isPrerelease and (.tagName | startswith("dev-v"))) ] + | sort_by(.createdAt) | reverse + | .[5:] + | .[].tagName + ' 2>&1) || { + echo "::warning::Failed to parse release list for pruning: ${OLD_TAGS}" + exit 0 + } + + # When fewer than 5 dev releases exist, OLD_TAGS is empty and the loop is a no-op + echo "$OLD_TAGS" | while read -r tag; do + [ -z "$tag" ] && continue + echo "Deleting old dev release: $tag" + gh release delete "$tag" --yes --cleanup-tag || echo "::warning::Failed to delete release ${tag}" + done + + - name: Summary + env: + VERSION: ${{ needs.compute-version.outputs.version }} + run: | + TAG="dev-v${VERSION}" + cat >> "$GITHUB_STEP_SUMMARY" < generated/DEPENDENCIES.json 2>/dev/null || true - name: Push version bump via PR - if: github.event_name != 'push' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ needs.compute-version.outputs.version }} @@ -313,25 +442,3 @@ jobs: git tag -a "$TAG" -m "release: $TAG" git push origin "$TAG" fi - - # ── Dev-only: summary with install instructions ── - - - name: Summary - if: github.event_name == 'push' - env: - VERSION: ${{ needs.compute-version.outputs.version }} - run: | - cat >> "$GITHUB_STEP_SUMMARY" <