Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 67 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Publish

on:
push:
branches: [main]
# Dev builds run on a schedule rather than on every push to main — a native
# build+release across 6 platforms is expensive to run 1:1 with merge
# frequency. See check-dev-needed below for the no-new-commits skip.
schedule:
- cron: '0 5 * * *' # daily dev build, 5am UTC
release:
types: [published]
workflow_dispatch:
Expand All @@ -19,11 +22,68 @@ concurrency:
permissions: {}

jobs:
check-dev-needed:
name: Check whether a dev build is needed
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
# Only the scheduled path below actually reads repo history (git rev-list);
# release/workflow_dispatch exit immediately with should_run=true and never
# touch the checkout, so skip the full-depth clone for those triggers.
- uses: actions/checkout@v7
if: github.event_name == 'schedule'
with:
fetch-depth: 0
Comment on lines +36 to +39

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unconditional full-history checkout for non-schedule events

actions/checkout@v7 with fetch-depth: 0 runs for every trigger (release, workflow_dispatch), even though the subsequent step immediately exits with should_run=true for those events without using the repo contents. For a stable-release run this means a full-depth clone for zero benefit. Consider wrapping the checkout in a step-level if: github.event_name == 'schedule' condition, or restructuring so non-schedule events bypass the job entirely.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — added if: github.event_name == 'schedule' to the checkout step so the full-depth clone only runs for the scheduled path that actually needs git history; release/workflow_dispatch now skip the checkout entirely and exit should_run=true without touching repo contents.


- name: Determine whether to proceed
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" != "schedule" ]; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
exit 0
fi

# Scheduled dev build: skip if main hasn't moved since the last one
# (e.g. a quiet weekend), so we don't rebuild identical content.
LATEST_TAG=$(gh release list --limit 20 --json tagName,isPrerelease,publishedAt \
| jq -r '[.[] | select(.isPrerelease and (.tagName | startswith("dev-v")))] | sort_by(.publishedAt) | reverse | .[0].tagName // empty')
if [ -z "$LATEST_TAG" ]; then
echo "No previous dev release found — proceeding"
echo "should_run=true" >> "$GITHUB_OUTPUT"
exit 0
fi

# Anchor the extraction to the "commit <sha>" phrasing from the
# publish-dev release notes template (see "Create GitHub pre-release"
# below) rather than grabbing the first bare 40-char hex string in the
# body, which could match unrelated content in future release notes.
COMMIT_SHA=$(gh release view "$LATEST_TAG" --json body -q .body \
| grep -oE 'commit[^0-9a-f]*[0-9a-f]{40}' | grep -oE '[0-9a-f]{40}$' | head -1)
if [ -z "$COMMIT_SHA" ]; then
echo "Could not parse commit SHA from ${LATEST_TAG} notes — proceeding to be safe"
echo "should_run=true" >> "$GITHUB_OUTPUT"
exit 0
fi

NEW_COMMITS=$(git rev-list "${COMMIT_SHA}..HEAD" --count 2>/dev/null || echo 1)
if [ "$NEW_COMMITS" -eq 0 ]; then
echo "No new commits since ${LATEST_TAG} (${COMMIT_SHA}) — skipping scheduled dev build"
echo "should_run=false" >> "$GITHUB_OUTPUT"
else
echo "${NEW_COMMITS} new commit(s) since ${LATEST_TAG} (${COMMIT_SHA}) — proceeding"
echo "should_run=true" >> "$GITHUB_OUTPUT"
fi

preflight:
name: Preflight checks
needs: check-dev-needed
runs-on: ubuntu-latest
# Skip dev publish when the push is a stable release version bump (direct push or merged PR)
if: "${{ github.event_name != 'push' || (!startsWith(github.event.head_commit.message, 'chore: release v') && !contains(github.event.head_commit.message, 'release/v')) }}"
if: needs.check-dev-needed.outputs.should_run == 'true'
permissions:
contents: read
steps:
Expand Down Expand Up @@ -139,7 +199,7 @@ jobs:

pre-publish-benchmark:
name: Pre-publish benchmark gate
if: github.event_name != 'push'
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
needs: [compute-version, build-native]
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -306,7 +366,7 @@ jobs:
# ── Dev builds: GitHub pre-release with tarballs ──

publish-dev:
if: github.event_name == 'push'
if: github.event_name == 'schedule'
needs: [compute-version, build-native]
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -478,7 +538,7 @@ jobs:
# ── Stable releases: publish to npm ──

publish:
if: github.event_name != 'push'
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
needs: [compute-version, build-native, pre-publish-benchmark]
runs-on: ubuntu-latest
environment: npm-publish
Expand Down
Loading