Skip to content
Merged
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: 4 additions & 1 deletion .github/workflows/alert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name: Alert
# pull_request_target. The author already sees them as a check on the PR, and
# that noise is what drives people to mute Actions notifications wholesale.
#
# Needs a DISCORD_WEBHOOK repo secret (Discord: Channel > Integrations >
# Needs a DISCORD_WEBHOOK secret in `publish` (Discord: Channel > Integrations >
# Webhooks). Nothing else reads it.

on:
Expand Down Expand Up @@ -77,6 +77,9 @@ jobs:
github.event.workflow_run.event != 'pull_request' &&
github.event.workflow_run.event != 'pull_request_target'
runs-on: ubuntu-latest
# The webhook lives in the `publish` Environment, which only protected refs
# can deploy to; workflow_run runs on `main`.
environment: publish

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/apt-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
publish:
name: Publish to apt.moq.dev
runs-on: ubuntu-22.04
# Write credentials live in the `publish` Environment, which only protected
# refs can deploy to, so dispatch this from `main`.
environment: publish

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
rust: false
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
# The Cachix write token lives in the protected `publish` Environment.
environment: publish

steps:
- name: Free disk space
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cachix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
release:
name: Release (${{ matrix.os }})
runs-on: ${{ matrix.runs-on }}
# The Cachix write token lives in the protected `publish` Environment.
environment: publish
permissions:
contents: read
strategy:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ jobs:
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
# Docker Hub credentials live in the `publish` Environment, which only
# protected refs can deploy to. Only a tag pushes; other builds need none.
environment: ${{ github.ref_type == 'tag' && 'publish' || '' }}
permissions:
contents: read
steps:
Expand Down Expand Up @@ -119,6 +122,7 @@ jobs:
needs: [parse, build]
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
environment: publish
permissions: {}
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
Expand Down
23 changes: 21 additions & 2 deletions .github/workflows/release-brew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,37 @@ jobs:
name: Publish formula to homebrew-tap
# workflow_run has the base repository's privileges and this job checks out
# the triggering commit, so accept only a successful tag push in this
# repository: a fork PR can rename a workflow and its branch to match.
# repository: a fork PR can rename a workflow and its branch to match. Only
# the tag patterns the `release tags` ruleset protects are accepted.
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository &&
startsWith(github.event.workflow_run.head_branch, 'moq-')
(startsWith(github.event.workflow_run.head_branch, 'moq-relay-v') ||
startsWith(github.event.workflow_run.head_branch, 'moq-cli-v') ||
startsWith(github.event.workflow_run.head_branch, 'moq-gst-v'))
runs-on: ubuntu-latest
# The moq-bot key lives in the `bot` Environment, which only protected
# refs can deploy to, not in an organization secret any branch can read.
environment: bot

steps:
# head_branch names a branch as readily as a tag, and anyone who can push
# may name a branch and a workflow after a release. Only a tag the
# `release tags` ruleset protects, at the run's commit, is a release.
- name: Require a release tag at the run's commit
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.workflow_run.head_branch }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/refs/tags/$TAG" --jq .sha)
if [[ "$commit" != "$SHA" ]]; then
echo "::error::$TAG is not a release tag at $SHA"
exit 1
fi

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# workflow_run runs the default branch's file, whose checkout would
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/release-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ jobs:
with:
ref: ${{ github.sha }}
persist-credentials: false
# head_branch names a branch as readily as a tag, and anyone who can push
# may name a branch and a workflow after a release. Only a tag the
# `release tags` ruleset protects, at the run's commit, is a release.
- name: Require a release tag at the run's commit
if: github.event_name == 'workflow_run'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.workflow_run.head_branch }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/refs/tags/$TAG" --jq .sha)
if [[ "$commit" != "$SHA" ]]; then
echo "::error::$TAG is not a release tag at $SHA"
exit 1
fi
- uses: ./.github/actions/just
- name: Check independent publisher
id: publisher
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
name: Release JS Packages
runs-on: ubuntu-latest
if: github.repository_owner == 'moq-dev'
# npm trusted publishing can require this Environment, which only `release`
# can deploy to, so a branch's OIDC identity cannot publish. It also holds
# the JSR token, since JSR's OIDC trust cannot require an Environment.
# Dry-runs skip it.
environment: ${{ github.event_name == 'push' && 'npm' || '' }}

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -52,5 +57,8 @@ jobs:

