Skip to content

Commit a315d86

Browse files
Merge commit '2d4d26936de8bec3af554db29b81364ffda7be0d' as '.repos/alchemy-effect'
2 parents 603bf81 + 2d4d269 commit a315d86

1,522 files changed

Lines changed: 242224 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alchemy/test/**
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Deploy Website
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- "website/**"
10+
- "packages/alchemy/**"
11+
- "bun.lock"
12+
- ".github/workflows/deploy.yml"
13+
pull_request:
14+
types:
15+
- opened
16+
- reopened
17+
- synchronize
18+
- closed
19+
paths:
20+
- "website/**"
21+
- "packages/alchemy/**"
22+
- "bun.lock"
23+
- ".github/workflows/deploy.yml"
24+
25+
concurrency:
26+
group: deploy-website-${{ github.ref }}
27+
cancel-in-progress: false
28+
29+
env:
30+
STAGE: ${{ github.event_name == 'pull_request' && format('pr-{0}',
31+
github.event.number) || (github.ref == 'refs/heads/main' && 'prod' ||
32+
github.ref_name) }}
33+
34+
jobs:
35+
deploy:
36+
if: ${{ github.event.action != 'closed' }}
37+
runs-on: ubuntu-latest
38+
permissions:
39+
contents: read
40+
pull-requests: write
41+
steps:
42+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
43+
44+
# Mint a token for the alchemy-version-bot GitHub App so the PR
45+
# preview comment (created via GitHub.Comment in alchemy.run.ts)
46+
# posts under the bot's identity instead of `github-actions[bot]`.
47+
# Same App as release.yml — its installation scopes already cover
48+
# PR comments.
49+
- name: Generate bot token
50+
id: bot-token
51+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
52+
with:
53+
app-id: ${{ secrets.ALCHEMY_VERSION_BOT_ID }}
54+
private-key: ${{ secrets.ALCHEMY_VERSION_BOT_PRIVATE_KEY }}
55+
56+
- name: Setup Bun
57+
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
58+
59+
- name: Install dependencies
60+
run: bun install
61+
62+
# Build the website ahead of `alchemy deploy`. The
63+
# Cloudflare.StaticSite resource declares the same `bun run build`
64+
# in its config and runs it as part of the create lifecycle, but
65+
# on update plans alchemy reads `dist/` during plan.diff before
66+
# the embedded Build resource gets a chance to (re)run, causing
67+
# a NotFound on a fresh CI checkout. Building here makes the
68+
# workflow correct under both create and update plans.
69+
- name: Build website
70+
working-directory: website
71+
run: bun run build
72+
73+
- name: Deploy
74+
working-directory: website
75+
run: bun alchemy deploy --stage ${{ env.STAGE }} --yes
76+
env:
77+
# Alchemy's Cloudflare auth provider accepts either a scoped
78+
# API token (CLOUDFLARE_API_TOKEN) or the legacy global API
79+
# key paired with email (CLOUDFLARE_API_KEY +
80+
# CLOUDFLARE_EMAIL). We use the latter here so CI matches
81+
# the credentials in Doppler / .env, where only the admin
82+
# global key is provisioned.
83+
CLOUDFLARE_API_KEY: ${{ secrets.ADMIN_CLOUDFLARE_API_KEY }}
84+
CLOUDFLARE_EMAIL: ${{ secrets.ADMIN_CLOUDFLARE_EMAIL }}
85+
CLOUDFLARE_ACCOUNT_ID: ${{ env.STAGE == 'prod' &&
86+
secrets.PROD_CLOUDFLARE_ACCOUNT_ID ||
87+
secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
88+
PULL_REQUEST: ${{ github.event.number }}
89+
# On `pull_request` events GitHub Actions' built-in
90+
# `GITHUB_SHA` is the synthetic merge commit (PR head merged
91+
# into base) — that SHA never shows up in the PR's git log.
92+
# `GITHUB_SHA` is also a reserved env var, so a step-level
93+
# override is silently ignored. Pass the PR head SHA under
94+
# a non-reserved name and read it from alchemy.run.ts.
95+
BUILD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
96+
GITHUB_TOKEN: ${{ steps.bot-token.outputs.token }}
97+
98+
cleanup:
99+
runs-on: ubuntu-latest
100+
if:
101+
${{ github.event_name == 'pull_request' && github.event.action == 'closed'
102+
}}
103+
permissions:
104+
contents: read
105+
pull-requests: write
106+
steps:
107+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
108+
109+
- name: Generate bot token
110+
id: bot-token
111+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
112+
with:
113+
app-id: ${{ secrets.ALCHEMY_VERSION_BOT_ID }}
114+
private-key: ${{ secrets.ALCHEMY_VERSION_BOT_PRIVATE_KEY }}
115+
116+
- name: Setup Bun
117+
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
118+
119+
- name: Install dependencies
120+
run: bun install
121+
122+
- name: Safety Check
123+
run: |-
124+
if [ "${{ env.STAGE }}" = "prod" ]; then
125+
echo "ERROR: Cannot destroy prod environment in cleanup job"
126+
exit 1
127+
fi
128+
129+
- name: Destroy Preview Environment
130+
working-directory: website
131+
run: bun alchemy destroy --stage ${{ env.STAGE }} --yes
132+
env:
133+
CLOUDFLARE_API_KEY: ${{ secrets.ADMIN_CLOUDFLARE_API_KEY }}
134+
CLOUDFLARE_EMAIL: ${{ secrets.ADMIN_CLOUDFLARE_EMAIL }}
135+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
136+
PULL_REQUEST: ${{ github.event.number }}
137+
GITHUB_TOKEN: ${{ steps.bot-token.outputs.token }}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
name: pr-package
2+
3+
# Publishes alchemy + better-auth + pr-package tarballs to the pr-package
4+
# service at pkg.ing on every push to main and every PR sync. On PR close,
5+
# deletes every tag we ever assigned for that PR so the underlying tarballs
6+
# become orphaned and the bucket cleans them up.
7+
8+
on:
9+
push:
10+
branches: [main]
11+
pull_request:
12+
types: [opened, synchronize, reopened, closed]
13+
14+
permissions:
15+
contents: read
16+
pull-requests: write
17+
18+
env:
19+
PR_PACKAGE_HOST: pkg.ing
20+
NODE_VERSION: "24"
21+
22+
jobs:
23+
# ── Publish on push-to-main and PR sync. ──────────────────────────────────
24+
publish:
25+
if: github.event_name == 'push' || (github.event_name == 'pull_request' &&
26+
github.event.action != 'closed')
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
30+
31+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
32+
with:
33+
node-version: ${{ env.NODE_VERSION }}
34+
35+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
36+
with:
37+
bun-version: latest
38+
39+
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
40+
with:
41+
path: ~/.bun/install/cache
42+
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
43+
restore-keys: |
44+
bun-${{ runner.os }}-
45+
46+
- run: bun install
47+
48+
# Build everything: tsdown bundles alchemy (bin/ + cli lib) and tsc -b
49+
# populates lib/ for the layer packages (better-auth, pr-package).
50+
# Their tarballs ship both src/ and lib/, and consumers in non-bun
51+
# runtimes resolve via the `import` condition → ./lib/index.js.
52+
- run: bun run build:packages
53+
54+
- name: Compute tags
55+
id: tags
56+
env:
57+
EVENT: ${{ github.event_name }}
58+
# `head_ref` for PRs (source branch), `ref_name` for push (e.g. "main").
59+
BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref ||
60+
github.ref_name }}
61+
PR_NUMBER: ${{ github.event.pull_request.number }}
62+
# PR builds run on the merge commit by default; tag the actual head sha
63+
# so consumers can pin to a specific PR commit.
64+
SHA: ${{ github.event_name == 'pull_request' &&
65+
github.event.pull_request.head.sha || github.sha }}
66+
run: |
67+
set -euo pipefail
68+
short="${SHA:0:7}"
69+
long="$SHA"
70+
tags=("$short" "$long" "$BRANCH")
71+
if [ "$EVENT" = "pull_request" ]; then
72+
tags+=("pr-${PR_NUMBER}")
73+
fi
74+
json=$(printf '%s\n' "${tags[@]}" | jq -R . | jq -s -c .)
75+
echo "tags=$json" >> "$GITHUB_OUTPUT"
76+
echo "short=$short" >> "$GITHUB_OUTPUT"
77+
echo "Tags: $json"
78+
79+
# PR builds expire after 1 week; pushes to main omit the header and
80+
# fall back to the worker's defaultTtl (3 weeks).
81+
- name: Publish alchemy
82+
env:
83+
TOKEN: ${{ secrets.PR_PACKAGE_TOKEN }}
84+
TAGS: ${{ steps.tags.outputs.tags }}
85+
TTL: ${{ github.event_name == 'pull_request' && '1 week' || '' }}
86+
working-directory: packages/alchemy
87+
run: |
88+
set -euo pipefail
89+
rm -f *.tgz
90+
bun pm pack --destination .
91+
tgz=$(ls *.tgz)
92+
echo "Publishing $tgz with tags $TAGS ttl=${TTL:-default}"
93+
curl -fsSL --show-error -X PUT \
94+
"https://${PR_PACKAGE_HOST}/projects/alchemy/packages" \
95+
-H "Authorization: Bearer ${TOKEN}" \
96+
-H "X-Tags: ${TAGS}" \
97+
${TTL:+-H "X-TTL: ${TTL}"} \
98+
-H "Content-Type: application/gzip" \
99+
--data-binary "@${tgz}"
100+
101+
- name: Publish better-auth
102+
env:
103+
TOKEN: ${{ secrets.PR_PACKAGE_TOKEN }}
104+
TAGS: ${{ steps.tags.outputs.tags }}
105+
TTL: ${{ github.event_name == 'pull_request' && '1 week' || '' }}
106+
working-directory: packages/better-auth
107+
run: |
108+
set -euo pipefail
109+
rm -f *.tgz
110+
bun pm pack --destination .
111+
tgz=$(ls *.tgz)
112+
echo "Publishing $tgz with tags $TAGS ttl=${TTL:-default}"
113+
curl -fsSL --show-error -X PUT \
114+
"https://${PR_PACKAGE_HOST}/projects/@alchemy.run/better-auth/packages" \
115+
-H "Authorization: Bearer ${TOKEN}" \
116+
-H "X-Tags: ${TAGS}" \
117+
${TTL:+-H "X-TTL: ${TTL}"} \
118+
-H "Content-Type: application/gzip" \
119+
--data-binary "@${tgz}"
120+
121+
- name: Publish pr-package
122+
env:
123+
TOKEN: ${{ secrets.PR_PACKAGE_TOKEN }}
124+
TAGS: ${{ steps.tags.outputs.tags }}
125+
TTL: ${{ github.event_name == 'pull_request' && '1 week' || '' }}
126+
working-directory: packages/pr-package
127+
run: |
128+
set -euo pipefail
129+
rm -f *.tgz
130+
bun pm pack --destination .
131+
tgz=$(ls *.tgz)
132+
echo "Publishing $tgz with tags $TAGS ttl=${TTL:-default}"
133+
curl -fsSL --show-error -X PUT \
134+
"https://${PR_PACKAGE_HOST}/projects/@alchemy.run/pr-package/packages" \
135+
-H "Authorization: Bearer ${TOKEN}" \
136+
-H "X-Tags: ${TAGS}" \
137+
${TTL:+-H "X-TTL: ${TTL}"} \
138+
-H "Content-Type: application/gzip" \
139+
--data-binary "@${tgz}"
140+
141+
# PR-only: leave a sticky comment with the install URLs pinned to this
142+
# commit. Uses pkg.ing (the canonical short host), which serves both
143+
# the pretty alias paths and the underlying /projects/:project/tags/:tag
144+
# API directly.
145+
- name: Generate bot token
146+
if: github.event_name == 'pull_request'
147+
id: bot-token
148+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
149+
with:
150+
app-id: ${{ secrets.ALCHEMY_VERSION_BOT_ID }}
151+
private-key: ${{ secrets.ALCHEMY_VERSION_BOT_PRIVATE_KEY }}
152+
153+
- name: Comment on PR
154+
if: github.event_name == 'pull_request'
155+
env:
156+
GH_TOKEN: ${{ steps.bot-token.outputs.token }}
157+
REPO: ${{ github.repository }}
158+
PR_NUMBER: ${{ github.event.pull_request.number }}
159+
SHORT_SHA: ${{ steps.tags.outputs.short }}
160+
run: |
161+
set -euo pipefail
162+
MARKER="<!-- pr-package-comment -->"
163+
# Use `bun add <name>@<url>` instead of `bun add <url>`. Without an
164+
# explicit name, bun's resolver hits a DependencyLoop bug when the
165+
# consumer already has the same package name resolved from npm
166+
# (oven-sh/bun#5789, oven-sh/bun#17946). The aliased form bypasses
167+
# the buggy reconciliation path and works on fresh and existing
168+
# projects alike.
169+
BODY=$(printf '%s\n\nInstall the packages built from this commit:\n\n**alchemy**\n```sh\nbun add alchemy@https://pkg.ing/alchemy/%s\n```\n\n**@alchemy.run/better-auth**\n```sh\nbun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/%s\n```\n\n**@alchemy.run/pr-package**\n```sh\nbun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/%s\n```\n' "$MARKER" "$SHORT_SHA" "$SHORT_SHA" "$SHORT_SHA")
170+
171+
existing=$(gh api --paginate \
172+
"repos/${REPO}/issues/${PR_NUMBER}/comments" \
173+
--jq ".[] | select(.user.login == \"alchemy-version-bot[bot]\") | select(.body | startswith(\"${MARKER}\")) | .id" \
174+
| head -1)
175+
176+
if [ -n "$existing" ]; then
177+
gh api -X PATCH "repos/${REPO}/issues/comments/${existing}" -f body="$BODY"
178+
else
179+
gh api -X POST "repos/${REPO}/issues/${PR_NUMBER}/comments" -f body="$BODY"
180+
fi

0 commit comments

Comments
 (0)