Update README.md (#5) #25
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: Lint, Test, Build | |
on: | |
pull_request: | |
branches: | |
- 'main' | |
push: | |
branches: | |
- 'main' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
environment: main | |
steps: | |
- 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}.${{ secrets.CF_BASE_URL }}.pages.dev" >> $GITHUB_OUTPUT | |
else | |
if [ "${{ github.ref }}" = "refs/heads/develop" ] | |
then | |
echo "branch_name=develop" >> $GITHUB_OUTPUT | |
echo "url=https://develop.${{ secrets.CF_BASE_URL }}.pages.dev" >> $GITHUB_OUTPUT | |
else | |
echo "branch_name=" >> $GITHUB_OUTPUT | |
fi | |
fi | |
id: extract_branch | |
- uses: actions/checkout@v4 # Updated to the latest version | |
- uses: actions/setup-node@v3 # Latest version as of now | |
with: | |
node-version: '22.12.0' | |
cache: 'npm' | |
- name: ⚙️ Install dependencies | |
run: npm install | |
- name: Build | |
run: | | |
npx @cloudflare/next-on-pages | |
- name: 'Deploy release' | |
if: ${{ steps.extract_branch.outputs.branch_name == '' }} | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
run: | | |
npx wrangler pages deploy --project-name "${{ secrets.CF_PROJECT_NAME }}" .vercel/output/static | |
- name: Deploy ${{ steps.extract_branch.outputs.branch_name }} (PR) | |
if: ${{ steps.extract_branch.outputs.branch_name != '' }} | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} | |
run: | | |
npx wrangler pages deploy --project-name "${{ secrets.CF_PROJECT_NAME }}" --branch "${{ steps.extract_branch.outputs.branch_name }}" .vercel/output/static | tee output.log | |
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.5.1 # Updated to latest version | |
if: ${{ steps.extract_branch.outputs.branch_name != '' }} | |
with: | |
message: | | |
### Deployed with **Cloudflare Pages** :cloud: :rocket: :ok: | |
- **URL**: [${{ steps.extract_branch.outputs.url }}](${{ steps.extract_branch.outputs.url }}) |