Skip to content

arranged Github workflows on deployment #2

arranged Github workflows on deployment

arranged Github workflows on deployment #2

Workflow file for this run

name: Deployment to Cloudflare Pages
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
statuses: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
- name: Set up yarn with corepack
run: |
corepack enable yarn
yarn --version
- name: Get yarn cache dir
id: yarn_cache
run: echo "STORE_PATH=$(yarn store path)" >> $GITHUB_OUTPUT
uses: actions/cache@v4
with:
path: ${{ steps.yarn_cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-astro-${{ hashFiles('**/yarn-lock.yaml') }}
restore-keys: ${{ runner.os }}-astro-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build project
run: yarn build
- name: Publish to Cloudflare Pages
id: cloudflare_pages_deploy
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: my-astro-blog
directory: dist
# Optional: Enable this if you want to have GitHub Deployments triggered
# gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional: Switch what branch you are publishing to.
# By default this will be the branch which triggered this workflow
# branch: main
# Optional: Change the working directory
# workingDirectory: my-site
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
# wranglerVersion: '3'
- name: Add publish URL
uses: actions/github-script@v6
with:
script: |
const sha = context.payload.pull_request?.head.sha ?? context.sha;
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
context: 'Cloudflare Pages',
description: 'Cloudflare Pages deployment',
state: 'success',
sha,
target_url: "${{ steps.cloudflare_pages_deploy.outputs.url }}",
});