- name: Release packages
env:
DRY_RUN: ${{ github.event_name == 'pull_request' }}
DRY_RUN: ${{ github.event_name != 'push' }}
# Only the `npm` Environment holds it, so dry-runs get none.
# release.ts hands it to `deno publish` alone.
JSR_TOKEN: ${{ secrets.JSR_TOKEN }}
run: nix develop --command bun --filter '*' release
4 changes: 4 additions & 0 deletions .github/workflows/release-kt-ffi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
name: Package and publish
needs: [ffi]
runs-on: ubuntu-latest
# Maven and signing credentials live in the `publish` Environment, which
# only protected refs can deploy to. Only a tag publishes; a dry-run needs
# no secrets, so it can run from any branch.
environment: ${{ github.ref_type == 'tag' && 'publish' || '' }}
env:
# Picked up by com.vanniktech.maven.publish via Gradle project properties.
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/release-kt-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ jobs:
with:
ref: ${{ github.sha }}
persist-credentials: false
# head_branch names a branch as readily as a tag, and anyone who can push
# may name a branch and a workflow after a release. Only a tag the
# `release tags` ruleset protects, at the run's commit, is a release.
- name: Require a release tag at the run's commit
if: github.event_name == 'workflow_run'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.workflow_run.head_branch }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/refs/tags/$TAG" --jq .sha)
if [[ "$commit" != "$SHA" ]]; then
echo "::error::$TAG is not a release tag at $SHA"
exit 1
fi
- uses: ./.github/actions/just
- name: Check independent publisher
id: publisher
Expand Down Expand Up @@ -178,6 +194,9 @@ jobs:
group: release-kt-lib-${{ github.event_name == 'pull_request' && github.ref || 'publish' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
# Maven and signing credentials live in the `publish` Environment, which
# only protected refs can deploy to. A dry-run needs no secrets.
environment: ${{ github.event_name != 'pull_request' && 'publish' || '' }}
env:
# Picked up by com.vanniktech.maven.publish via Gradle project properties.
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/release-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ jobs:
publish: ${{ steps.pypi.outputs.exists == 'false' && (github.event_name == 'workflow_run' || (steps.ffi-gate.outputs.unreleased != 'true' && steps.ffi-pypi.outputs.exists == 'true')) }}

steps:
# head_branch names a branch as readily as a tag, and anyone who can push
# may name a branch and a workflow after a release. Only a tag the
# `release tags` ruleset protects, at the run's commit, is a release.
- name: Require a release tag at the run's commit
if: github.event_name == 'workflow_run'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.workflow_run.head_branch }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/refs/tags/$TAG" --jq .sha)
if [[ "$commit" != "$SHA" ]]; then
echo "::error::$TAG is not a release tag at $SHA"
exit 1
fi

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
name: Plz

runs-on: ubuntu-latest
# The moq-bot key lives in the `publish` Environment, which only protected
# refs can deploy to, not in an organization secret any branch can read.
environment: publish
if: ${{ github.repository_owner == 'moq-dev' && github.ref == 'refs/heads/release' }}
# Write credentials live in the `publish` Environment, which only protected
# refs can deploy to. The R2 cache pair stays the repository's read key.
environment: publish

env:
# release-plz copies each crate into its own temp directory to compare it
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/release-swift-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ jobs:
with:
ref: ${{ github.sha }}
persist-credentials: false
# head_branch names a branch as readily as a tag, and anyone who can push
# may name a branch and a workflow after a release. Only a tag the
# `release tags` ruleset protects, at the run's commit, is a release.
- name: Require a release tag at the run's commit
if: github.event_name == 'workflow_run'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.workflow_run.head_branch }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/refs/tags/$TAG" --jq .sha)
if [[ "$commit" != "$SHA" ]]; then
echo "::error::$TAG is not a release tag at $SHA"
exit 1
fi
- uses: ./.github/actions/just
- name: Check independent publisher
id: publisher
Expand Down
30 changes: 27 additions & 3 deletions .github/workflows/release-winget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,36 @@ env:
jobs:
publish:
name: Submit winget manifest
# workflow_run: only after a successful release of a moq-* tag.
# workflow_dispatch: always (it's an explicit dry run).
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'moq-')) }}
# workflow_run: only after a successful release of a tag the `release tags`
# ruleset protects. workflow_dispatch: always (it's an explicit dry run).
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
(startsWith(github.event.workflow_run.head_branch, 'moq-relay-v') ||
startsWith(github.event.workflow_run.head_branch, 'moq-cli-v')))
runs-on: windows-latest
# WINGET_TOKEN lives in the `publish` Environment, which only protected refs
# can deploy to. A dry run needs no token, so it can run from any branch.
environment: ${{ github.event_name == 'workflow_run' && 'publish' || '' }}

