diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..e43fd64 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,27 @@ +name: Setup Node.js (v20) with Yarn v2 ๐Ÿš€ +description: 'Set up Node.js version 20 and enable Yarn v2 using Corepack' + +inputs: + node-version: + description: 'The version of Node.js to set up.' + required: true + default: '20' + +outputs: + node-version: + description: 'The version of Node.js that was installed.' + +runs: + using: composite + steps: + - name: Set up Node.js v${{ inputs.node-version }} ๐Ÿ’ป + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + + - name: Enable Yarn v2 โšก๏ธ + run: | + corepack enable + yarn --version + node --version + shell: bash \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c263729..d91cdb1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,52 +1,102 @@ -# Simple workflow for deploying static content to GitHub Pages -name: Deploy static content to Pages +name: ๐Ÿš€ Test & Deploy Static Content to GitHub Pages -on: - # Runs on pushes targeting the default branch - push: - branches: ['main'] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: +on: push # Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages permissions: - contents: read - pages: write - id-token: write + contents: read # Read access to repository contents + pages: write # Write access for deployment to GitHub Pages + id-token: write # Allow GitHub to issue an ID token for authentication -# Allow one concurrent deployment +# Allow only one concurrent deployment at a time concurrency: - group: 'pages' - cancel-in-progress: true + group: 'pages' # Group deployments by name for concurrency control + cancel-in-progress: true # Cancel any in-progress deployments if a new one starts jobs: - # Single deploy job since we're just deploying + # Setup environment and dependencies + setup: + name: ๐Ÿ› ๏ธ Setup Development Environment + runs-on: ubuntu-latest + outputs: + node-modules-path: ${{ steps.cache-dependencies.outputs.cache-hit }} + + steps: + - name: Checkout Repository ๐Ÿ“ฅ + uses: actions/checkout@v4 + + - name: Cache Dependencies ๐Ÿ“ฆ + uses: actions/cache@v4 + id: cache-dependencies + with: + path: node_modules + key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Setup Node.js Environment โš™๏ธ + uses: ./.github/actions/setup + with: + node-version: 20 + + - name: Install Dependencies ๐Ÿ› ๏ธ + run: yarn install --immutable + if: steps.cache-dependencies.outputs.cache-hit != 'true' # Only install if cache miss + + tests: + name: ๐Ÿ” Execute Unit Tests + needs: setup + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository ๐Ÿ“ฅ + uses: actions/checkout@v4 + + - name: Setup Node.js Environment โš™๏ธ + uses: ./.github/actions/setup + with: + node-version: 20 + + - name: Install Dependencies ๐Ÿ› ๏ธ + run: yarn install --immutable + + - name: Run Tests ๐Ÿงช + run: yarn test + deploy: + name: ๐Ÿš€ Deploy to GitHub Pages + needs: [setup, tests] + if: github.ref == 'refs/heads/main' # Only deploy from the main branch + environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} + name: github-pages # Set deployment environment to GitHub Pages + url: ${{ steps.deployment.outputs.page_url }} # Output page URL + runs-on: ubuntu-latest + steps: - - name: Checkout + - name: Checkout Repository ๐Ÿ“ฅ uses: actions/checkout@v4 - - run: corepack enable - - name: Set up Node - uses: actions/setup-node@v4 + + - name: Setup Node.js Environment โš™๏ธ + uses: ./.github/actions/setup with: node-version: 20 - cache: 'yarn' - - name: Install dependencies - run: yarn install - - name: Build - run: yarn build:demo - - name: Setup Pages + + - name: Install Dependencies ๐Ÿ› ๏ธ + run: yarn install --immutable + + - name: Build Static Content ๐Ÿ—๏ธ + run: yarn build:demo # Build the static site with Vite + + - name: Setup GitHub Pages โš™๏ธ uses: actions/configure-pages@v4 - - name: Upload artifact + + - name: Upload Build Artifacts ๐Ÿ“ฆ uses: actions/upload-pages-artifact@v3 with: - # Upload dist folder - path: './dist' - - name: Deploy to GitHub Pages + path: './dist' # Path to the build output directory + + - name: Deploy to GitHub Pages ๐ŸŒ id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@v4 # Deploy the build to GitHub Pages