-
Notifications
You must be signed in to change notification settings - Fork 6
149 lines (131 loc) · 6.01 KB
/
publish.yaml
File metadata and controls
149 lines (131 loc) · 6.01 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
mode:
description: >
Release mode:
- "version" — Creates a "Version Packages" PR that bumps versions and
updates each package's CHANGELOG.md based on pending changesets. Run
this first.
- "publish" — Publishes every package whose on-disk version differs
from npm, with provenance. Only run this AFTER the Version Packages
PR has been merged to main.
NOTE: @openrouter/agent releases must be coordinated with @openrouter/sdk
because callModel changes are typically coupled with SDK type changes.
required: true
type: choice
options:
- version
- publish
default: version
dry-run:
description: >
Dry run: If enabled, simulates the publish without making any changes.
Useful for verifying what would publish before committing to a release.
required: false
type: boolean
default: false
permissions:
contents: write # For creating releases and the Version Packages PR
pull-requests: write # For creating/updating the Version Packages PR
id-token: write # For npm provenance signing
env:
TURBO_TELEMETRY_DISABLED: '1'
jobs:
release:
runs-on: ubuntu-latest
environment: npm-publish
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
registry-url: https://registry.npmjs.org
- run: pnpm install --frozen-lockfile
- run: pnpm run build
- run: pnpm run test
- name: Version PR or Publish (changesets)
id: changesets
if: >
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && inputs.mode == 'version')
uses: changesets/action@v1
with:
title: 'chore: version packages'
commit: 'chore: version packages'
version: pnpm exec changeset version
publish: pnpm exec changeset publish --no-git-checks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Record the npm version before a manual publish so the dispatch step can
# tell whether this run actually published a new @openrouter/agent (the
# changesets/action `published` output only exists for the push /
# mode=version path, not this manual one).
- name: Capture pre-publish version (manual publish)
id: pre-publish
if: github.event_name == 'workflow_dispatch' && inputs.mode == 'publish' && !inputs.dry-run
run: echo "version=$(npm view @openrouter/agent version)" >> "$GITHUB_OUTPUT"
- name: Publish (workflow_dispatch, live)
if: github.event_name == 'workflow_dispatch' && inputs.mode == 'publish' && !inputs.dry-run
run: pnpm exec changeset publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# `changeset publish` has no native --dry-run. Fall back to pnpm's
# recursive dry-run, which simulates publishing every workspace package
# rather than only the ones changesets would pick. Output set may be
# wider than the live publish — but nothing is actually published, so
# this is only a diagnostic preview.
- name: Publish (workflow_dispatch, dry-run)
if: github.event_name == 'workflow_dispatch' && inputs.mode == 'publish' && inputs.dry-run
run: pnpm -r publish --dry-run --access public --provenance --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# HOP B trigger: when @openrouter/agent is actually published, tell the
# monorepo (openrouter-web) to bump its pinned @openrouter/agent for
# server tools. Two publish paths produce a real publish:
# 1. changesets/action on push (Version PR merged) → `published` output
# 2. manual workflow_dispatch mode=publish → detect via npm version diff
- name: Resolve published @openrouter/agent version
id: published
if: ${{ !inputs.dry-run }}
run: |
set -euo pipefail
VERSION=""
# Path 1: changesets/action publish leg.
if [ "${{ steps.changesets.outputs.published }}" = "true" ]; then
VERSION=$(printf '%s' '${{ steps.changesets.outputs.publishedPackages }}' \
| python3 -c "import sys,json; pkgs=json.load(sys.stdin); print(next((p['version'] for p in pkgs if p['name']=='@openrouter/agent'), ''))")
fi
# Path 2: manual live publish — compare npm version before/after.
if [ -z "$VERSION" ] && [ -n "${{ steps.pre-publish.outputs.version }}" ]; then
AFTER="$(npm view @openrouter/agent version)"
if [ "$AFTER" != "${{ steps.pre-publish.outputs.version }}" ]; then
VERSION="$AFTER"
fi
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [ -n "$VERSION" ]; then
echo "Published @openrouter/agent $VERSION"
else
echo "No new @openrouter/agent publish detected — no dispatch"
fi
- name: Dispatch monorepo bump
if: ${{ !inputs.dry-run && steps.published.outputs.version != '' }}
env:
# Cross-repo PAT; needs contents:write on
# OpenRouterTeam/openrouter-web so the repository_dispatch is accepted.
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
set -euo pipefail
gh api repos/OpenRouterTeam/openrouter-web/dispatches \
-f event_type=openrouter-agent-published \
-F "client_payload[version]=${{ steps.published.outputs.version }}" \
-F "client_payload[source_run_url]=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "Dispatched openrouter-agent-published (version ${{ steps.published.outputs.version }}) to openrouter-web"