Add files via upload #9
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
| # This workflow builds your Jekyll site and deploys it to GitHub Pages. | |
| # It handles only the main site deployment (from 'main' branch) | |
| # and manual deployments via workflow_dispatch. | |
| # PR preview logic has been removed. | |
| name: Jekyll Build and Deploy | |
| # Controls when the workflow will run | |
| on: | |
| # Triggers the workflow on pushes to the main branch (for main site deployment) | |
| push: | |
| branches: | |
| - main | |
| # Allows you to run this workflow manually from the Actions tab in GitHub. | |
| workflow_dispatch: | |
| inputs: | |
| target_ref: | |
| description: 'Branch name (e.g., feature/my-branch) to build/deploy. Leave empty to use the current branch (main).' | |
| required: false | |
| type: string | |
| # Define jobs | |
| jobs: | |
| # Job to perform the build and deploy | |
| deploy_site: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Allows checking out code | |
| pages: write # Allows deploying to GitHub Pages | |
| id-token: write # Required for OIDC authentication with GitHub Pages | |
| environment: | |
| name: github-pages # The default environment for GitHub Pages | |
| url: ${{ steps.deployment.outputs.page_url }} # Output URL of the deployed site | |
| steps: | |
| - name: Determine Ref for Checkout | |
| id: determine_ref | |
| run: | | |
| # Logic to determine the correct ref to checkout based on event type and inputs | |
| # For push event, checkout the main branch | |
| # For workflow_dispatch: | |
| # If target_ref is empty, use the current branch (main) | |
| # Else, checkout the specified branch name | |
| if [[ "${{ github.event_name }}" == "push" ]]; then | |
| echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_OUTPUT | |
| elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| INPUT_REF="${{ github.event.inputs.target_ref }}" | |
| if [[ -z "$INPUT_REF" ]]; then # If target_ref is empty, use the current branch | |
| echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_OUTPUT # Use github.ref for the actual branch ref | |
| else # Assume it's a branch name | |
| echo "CHECKOUT_REF=refs/heads/${INPUT_REF}" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| echo "Determined checkout ref: ${{ steps.determine_ref.outputs.CHECKOUT_REF }}" | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ steps.determine_ref.outputs.CHECKOUT_REF }} | |
| fetch-depth: 0 # Fetch all history for Jekyll (if needed by some plugins) | |
| - name: Setup Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: '3.2.2' # IMPORTANT: Ensure this matches your local Ruby version | |
| bundler-cache: true # Caches installed gems for faster builds | |
| - name: Install Jekyll dependencies | |
| run: bundle install | |
| - name: Setup Pages | |
| # This action configures the GitHub Pages environment for deployment. | |
| # It sets up necessary environment variables like GITHUB_PAGES_URL. | |
| id: pages_setup # Added an ID to access its outputs | |
| uses: actions/configure-pages@v3 | |
| - name: Build Jekyll site | |
| # CRITICAL FIX: Explicitly pass the baseurl to Jekyll build using the output from Setup Pages | |
| run: bundle exec jekyll build --trace --baseurl "${{ steps.pages_setup.outputs.base_url }}" | |
| - name: Upload artifact | |
| # Uploads the '_site' directory (your built Jekyll site) as an artifact. | |
| # This artifact will then be used by the deploy-pages action. | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: './_site' # The directory where Jekyll builds your site | |
| - name: Deploy to GitHub Pages | |
| # Deploys the uploaded artifact to GitHub Pages. | |
| # The 'id' allows us to reference its outputs, like the page_url. | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |