Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions .github/workflows/j5-ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: J5 CI

# Pull request branches are covered by `pull_request`, so `push` lists only the
# branches that are tested without a PR: `j5/main`, and the release and preview
# branches the packaging runbook publishes from before any PR exists.
# branches that are tested without a PR: `j5/main`, and the preview branches
# the packaging runbook publishes from before any PR exists.
# `pull_request` has no base filter, so every layer of a chain of PRs is tested
# whatever its base branch is named, and whether or not GitHub knows the chain
# as a stack.
on:
push:
branches:
- "j5/main"
- "j5/release-[0-9]*"
- "j5/preview-[0-9]*"
pull_request:

Expand Down
35 changes: 16 additions & 19 deletions .github/workflows/j5-nightly.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: J5 Nightly

# Publishes a nightly of `j5/main`: a pre-release tagged
# `v<x.y.z>-nightly.<yyyymmdd>.<run>`, where `x.y.z` is the next patch after the
# version the manifests commit. Servers on the nightly channel and desktop apps
# on the nightly update track follow it. Nothing is committed: the version is
# stamped into the manifests during each build.
# `v<yyyymm>.<d>.<n>-nightly.<yyyymmdd>.<run>`, named for the UTC day it is built
# (scripts/j5/release-version.ts). Servers on the nightly channel and desktop
# apps on the nightly update track follow it. Nothing is committed: the version
# is stamped into the manifests during each build. J5 Stable promotes a nightly
# to a stable release.
#
# Started by hand for now. To run it on a schedule, add a `schedule` trigger and
# set `due` in the `resolve` job from `shouldReleaseNightly` in upstream's
Expand All @@ -16,8 +17,10 @@ on:

permissions: {}

# Shared with J5 Stable, so no stable release of today lands between this run
# picking its number and publishing.
concurrency:
group: j5-nightly
group: j5-publish
cancel-in-progress: false

jobs:
Expand All @@ -42,30 +45,24 @@ jobs:

- uses: actions/checkout@v6

- uses: pnpm/action-setup@v6
with:
version: 12.14.0
run_install: false

- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: pnpm

- run: pnpm install --frozen-lockfile

