Skip to content

Workflow upstream sync

github-actions[bot] edited this page Dec 6, 2026 · 2 revisions

upstream-sync

What it does. Follows another GitHub repository's releases, pins the one you track to a full commit SHA, holds every new release for a number of days, runs your build command and opens a pull request. It never merges. The pull request changes the pin file and the files you list, nothing else.

Why it exists. A project that builds on someone else's release (a stylesheet, a schema, a binary) wants to follow it without trusting the newest tag on the day it appears: a tag can be moved, a release can be pulled or compromised. The first caller was a repository that rebuilds two stylesheets from a pinned upstream. The watcher is generic: a pin file, a tag filter and your own build command.

Inputs (17), read from upstream-sync.yml:

Input Type Default Meaning
upstream-repo string required The upstream GitHub repository to follow, owner/name. Required. Must equal repo in the pin file. (required)
pin-file string upstream.json Repository-relative path of the pin file, a JSON object with repo, tag, sha and dist. The job rewrites tag and sha.
tag-filter string empty A regular expression (Python syntax, searched, not anchored unless you anchor it) a release tag must match, for example ^5\.. Empty matches every tag.
stable-only boolean true Skip pre-releases and drafts. Set false to follow pre-releases too (a draft is never followed).
hold-days number 7 Whole days, 1 to 365, a new release is held from the moment this job first saw it, before a pull request may be opened.
build-command string required Required. Shell command run from the repository root after the new pin is written (it rebuilds whatever derives from the upstream). It holds no token and no secret. (required)
check-command string empty Optional shell command run after the build, from the repository root. A non-zero exit stops the job before any pull request. Empty skips it.
commit-paths string empty Space-separated repository-relative files to commit besides the pin file, the files the build command rewrites. Empty commits the pin file only.
branch-prefix string upstream/ Prefix of the pull request branch, <prefix><tag>, one to three directory names ending in a slash. A leftover branch of that name with no open pull request is replaced, so keep this namespace for the job.
pr-title-template string Update {repo} to {tag} Title of the pull request and its commit. Plain text; {tag} and {repo} are replaced. At most 200 characters.
runner string ubuntu-24.04 The runner label for all three jobs. Only the GitHub-hosted Linux labels ubuntu-22.04, ubuntu-22.04-arm, ubuntu-24.04, ubuntu-24.04-arm and ubuntu-latest are accepted, because a runner that is reused between jobs could carry state from the build job into the publishing job. Anything else fails the first step.
require-protected-record boolean true An update needs the upstream-seen branch to exist and be protected (GitHub reports it protected). Otherwise the first sight is recorded as usual but the run never opens a pull request and warns you to protect the branch like the default branch (no force pushes, restricted pushes). The hold is only as good as the record it is measured from. Setting false is not recommended.
dry-run boolean false Plan, build and check, but write nothing - no record on upstream-seen, no branch, no pull request. For trying a caller out. The only way to run from an event other than a schedule or a manual start on the default branch, and then only the plan runs.
egress-policy string block harden-runner egress policy of the build job only - audit logs outbound connections, block allows only allowed-endpoints. The jobs that hold a token (plan, publish) are always block with a fixed allow-list; no input changes that.
allowed-endpoints string api.github.com:443 github.com:443 harden-runner allow-list of the build job only, space-separated host:port entries. The default is what the checkout needs; wildcards are not supported. Hosts your build reaches go in extra-allowed-endpoints.
extra-allowed-endpoints string empty Appended to allowed-endpoints for the build job only, for hosts only the build or check command reaches (a download host, for example). Same format.
timeout-minutes number 15 Job timeout.

The hold starts when this job first saw the tag

The hold is never measured from a git date or from the release date: whoever publishes chooses both. The job keeps a record on a branch of your repository named upstream-seen, one file, seen.json, mapping each tag to {"sha": ..., "first_seen": ...}:

What the job finds What it does
The tag is not in the record Records it now with its commit SHA and holds.
The tag is there with the same SHA Holds until first_seen plus hold-days; then opens the pull request.
The tag is there with a different SHA The tag moved. Overwrites the record with the new SHA and a fresh first_seen, prints a ::warning:: and holds again. No pull request is opened for it in the same run.

The record is written with one push of that one branch: not forced, three attempts at most (each from a fresh fetch, so two runs that race both end up recorded), nothing pushed when the record already says the same, and the branch created when it does not exist yet. The job token reaches git only through a credential helper that reads it from the environment when git asks, never on a command line, in .git/config or in any file, and nothing is derived from it. No other branch is touched except the pull request branch (branch-prefix plus the tag) the job owns.

An unreadable or damaged seen.json on an existing upstream-seen branch stops the run with an error rather than starting over, because starting over would hide that someone edited it. An entry whose first_seen is in the future (more than five minutes ahead) or earlier than the time the upstream published that release is not believable: the job prints a ::warning::, records the tag again with the time of this run and holds again.

Protect the upstream-seen branch like the default branch (no force pushes, pushes restricted to the Actions bot and the administrators, no deletion). The sanity check above catches an implausible date, not a plausible one: anyone who can rewrite that branch can shorten a hold. So this is a precondition, not advice: with require-protected-record (default true) the job opens a pull request only when GitHub reports the branch protected. When the branch does not exist yet or is not protected, the first sight is recorded as usual, the run stays a hold and prints a ::warning:: saying to protect the branch and run again. require-protected-record: false opts out; that is not recommended.

What the job pins

