back to netlify #4
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: Build and Deploy to Netlify | |
on: [ push, workflow_dispatch ] | |
env: | |
BRANCH_NAME: ${{ github.ref_name }} | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create .env File | |
run: echo "${{ secrets.ENV_FILE_CONTENT }}" > .env | |
- name: Verify .env File | |
run: cat .env | |
- uses: pnpm/action-setup@v4 | |
with: | |
version: 9 | |
- name: Install Netlify | |
run: pnpm install netlify-cli -g | |
- name: Install Dependencies | |
run: pnpm i --frozen-lockfile | |
- name: Build Application | |
run: pnpm run build | |
- name: Deploy to Netlify | |
id: netlify_deploy | |
run: | | |
prod_flag="" | |
if [ "$BRANCH_NAME" = "main" ]; then prod_flag="--prod"; fi | |
netlify deploy \ | |
--dir dist/client \ | |
--site ${{ secrets.NETLIFY_SITE_ID }} \ | |
--auth ${{ secrets.NETLIFY_API_TOKEN }} \ | |
$prod_flag \ | |
--json \ | |
> deploy_output.json | |
- name: Generate URL Preview | |
id: url_preview | |
if: ${{ env.BRANCH_NAME != 'main' }} | |
run: | | |
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) | |
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" |