# Upstream's script; its `name` output says "T3 Code" and is not used.
# The stable releases already tagged for today decide the nightly's number.
- name: Resolve the nightly version
id: version
env:
GH_TOKEN: ${{ github.token }}
NIGHTLY_DATE: ${{ github.run_started_at }}
run: |
set -euo pipefail
pnpm exec node scripts/resolve-nightly-release.ts \
--date "$(date -u -d "$NIGHTLY_DATE" +%Y%m%d)" \
--run-number "$GITHUB_RUN_NUMBER" \
--sha "$GITHUB_SHA" \
--github-output
date="$(date -u -d "$NIGHTLY_DATE" +%Y%m%d)"
gh api --paginate "repos/$GITHUB_REPOSITORY/git/matching-refs/tags/v${date:0:6}.$((10#${date:6}))." \
--jq '.[].ref | sub("^refs/tags/"; "")' > "$RUNNER_TEMP/tags.txt"
version="$(node scripts/j5/release-version.ts nightly \
--date "$date" --run-number "$GITHUB_RUN_NUMBER" --tags-file "$RUNNER_TEMP/tags.txt")"
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Decide whether a nightly is due
id: due
Expand Down
46 changes: 31 additions & 15 deletions .github/workflows/j5-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ name: J5 Release
# A version `<x.y.z>-nightly.<yyyymmdd>.<n>` publishes a nightly: also a
# pre-release that never becomes "latest", but with `nightly-mac.yml`, the feed
# desktop apps on the nightly update track follow. Nightlies come only from J5
# Nightly, which calls this workflow with a commit and a version; a manual run
# refuses a nightly version, and a call refuses any other. The version is
# then stamped into the manifests at build time instead of being read from them,
# and the desktop app is built by this run's `desktop` job.
# Nightly, and stable releases only from J5 Stable, which promotes a nightly.
# Both call this workflow with a commit and a date version
# (scripts/j5/release-version.ts); the version is then stamped into the
# manifests at build time instead of being read from them, and the desktop app
# is built by this run's `desktop` job. A manual run publishes only a preview,
# at the version its branch commits.
#
# The builds run side by side and only `release` waits for all of them. Each
# macOS job is one more wait for a scarce macOS runner, so there are two:
Expand Down Expand Up @@ -139,15 +141,20 @@ jobs:
if (channel === null) {
throw new Error(`This workflow requires a stable (x.y.z), preview (x.y.z-preview.<date>.<n>) or nightly (x.y.z-nightly.<date>.<n>) version; found ${version}.`);
}
// A nightly reaches every install on the nightly track, so it comes only from J5
// Nightly, which builds j5/main. A manual run never publishes one, whatever version
// the branch commits.
if (!stamp && channel === 'nightly') {
throw new Error(`Nightlies are published by J5 Nightly, not by a manual J5 Release; found ${version}.`);
// A nightly reaches every install on the nightly track and a stable release every
// install, so they come only from J5 Nightly, which builds j5/main, and J5 Stable,
// which promotes a nightly. A manual run never publishes one, whatever version the
// branch commits.
if (!stamp && channel !== 'preview') {
throw new Error(`A manual J5 Release publishes only a preview; nightlies come from J5 Nightly and stable releases from J5 Stable. Found ${version}.`);
}
// Nothing calls this workflow with a stable or preview version until promotion exists.
if (stamp && channel !== 'nightly') {
throw new Error(`A calling workflow can publish only a nightly; found ${version}.`);
if (stamp && channel === 'preview') {
throw new Error(`A calling workflow publishes a nightly or a stable release; found ${version}.`);
}
// Nightly and stable versions are dates (scripts/j5/release-version.ts). Anything
// else would sort below every date version and never be offered as an update.
if (stamp && !/^\d{6}\.([1-9]|[12]\d|3[01])\.\d+(-|$)/.test(version)) {
throw new Error(`A nightly or stable version is <yyyymm>.<d>.<n>; found ${version}.`);
}
// Release archives replace the npm package from 0.0.44 on; an older
// version number would be offered as a downgrade to every installed
Expand All @@ -159,8 +166,10 @@ jobs:
// A published release that already carries SHA256SUMS is final:
// rebuilding would change archive bytes under existing checksums.
// An existing release for this version must come from the same
// commit; a mismatch means the version was not bumped, so fail
// rather than report "already published".
// commit. A mismatch means a preview's version was not bumped, or
// a nightly whose number another nightly already took as a stable
// release is being promoted, so fail rather than report "already
// published".
const tag = `v${version}`;
let published = false;
let release = null;
Expand All @@ -179,7 +188,7 @@ jobs:
if (error.status !== 404 && error.status !== 422) throw error;
}
if (tagSha !== null && tagSha !== sha) {
throw new Error(`Release ${tag} already exists at ${tagSha}, but this build is ${sha}. Bump the version before releasing.`);
throw new Error(`Release ${tag} already exists at ${tagSha}, but this build is ${sha}. ${channel === 'stable' ? 'Promote a newer nightly.' : 'Bump the version before releasing.'}`);
}
published = tagSha === sha && !release.draft && release.assets.some(asset => asset.name === 'SHA256SUMS');
}
Expand Down Expand Up @@ -591,6 +600,13 @@ jobs:
if tag_sha="$(gh api "repos/$GH_REPO/commits/$tag" --jq .sha 2>/dev/null)"; then
test "$tag_sha" = "$RELEASE_SHA"
fi
# A draft has no tag yet, so a draft a failed run left for another commit
# passes the check above; publishing into it would mislabel this build.
if target="$(gh release view "$tag" --json targetCommitish --jq .targetCommitish 2>/dev/null)" \
&& [[ "$target" != "$RELEASE_SHA" ]]; then
echo "::error::A release for $tag already targets $target, not $RELEASE_SHA. Delete that draft, or promote a newer nightly."
exit 1
fi
if ! gh release view "$tag" >/dev/null 2>&1; then
if [[ "$RELEASE_CHANNEL" == nightly ]]; then
cat > "$RUNNER_TEMP/release-notes.md" <<EOF
Expand Down
113 changes: 113 additions & 0 deletions .github/workflows/j5-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: J5 Stable

