Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
62 changes: 62 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22.9.0'

- name: Setup Yarn Corepack
run: corepack enable

- name: Install dependencies
run: yarn install

- name: Build Storybook
run: yarn build-storybook

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Don't remove PR previews when deploying the main branch
path: 'apps/docs/storybook-static'
retention-days: 30

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

168 changes: 168 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Deploy PR Preview

on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
pull-requests: write

# Allow only one concurrent deployment per PR
concurrency:
group: pr-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
# Build job
build:
runs-on: ubuntu-latest
# Don't run on closed PRs
if: github.event.action != 'closed'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22.9.0'

- name: Setup Yarn Corepack
run: corepack enable

- name: Install dependencies
run: yarn install

- name: Build Storybook
run: yarn build-storybook

# Verify the build output
- name: Verify build output
run: |
echo "Checking build output directory..."
ls -la apps/docs/storybook-static
echo "Checking for index.html..."
if [ -f apps/docs/storybook-static/index.html ]; then
echo "index.html exists"
else
echo "index.html does not exist"
exit 1
fi

# Add a comment to the PR with the preview URL
- name: Comment PR
uses: actions/github-script@v6
with:
script: |
const previewUrl = `https://lambda-curry.github.io/medusa-forms/pr-${context.issue.number}/`;
const commentBody = `πŸ“ **Storybook Preview**: [View Storybook](${previewUrl})

This preview will be updated automatically when you push new changes to this PR.

> Note: The preview will be available after the workflow completes and the PR is approved for deployment.`;

// Get existing comments
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

// Check if we already have a comment
const botComment = comments.data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('Storybook Preview')
);

if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}

# Create PR-specific directory structure
- name: Create PR-specific directory
run: |
mkdir -p pr-preview/pr-${{ github.event.pull_request.number }}
cp -r apps/docs/storybook-static/* pr-preview/pr-${{ github.event.pull_request.number }}/

# Upload the artifact for the deployment job
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: pr-preview
retention-days: 30

# Deploy job
deploy:
needs: build
runs-on: ubuntu-latest
if: github.event.action != 'closed'

# Use a specific environment with protection rules
# This ensures only approved PRs can deploy
environment:
name: pr-preview
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Setup Pages
uses: actions/configure-pages@v5

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

# Clean up when PR is closed
cleanup:
runs-on: ubuntu-latest
if: github.event.action == 'closed'
permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: gh-pages

- name: Delete PR Preview
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
PR_PREVIEW_PATH="pr-preview/pr-$PR_NUMBER"

if [ -d "$PR_PREVIEW_PATH" ]; then
echo "Removing PR preview at $PR_PREVIEW_PATH"
rm -rf "$PR_PREVIEW_PATH"

# Commit and push the changes
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add -A
git commit -m "Remove PR preview for PR #$PR_NUMBER" || echo "No changes to commit"
git push
else
echo "PR preview directory not found"
fi

41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Enable Corepack
run: corepack enable

- name: Install Correct Yarn Version
run: corepack prepare yarn@4.9.1 --activate

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Run Tests

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22.9.0'

- name: Setup Yarn Corepack
run: corepack enable

- name: Install dependencies
run: yarn install

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: Build packages
run: yarn build

- name: Build Storybook
run: yarn build-storybook

- name: Lint and format check
run: yarn format-and-lint

- name: Upload artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-failure
path: apps/docs/storybook-static
retention-days: 2

5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"source.fixAll.biome": "explicit",
"source.organizeImports.biome": "explicit"
},
"tailwindCSS.classAttributes": ["class", "className", "ngClass", "class:list", "wrapperClassName"]
"tailwindCSS.classAttributes": ["class", "className", "ngClass", "class:list", "wrapperClassName"],
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
Loading
Loading