Skip to content

Commit

Permalink
fix: Add cloudflare
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Oct 12, 2023
1 parent 40f4920 commit 75d0871
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ name: ci

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

env:
CF_PROJECT_NAME: tech-docs
CF_BASE_URL: tech-docs-2ac

jobs:
checks:
if: github.event_name != 'push'
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install ⚙️
run: yarn install --frozen-lockfile
Expand All @@ -22,23 +28,34 @@ jobs:
- name: Build 🛠
run: yarn build

build-and-deploy:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Extract branch name
shell: bash
run: |
PR_NUMBER="${{ github.event.number }}"
if [ -n "$PR_NUMBER" ]
then
echo "branch_name=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "url=https://pr-${PR_NUMBER}.${{ env.CF_BASE_URL }}.pages.dev" >> $GITHUB_OUTPUT
else
echo "branch_name=" >> $GITHUB_OUTPUT
fi
id: extract_branch

- name: Deploy
uses: cloudflare/[email protected]
with:
fetch-depth: 0

- name: Install ⚙️
run: yarn install --frozen-lockfile

- name: Build 🛠
run: yarn build

- name: Deploy 🚀
uses: JamesIves/github[email protected]
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: pages deploy --project-name "${CF_PROJECT_NAME}" build ${{ steps.extract_branch.outputs.branch }} | tee output.log
postCommands: |
sed < output.log -n 's#.*Take a peek over at \(.*\)$#specific_url=\1#p' >> $GITHUB_OUTPUT
id: deploy

- name: Create commit comment
uses: mshick/add-pr-comment@v2
if: ${{ github.event.number != '' }}
with:
branch: gh-pages # The branch the action should deploy to.
folder: build # The folder the action should deploy.
message: |
### Deployed with **Cloudflare Pages** :cloud: :rocket: :ok:
- **URL**: [${{ steps.extract_branch.outputs.url }}](${{ steps.extract_branch.outputs.url }})
- **Specific**: [${{ steps.deploy.outputs.specific_url }}](${{ steps.deploy.outputs.specific_url }})

0 comments on commit 75d0871

Please sign in to comment.