steps:
# head_branch names a branch as readily as a tag, and anyone who can push
# may name a branch and a workflow after a release. Only a tag the
# `release tags` ruleset protects, at the run's commit, is a release.
- name: Require a release tag at the run's commit
if: github.event_name == 'workflow_run'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.workflow_run.head_branch }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/refs/tags/$TAG" --jq .sha)
if [[ "$commit" != "$SHA" ]]; then
echo "::error::$TAG is not a release tag at $SHA"
exit 1
fi

- name: Resolve mode and tag
id: mode
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rpm-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
publish:
name: Publish to rpm.moq.dev
runs-on: ubuntu-22.04
# Write credentials live in the `publish` Environment, which only protected
# refs can deploy to, so dispatch this from `main`.
environment: publish

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
12 changes: 9 additions & 3 deletions js/common/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { execFileSync } from "node:child_process";

const dryRun = process.argv.includes("--dry-run") || process.env.DRY_RUN === "true";

// JSR publish token, from the `npm` Environment. Remove it from this process's
// environment so only `deno publish` receives it, not builds or npm.
const jsrToken = process.env.JSR_TOKEN;
delete process.env.JSR_TOKEN;

// Read package.json to get name, version, and whether to also publish to JSR.
const pkg = JSON.parse(await Bun.file("package.json").text());
const { name, version } = pkg;
Expand Down Expand Up @@ -72,9 +77,9 @@ if (publishJsr) {
// Call `deno publish` directly (what `jsr publish` wraps) using the deno from
// the nix devshell, so parallel package releases don't race on a runtime
// jsr/deno download into a shared bunx cache. jsr.json and the generated dist
// leave the tree dirty, so allow it. OIDC trusted publishing kicks in
// automatically under GitHub Actions; locally it falls back to an interactive
// browser login.
// leave the tree dirty, so allow it. Without a token, Deno tries JSR's GitHub
// OIDC trust under GitHub Actions, which the packages should not grant since
// any branch of the repository could claim it, and a browser login locally.
const args = [
"publish",
"--unstable-bare-node-builtins",
Expand Down Expand Up @@ -114,6 +119,7 @@ if (publishJsr) {
console.log(`⏭️ ${name}@${version} already on JSR, skipping`);
} else {
console.log(`🚀 Publishing ${name}@${version} to JSR...`);
if (jsrToken) args.push("--token", jsrToken);
execFileSync("deno", args, { stdio: "inherit", env });
}
}
Loading