Skip to content

chore(deps): update github artifact actions (major) #323

chore(deps): update github artifact actions (major)

chore(deps): update github artifact actions (major) #323

name: Preview Deploy
on:
pull_request:
types: [opened, synchronize, reopened, closed]
permissions:
contents: write
pull-requests: write
jobs:
deploy-preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install mise
uses: jdx/mise-action@v2
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Compute preview version
run: |
NEXT_VERSION=$(bunx release-it --release-version --ci 2>/dev/null || cat package.json | grep '"version"' | head -1 | sed 's/.*"\([0-9][^"]*\)".*/\1/')
SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | head -c 7)
echo "PREVIEW_VERSION=${NEXT_VERSION}-pr.${{ github.event.pull_request.number }}+${SHORT_SHA}" >> $GITHUB_ENV
- name: Build web app
run: |
cd packages/web
npx vite build
env:
VITE_BASE_PATH: /cept/pr-${{ github.event.pull_request.number }}/
VITE_APP_VERSION: ${{ env.PREVIEW_VERSION }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO_URL: ${{ github.event.repository.html_url }}
PRODUCTION_URL: https://nsheaps.github.io/cept/app/
VITE_IS_PREVIEW: 'true'
HEAD_BRANCH: ${{ github.event.pull_request.head.ref }}
- name: Deploy to GitHub Pages subdirectory
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
DEPLOY_DIR="pr-${PR_NUMBER}"
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Fetch gh-pages branch or create it
# Discard working tree changes since the build is already complete
git checkout -- .
git fetch origin gh-pages || true
if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
git checkout -B gh-pages origin/gh-pages
else
git checkout --orphan gh-pages
fi
# Clean the PR directory and copy new build
rm -rf "${DEPLOY_DIR}"
mkdir -p "${DEPLOY_DIR}"
cp -r packages/web/dist/* "${DEPLOY_DIR}/"
# Copy shared site-level 404 router if not already present
if [ ! -f 404.html ]; then
git show origin/main:.github/pages/404.html > 404.html
git add 404.html
fi
# Commit and push
git add "${DEPLOY_DIR}"
git commit -m "Deploy preview for PR #${PR_NUMBER}" --allow-empty
git push origin gh-pages
- name: Comment PR with preview URL
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://nsheaps.github.io/cept/pr-${prNumber}/`;
const body = `## Preview Deployment\n\nThe web app for this PR has been deployed:\n\n**[Open Preview](${previewUrl})**\n\nUse this to verify the app works correctly, especially for dependency updates.`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body.includes('Preview Deployment'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}
cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- name: Remove PR preview directory
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
DEPLOY_DIR="pr-${PR_NUMBER}"
if [ -d "${DEPLOY_DIR}" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
rm -rf "${DEPLOY_DIR}"
git add -A
git commit -m "Clean up preview for PR #${PR_NUMBER}" --allow-empty
git push origin gh-pages
fi