# Promotes a published nightly to a stable release: the nightly's commit, built
# again as `<yyyymm>.<d>.<n>` (the nightly's version without its suffix) and
# published as "latest". The stable build is of a commit nightly users already
# ran. Nothing is committed: the version is stamped into the manifests during
# each build. J5 Release builds the desktop app and the CLI archives and
# publishes them.

on:
workflow_dispatch:
inputs:
nightly:
description: Nightly to promote, such as v202610.15.0-nightly.20261015.12. Defaults to the newest.
required: false
type: string

permissions: {}

# Shared with J5 Nightly: a nightly picks its number before its builds, so a
# stable release of the same day published meanwhile would sort above it.
concurrency:
group: j5-publish
cancel-in-progress: false

jobs:
resolve:
name: Resolve the nightly and its stable version
if: github.repository == 'Jacksondr5/j5code'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
outputs:
ref: ${{ steps.version.outputs.ref }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Require the default branch
run: |
if [[ "$GITHUB_REF" != "refs/heads/j5/main" ]]; then
echo "::error::Run J5 Stable on j5/main, whose workflows it uses; this run was started on $GITHUB_REF."
exit 1
fi

- uses: actions/checkout@v6

- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc

- name: Resolve the nightly and its stable version
id: version
env:
GH_TOKEN: ${{ github.token }}
NIGHTLY: ${{ inputs.nightly }}
run: |
set -euo pipefail
tag="$NIGHTLY"
if [[ -z "$tag" ]]; then
tag="$(gh api "repos/$GITHUB_REPOSITORY/releases?per_page=100" \
--jq '[.[] | select(.draft | not) | select(.tag_name | test("-nightly\\."))] | sort_by(.published_at) | last | .tag_name // empty')"
if [[ -z "$tag" ]]; then
echo "::error::No published nightly found. Run J5 Nightly first."
exit 1
fi
fi
tag="v${tag#v}"
# A nightly that was never published was never offered to anyone to run.
if [[ "$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$tag" --jq '.draft')" != "false" ]]; then
echo "::error::$tag is not a published release."
exit 1
fi
latest="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq '.tag_name')"
version="$(node scripts/j5/release-version.ts stable "$tag" --latest "$latest")"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Small one. This only checks "older than latest". If v$version already exists at a different commit, that only shows up in J5 Release's resolve, after we've paid for a full signed and notarized build. Could check commits/v$version here and fail early with "Promote a newer nightly".

ref="$(gh api "repos/$GITHUB_REPOSITORY/commits/$tag" --jq '.sha')"
# Fail before the signed builds when another nightly already took this number.
if taken="$(gh api "repos/$GITHUB_REPOSITORY/commits/v$version" --jq '.sha' 2>/dev/null)" && [[ "$taken" != "$ref" ]]; then
echo "::error::v$version is already released from $taken, not $tag ($ref). Promote a newer nightly."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "ref=$ref" >> "$GITHUB_OUTPUT"
echo "::notice::Promoting $tag ($ref) to J5 Code $version."

# These gitlinks belong to vendored manifests, not this repository.
# Remove them only from the disposable index before checkout's cleanup.
- name: Exclude vendored gitlinks from checkout cleanup
if: always()
run: |
python3 - <<'PYTHON'
import subprocess
entries = subprocess.check_output(["git", "ls-files", "--stage", "-z", ".repos"])
paths = [entry.split(b"\t", 1)[1] for entry in entries.split(b"\0") if entry.startswith(b"160000 ")]
if paths:
subprocess.run(["git", "update-index", "--force-remove", "-z", "--stdin"], input=b"\0".join(paths) + b"\0", check=True)
PYTHON

release:
name: Release
needs: resolve
permissions:
contents: write
actions: read
uses: ./.github/workflows/j5-release.yml
with:
ref: ${{ needs.resolve.outputs.ref }}
version: ${{ needs.resolve.outputs.version }}
secrets:
CSC_LINK: ${{ secrets.CSC_LINK }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
Loading
Loading