Deploy to GitHub Pages #43
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: Deploy to GitHub Pages | |
| on: | |
| workflow_run: | |
| workflows: ['Release'] | |
| types: | |
| - completed | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| pull-requests: read | |
| concurrency: | |
| group: 'pages' | |
| cancel-in-progress: false | |
| jobs: | |
| # This job finds the SHA of the last successful deployment | |
| find_last_deployment: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| last_sha: ${{ steps.get_sha.outputs.sha }} | |
| steps: | |
| - name: Get last deployment SHA | |
| id: get_sha | |
| run: | | |
| # Install GitHub CLI if not available | |
| if ! command -v gh &> /dev/null; then | |
| echo "Installing GitHub CLI..." | |
| curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
| sudo apt update | |
| sudo apt install gh | |
| fi | |
| # Authenticate with GitHub token | |
| echo "${{ github.token }}" | gh auth login --with-token | |
| # Get the last successful deployment workflow run | |
| WORKFLOW_ID=$(gh api /repos/${{ github.repository }}/actions/workflows/deploy.yml | jq -r '.id') | |
| # Find the last successful run of the deploy workflow | |
| LAST_SHA=$(gh api "/repos/${{ github.repository }}/actions/workflows/$WORKFLOW_ID/runs?status=success&per_page=1" | jq -r '.workflow_runs[0].head_sha') | |
| # If no previous successful run, use a fallback | |
| if [ "$LAST_SHA" = "null" ] || [ -z "$LAST_SHA" ]; then | |
| echo "No previous successful deployment found. Using current SHA as reference." | |
| LAST_SHA="${{ github.sha }}" | |
| fi | |
| echo "Last successful deployment SHA: $LAST_SHA" | |
| echo "sha=$LAST_SHA" >> $GITHUB_OUTPUT | |
| check_changes: | |
| runs-on: ubuntu-latest | |
| needs: find_last_deployment | |
| outputs: | |
| should_build: ${{ steps.filter.outputs.should_build }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # For workflow_dispatch events, we always want to build | |
| - name: Set manual trigger output | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| echo "SHOULD_BUILD=true" >> $GITHUB_ENV | |
| # Only run the filter if not manually triggered | |
| - name: Filter changes | |
| if: github.event_name != 'workflow_dispatch' | |
| uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| # Compare against the last successful deployment SHA | |
| base: ${{ needs.find_last_deployment.outputs.last_sha }} | |
| # Look for changes in these patterns | |
| filters: | | |
| should_build: | |
| - '.stories.tsx' | |
| - 'landing/**' | |
| - '.storybook/**' | |
| - 'package.json' | |
| - 'landing/package.json' | |
| # Set the output for use by the build job | |
| - name: Set final output | |
| id: set_output | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "should_build=${{ steps.filter.outputs.should_build || 'false' }}" >> $GITHUB_OUTPUT | |
| fi | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: check_changes | |
| if: needs.check_changes.outputs.should_build == 'true' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Restore Bun cache | |
| uses: actions/cache@v4 | |
| id: bun-cache | |
| with: | |
| path: ~/.bun/install/cache | |
| key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }} | |
| restore-keys: | | |
| ${{ runner.os }}-bun- | |
| # Build the component library and Storybook | |
| - name: Install root dependencies | |
| run: bun install | |
| - name: Build component library | |
| run: bun run build | |
| - name: Build Storybook | |
| run: bun run build-storybook | |
| env: | |
| NODE_OPTIONS: '--max_old_space_size=4096' | |
| # Build the landing page (Vike site) | |
| - name: Install landing page dependencies | |
| working-directory: ./landing | |
| run: bun install | |
| - name: Build Vike site | |
| working-directory: ./landing | |
| run: bun run build | |
| # Prepare the deployment directory | |
| - name: Prepare deployment directory | |
| run: | | |
| mkdir -p ./deploy | |
| # Move Vike site to root of deployment directory | |
| cp -r ./landing/dist/client/* ./deploy/ | |
| # Ensure Storybook directory exists | |
| mkdir -p ./deploy/storybook | |
| # Move Storybook to /storybook subfolder | |
| cp -r ./storybook-static/* ./deploy/storybook/ | |
| # Create CNAME file for the custom domain | |
| echo "ui.bizar.re" > ./deploy/CNAME | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./deploy | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |