fix: Add @types/escape-html #30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cloudflare Pages Deploy | |
env: | |
ARTIFACT_NAME: blog-artifact | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
jobs: | |
# Build job | |
build: | |
runs-on: ubuntu-latest | |
name: Build Pages | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: npm | |
- name: Restore cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.next/cache | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx', '**.md') }} | |
restore-keys: | | |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- | |
- name: Install dependencies | |
run: npm ci | |
- name: Build with Next.js | |
run: npm run build | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
retention-days: 3 | |
path: ./out | |
# Deployment job | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
contents: read | |
deployments: write | |
pull-requests: write # To can create a comment in PR | |
name: Deploy to Cloudflare Pages | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download a Build Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: ./out | |
- name: Deploy | |
id: deploy | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
command: pages deploy out --project-name=blog-c3 --branch ${{ github.ref_name }} | |
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Comment PR" | |
uses: actions/github-script@v7.0.1 | |
if: github.event_name == 'pull_request' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { issue: { number: issue_number }, repo: { owner, repo } } = context; | |
const message = `### 🚀 **Preview Url** 🚀 | |
[${{ steps.deploy.outputs.deployment-url }}](${{ steps.deploy.outputs.deployment-url }})`; | |
github.rest.issues.createComment({ | |
issue_number, | |
owner, | |
repo, | |
body: message | |
}); |