Integrate CI/CD Workflow with GitHub Actions #2
Workflow file for this run
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
# Workflow for deploying static content to GitHub Pages using GitHub Actions | |
# it will also run linting and unit tests before deploying | |
# the BYOB package is used to update and create custom status badges | |
name: Lint, Test & Deploy | |
on: | |
# Runs on pushes targeting the main branch | |
push: | |
branches: ['main'] | |
# Ignores changes in the .md, .env.example and .gitignore files | |
paths-ignore: | |
- '**/*.md' | |
- '**/*.env.example' | |
- '.gitignore' | |
pull_request: | |
branches: ['main'] | |
paths-ignore: | |
- '**/*.md' | |
- '**/*.env.example' | |
- '.gitignore' | |
env: | |
CI: true | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages & create status badges | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
# Allow one concurrent deployment | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: true | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache npm modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- name: Install dependencies | |
run: npm ci | |
lint: | |
needs: setup | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: npm ci | |
- name: Lint | |
run: npm run lint | |
- name: Update lint Badge | |
uses: RubbaBoy/BYOB@v1.3.0 | |
if: ${{ always() }} | |
with: | |
name: lint | |
status: ${{ job.status }} | |
color: ${{ job.status == 'success' && '31A802' || job.status == 'failure' && 'D10007' || 'E0A607' }} | |
label: 'Lint Status' | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
unit-test: | |
name: Unit Test | |
needs: setup | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: npm ci | |
- name: Test | |
run: npm run test-unit | |
- name: Update test Badge | |
uses: RubbaBoy/BYOB@v1.3.0 | |
if: ${{ always() }} | |
with: | |
name: unit-test | |
status: ${{ job.status }} | |
color: ${{ job.status == 'success' && '31A802' || job.status == 'failure' && 'D10007' || 'E0A607' }} | |
label: 'Unit Test Status' | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
deploy: | |
needs: [unit-test, lint, setup] | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install | |
run: npm ci | |
- name: Build Vite | |
run: npm run build | |
- name: Setup Pages | |
uses: actions/configure-pages@v2 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v1 | |
with: | |
# Upload build file | |
path: './dist' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v1 | |
- name: Update deploy Badge | |
uses: RubbaBoy/BYOB@v1.3.0 | |
if: ${{ always() }} | |
with: | |
name: deploy | |
status: ${{ job.status }} | |
color: ${{ job.status == 'success' && '31A802' || job.status == 'failure' && 'D10007' || 'E0A607' }} | |
label: 'Deployment Status' | |
github_token: ${{ secrets.GITHUB_TOKEN }} |