DEPLOYMENT PR - FEATURE SHOWCASE #44
This file contains hidden or 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: 'yarn' | |
| - name: ⚙️ Install dependencies | |
| run: yarn install | |
| - name: Build | |
| run: | | |
| yarn dlx @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: | | |
| yarn dlx 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: | | |
| yarn dlx 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/[email protected] # 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 }}) |