arranged Github workflows on deployment #7
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: 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@v4 | |
- name: Set up node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: yarn | |
- name: Set up yarn with corepack | |
run: | | |
corepack enable yarn | |
yarn --version | |
# - name: Get yarn store path | |
# id: yarn_cache | |
# run: echo "STORE_PATH=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
# - name: Set up yarn store | |
# 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 run 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 }}", | |
}); |