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
25 changes: 12 additions & 13 deletions .github/workflows/alchemy.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Deploys with Alchemy (alchemy.run.ts). A push to main deploys the stage `prod`,
# the production deployment. A pull request from this repository deploys the stage
# `pr-<number>`, a preview with that name; closing the pull request destroys the
# stage and deletes the preview. The state of every stage is in the
# `alchemy-state-store` project of the team, under the stack name GITHUB_REPOSITORY.
# Every run needs only the team token CONVEX_ACCESS_TOKEN; it mints the deploy
# keys itself. Only the Alchemy steps get the secret. `id-token: write` lets a deploy
# stage and deletes the preview. The state of every stage is on the branch
# `alchemy-state-store` of this repository, under the stack name GITHUB_REPOSITORY.
# `contents: write` lets a run write that branch with its own token, and the secret
# ALCHEMY_GITHUB_STATE_KEY seals each secret in the state. Every run also needs the team
# token CONVEX_ACCESS_TOKEN; it mints the deploy keys itself. Only the Alchemy steps get
# the secrets. `id-token: write` lets a deploy
# ask Samebase for the deployment's Google sign-in client with GitHub's token of the run.
on:
push: { branches: [main] }
pull_request: { types: [opened, synchronize, reopened, closed] }
# Run once on main with adopt to take over a project with the name of the repository that
# exists already.
workflow_dispatch: { inputs: { adopt: { type: boolean, default: false } } }
permissions: { contents: read, pull-requests: write, id-token: write }
permissions: { contents: write, pull-requests: write, id-token: write }
# One run per stage at a time: the state store has no lock. A closed pull request keeps
# its head_ref.
concurrency: { group: "alchemy-${{ github.head_ref || github.ref_name }}", queue: max }
Expand Down Expand Up @@ -69,29 +71,26 @@ jobs:
env:
ADOPT: ${{ inputs.adopt && '--adopt' || '' }}
CONVEX_ACCESS_TOKEN: ${{ secrets.CONVEX_ACCESS_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ALCHEMY_GITHUB_STATE_KEY: ${{ secrets.ALCHEMY_GITHUB_STATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
- name: Deploy the preview
if: steps.keys.outputs.skip != 'true' && github.event_name == 'pull_request' && github.event.action != 'closed'
run: pnpm exec alchemy deploy --stage "$STAGE" --yes --no-input
env:
CONVEX_ACCESS_TOKEN: ${{ secrets.CONVEX_ACCESS_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ALCHEMY_GITHUB_STATE_KEY: ${{ secrets.ALCHEMY_GITHUB_STATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
- name: Update the stack comment
if: steps.keys.outputs.skip != 'true' && github.event_name == 'pull_request' && github.event.action != 'closed'
run: pnpm exec alchemy-convex stack-comment
env:
CONVEX_ACCESS_TOKEN: ${{ secrets.CONVEX_ACCESS_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ALCHEMY_GITHUB_STATE_KEY: ${{ secrets.ALCHEMY_GITHUB_STATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
- name: Destroy the preview
if: steps.keys.outputs.skip != 'true' && github.event.action == 'closed'
run: pnpm exec alchemy destroy --stage "$STAGE" --yes --no-input
env:
CONVEX_ACCESS_TOKEN: ${{ secrets.CONVEX_ACCESS_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ALCHEMY_GITHUB_STATE_KEY: ${{ secrets.ALCHEMY_GITHUB_STATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
5 changes: 2 additions & 3 deletions .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
required: true
type: string

permissions: { contents: read, pull-requests: write }
permissions: { contents: write, pull-requests: write }

# The group of the deploy of main in alchemy.yml, so a destroy waits for a running deploy.
concurrency: { group: "alchemy-main", queue: max }
Expand Down Expand Up @@ -50,6 +50,5 @@ jobs:
run: pnpm exec alchemy destroy --stage prod --yes --no-input
env:
CONVEX_ACCESS_TOKEN: ${{ secrets.CONVEX_ACCESS_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
ALCHEMY_GITHUB_STATE_KEY: ${{ secrets.ALCHEMY_GITHUB_STATE_KEY }}
GITHUB_TOKEN: ${{ github.token }}
9 changes: 5 additions & 4 deletions alchemy.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
// uploads the site, and pushes the functions.
//
// The stack is named after the repository, `owner/name`, and its Convex project after `name`. The
// state of every stage is in the `alchemy-state-store` project of the team, which Convex.state()
// creates on the first run. Every run needs the team token CONVEX_ACCESS_TOKEN, or a Convex CLI
// state of every stage is on the branch `alchemy-state-store` of this repository, which
// GitHubState.state() creates on the first run. It writes with GITHUB_TOKEN and seals each secret
// with the key ALCHEMY_GITHUB_STATE_KEY. Every run needs the team token CONVEX_ACCESS_TOKEN, or a Convex CLI
// login (`npx convex login`) on a development machine; it mints the deploy keys itself. The token
// names its team; with the Convex CLI login, the team is the team of the deployment that .env.local
// selects.
Expand All @@ -41,9 +42,9 @@
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { parseEnv } from "node:util";
import * as Cloudflare from "@alchemy.run/cloudflare";
import * as Convex from "@samebase/alchemy-convex";
import * as IdentityHub from "@samebase/alchemy-convex/identity-hub";
import * as GitHubState from "@samebase/alchemy-kit/github-state";
import * as Alchemy from "alchemy";
import { adopt } from "alchemy/AdoptPolicy";
import * as Output from "alchemy/Output";
Expand Down Expand Up @@ -93,7 +94,7 @@ export default Alchemy.Stack(
repository,
{
providers: Convex.providers(),
state: Convex.withRunRecord(Cloudflare.state()),
state: Convex.withRunRecord(GitHubState.state()),
},
Effect.gen(function* () {
const { stage } = yield* Alchemy.Stack;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"tw-animate-css": "^1.4.0"
},
"devDependencies": {
"@alchemy.run/cloudflare": "2.0.0-beta.85",
"@effect/platform-node": "4.1.2",
"@samebase/alchemy-convex": "0.40.0",
"@samebase/alchemy-kit": "0.2.1",
"@tanstack/router-plugin": "1.168.48",
"@types/node": "26.6.6",
"@types/react": "19.3.0",
Expand Down
Loading
Loading