Skip to content

Create deploy.yml

Create deploy.yml #5

Workflow file for this run

name: Deploy to GitHub Pages
# Trigger the workflow on pushes to the main branch and manually via the workflow dispatch
on:
push:
branches: master
workflow_dispatch:
# Define permissions for the workflow
permissions:
contents: read
pages: write
id-token: write
# Manage concurrency to avoid conflicts
concurrency:
group: pages
cancel-in-progress: false
jobs:
# Job to build the project
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Determine Package Manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
else
echo "No package manager found"
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '14'
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Install Dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Build Project
run: ${{ steps.detect-package-manager.outputs.runner }} npm run build
- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./build
# Job to deploy the project to GitHub Pages
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: github-pages
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
# The URL of the deployed page will be available in the output
with:
page_url: ${{ steps.deployment.outputs.page_url }}