It lists the newest release (by publish time) whose tag matches tag-filter and, with stable-only, is neither a pre-release nor a draft. Its tag is resolved to a commit: an annotated tag, or a tag that points at another tag, is followed until the object is a commit, so the pinned SHA is never a tag object. The tag is resolved again right before the pull request is opened, and the job fails if the SHA moved during the run. Releases are listed 100 per page; if all 30 pages are full, the job fails with an error instead of choosing from a partial list. A pinned tag that now resolves to a different SHA is recorded and held like a new revision, even though its tag name has not changed.

The pin file

A JSON object in your repository with repo, tag, sha and dist. repo must equal upstream-repo; the job rewrites tag and sha and leaves everything else as it was. Your build command reads the pin and fetches by SHA (raw.githubusercontent.com/<repo>/<sha>/<dist>).

Three jobs, so your commands never share a job with the write token

Job Scopes What it does
plan contents: read, pull-requests: read Reads the releases and the record, decides none, hold or update. Runs none of your commands.
build contents: read Writes the pin, runs build-command and check-command. No token in any step. Uploads only the pin file and the commit-paths, each a regular file within a size cap.
publish contents: write, pull-requests: write Checks out fresh, installs its own copy of the script, records the first sight, downloads the artifact and validates every file (the pin file or under a declared path, no link, no .git, the pin holding exactly the planned repo, tag and commit), resolves the tag again, then commits and opens the pull request. Runs none of your commands; git runs without hooks and with a fixed PATH.

The record is written only by publish, so a build that fails still leaves the first sight on record. Only the pull request of this repository's own Actions bot for the branch counts as already open; one from a fork or by another author does not suppress an update. A branch left by an earlier run is reused, never removed: only when no pull request of this repository uses it, whoever opened it, and only when its tip was created by the job, it is updated with a lease on the tip that was just inspected (--force-with-lease), so a branch that moved in the meantime fails the push instead of being overwritten. In every other case the job fails with a plain message and changes nothing. If an open pull request of this job proposes an older commit for a moved tag, the plan fails once the new commit's hold has ended and an update is planned (not on the run that first records the move), and tells you to close it; the next run can propose the new commit. The job does not refresh the open pull request automatically.

Only the build job follows your egress-policy, allowed-endpoints and extra-allowed-endpoints: list the hosts your build reaches there. The plan and publish jobs hold tokens, so they are always block with a fixed list (api.github.com, github.com and the Actions results receiver) that no input changes.

Runners and git

All three jobs run on a GitHub-hosted Linux runner: runner accepts only ubuntu-22.04, ubuntu-22.04-arm, ubuntu-24.04, ubuntu-24.04-arm and ubuntu-latest, and any other value fails the first step with a clear error (the job itself is scheduled on ubuntu-24.04, never on the label that was refused). A runner that is reused between jobs could carry state from the build job into the publishing job. Every git call of the script runs in a neutral environment: no inherited GIT_* variable, GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM set to /dev/null, an empty HOME, a fixed PATH, and the options core.hooksPath=/dev/null, core.fsmonitor=false and protocol.ext.allow=never on every command.

Which events may run it

This repository's own check of the workflow (fixture-upstream-sync.yml) runs only on a push to the default branch or a manual start, never on a pull request, because the called workflow declares write scopes.

The plan job refuses to run unless the event is a schedule or a workflow_dispatch and the ref is the default branch; the build and publish jobs then never start. The one exception is dry-run: true, which may run from any event. From an event or ref that may not build it runs the plan only; on a schedule or manual start on the default branch it also runs the build and check commands for a candidate, but never the publish job, and writes nothing. The plan exposes a build output: normally it is true for an update with no open pull request of this job; in a dry run it is also true for a held or already proposed candidate. No build runs when the plan finds the pin already current.

Inputs are data

Every input is checked against a strict pattern before anything uses it, reaches the script through an environment variable and is never expanded into a run: line. build-command and check-command are code you chose, run with your privileges in the build job only. branch-prefix must form a Git-valid branch name and cannot use the reserved upstream-seen/ namespace.

A minimal caller

on:
  schedule:
    - cron: '0 7 * * 2'
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: upstream-sync
  cancel-in-progress: false

jobs:
  sync:
    uses: ChiefGyk3D/git-your-ship-together/.github/workflows/upstream-sync.yml@<sha> # vX.Y.Z
    permissions:
      contents: write
      pull-requests: write
    with:
      upstream-repo: owner/name
      tag-filter: '^5\.'
      build-command: bash scripts/build.sh
      commit-paths: out/styles.css

Set dry-run: true to try it out: it plans, builds and checks any candidate, including one held or already proposed, and writes nothing.

What it cannot do

A pull request opened with the job token starts no checks of its own (a GitHub rule); close and reopen it, or push to its branch, to run them. The script is scripts/upstream_sync.py, standard library only, inlined byte for byte; tests/test_upstream_sync.py fails if the copy differs.

What it refuses to do

It never merges, never runs your commands in the job that holds the write token, never pushes to the default branch, never deletes a branch, never forces a push except with a lease on the tip it inspected, and never touches a branch other than upstream-seen and its own pull request branch. It opens no pull request for a tag it has not watched for the whole hold, for a tag that moved, for a tag that moved while it ran, for a build or check that failed, or when an input does not match its pattern. It never starts the hold from a git date or a release date. A reusable workflow cannot declare concurrency, so give the caller a group of its own (the minimal caller above has one).

Clone this wiki locally