-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (117 loc) · 5.38 KB
/
Copy pathrelease.yml
File metadata and controls
132 lines (117 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Changesets-based release workflow with npm Trusted Publishing (OIDC).
#
# How this works:
# 1. Contributors add a changeset file (`pnpm changeset`) per PR describing
# affected packages + bump kind. Changesets accumulate in `.changeset/`.
# 2. On every push to main, this workflow runs `changesets/action@v1`:
# - If unreleased changesets exist: opens / updates a "Version Packages"
# PR that bumps versions + generates CHANGELOGs. The PR sits open
# until you merge it.
# - If the most recent push merged that PR (= no pending changesets,
# but committed version bumps): runs the `publish` script, which
# runs `pnpm changeset publish` to push tags + publish to npm.
# 3. npm publish uses OIDC trusted publishing — no NPM_TOKEN secret.
# Each package's npm trusted-publisher config must point at this
# workflow file (`release.yml`) for OIDC to be accepted.
#
# Manual prerequisites (one-time, for each public package):
# - First publish must be manual to claim the npm name + bootstrap
# trusted-publisher config. After that, this workflow handles updates.
# - Configure trusted publisher at
# https://www.npmjs.com/package/<name>/access → Trusted Publisher →
# GitHub Actions → org=graphrefly, repo=graphrefly-ts, workflow=release.yml
#
# Packages currently in scope (from .changeset/config.json):
# - @graphrefly/ts (clean-slate TypeScript package)
# Ignored:
# - @graphrefly/graphrefly (retired root package, B65)
name: Release
on:
push:
branches: [main]
permissions:
contents: read
# Prevent concurrent release runs racing on the version PR.
concurrency:
group: release-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
name: Release
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ubuntu-latest
permissions:
contents: write # changesets-action commits to version PR + creates GitHub releases
pull-requests: write # opens / updates the Version Packages PR
id-token: write # REQUIRED for npm OIDC trusted publishing
steps:
# Mint a GitHub App installation token. Default GITHUB_TOKEN can't
# create PRs when the org disallows "Allow GitHub Actions to create
# and approve pull requests" — and PRs created by GITHUB_TOKEN don't
# trigger downstream workflows. The App token sidesteps both. Org-
# level var + secret (set on the graphrefly org once, accessible by
# all repos that have the App installed):
# - var: GRAPHREFLY_WRITE_CONTENT_APP_CLIENT_ID
# - secret: GRAPHREFLY_WRITE_CONTENT_APP_PRIVATE_KEY
# The GitHub App must be installed on this repo with permissions:
# Contents=write, Issues=write, Pull requests=write, Metadata=read.
- name: Create GitHub App installation token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.GRAPHREFLY_WRITE_CONTENT_APP_CLIENT_ID }}
private-key: ${{ secrets.GRAPHREFLY_WRITE_CONTENT_APP_PRIVATE_KEY }}
permission-contents: write
permission-issues: write
permission-pull-requests: write
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0 # changesets needs full history to compute diffs
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true
- name: Configure Git committer (GitHub App)
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
user_id=$(gh api "users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)
git config user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config user.email "${user_id}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com"
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24" # >= 22 required for npm OIDC trusted publishing
registry-url: "https://registry.npmjs.org"
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm run lint
- name: Test
run: NODE_ENV=test pnpm test
# Build before publishing. The release build follows the clean-slate
# @graphrefly/ts package; the root package is retired/private.
- name: Build
env:
NODE_OPTIONS: --max-old-space-size=6144
run: pnpm run build
# changesets/action handles BOTH paths (open PR or publish on merge).
- name: Create Release PR or Publish
id: changesets
uses: changesets/action@v1
with:
# `pnpm release` runs `changeset publish` which publishes any
# packages whose version on disk is ahead of npm. Defined in
# root package.json scripts.
publish: pnpm run release
version: pnpm run version-packages
commit: "chore: release packages"
title: "chore: release packages"
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
# `pnpm release` rebuilds the package inside this action step, so it
# needs the same declaration-worker heap budget as the preflight.
NODE_OPTIONS: --max-old-space-size=6144