11# This workflow builds your Jekyll site and deploys it to GitHub Pages.
2- # It handles both the main site deployment (from 'main' branch)
3- # and temporary Pull Request preview deployments.
2+ # It handles only the main site deployment (from 'main' branch)
3+ # and manual deployments via workflow_dispatch.
4+ # PR preview logic has been removed.
45
56name : Jekyll Build and Deploy
67
1011 push :
1112 branches :
1213 - main
13- # Triggers the workflow on pull request events (for PR previews)
14- pull_request :
15- branches :
16- - main # PRs targeting the main branch
1714 # Allows you to run this workflow manually from the Actions tab in GitHub.
1815 workflow_dispatch :
1916 inputs :
2017 target_ref :
21- description : ' Branch name (e.g., feature/my-branch) or PR number (e.g., 123) to build/deploy. Leave empty to use the current branch.'
18+ description : ' Branch name (e.g., feature/my-branch) to build/deploy. Leave empty to use the current branch (main) .'
2219 required : false
2320 type : string
24- # Removed: default: ${{ github.ref_name }} - This caused the "github not found" error
25- cleanup_only :
26- description : ' Set to true to only perform cleanup, skipping build/deploy.'
27- required : false
28- type : boolean
29- default : false
3021
3122# Define jobs
3223jobs :
3324 # Job to perform the build and deploy
3425 deploy_site :
35- # Only run if cleanup_only is not true
36- if : github.event_name != 'workflow_dispatch' || github.event.inputs.cleanup_only == false
3726 runs-on : ubuntu-latest
3827
3928 permissions :
@@ -50,21 +39,16 @@ jobs:
5039 id : determine_ref
5140 run : |
5241 # Logic to determine the correct ref to checkout based on event type and inputs
53- # For pull_request event, checkout the head ref of the PR
5442 # For push event, checkout the main branch
5543 # For workflow_dispatch:
56- # If target_ref is a PR number (e.g., "123"), checkout 'refs/pull/123/merge'
57- # Else (if target_ref is a branch name or empty), checkout that ref
58- if [[ "${{ github.event_name }}" == "pull_request" ]]; then
59- echo "CHECKOUT_REF=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
60- elif [[ "${{ github.event_name }}" == "push" ]]; then
44+ # If target_ref is empty, use the current branch (main)
45+ # Else, checkout the specified branch name
46+ if [[ "${{ github.event_name }}" == "push" ]]; then
6147 echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_OUTPUT
6248 elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
6349 INPUT_REF="${{ github.event.inputs.target_ref }}"
6450 if [[ -z "$INPUT_REF" ]]; then # If target_ref is empty, use the current branch
6551 echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_OUTPUT # Use github.ref for the actual branch ref
66- elif [[ "$INPUT_REF" =~ ^[0-9]+$ ]]; then # Check if input is a number (PR number)
67- echo "CHECKOUT_REF=refs/pull/${INPUT_REF}/merge" >> $GITHUB_OUTPUT
6852 else # Assume it's a branch name
6953 echo "CHECKOUT_REF=refs/heads/${INPUT_REF}" >> $GITHUB_OUTPUT
7054 fi
@@ -86,18 +70,16 @@ jobs:
8670 - name : Install Jekyll dependencies
8771 run : bundle install
8872
89- - name : Build Jekyll site
90- # When GitHub Pages is configured to use GitHub Actions,
91- # 'actions/configure-pages' and 'actions/deploy-pages'
92- # automatically handle the baseurl for PR previews.
93- # For the main branch deployment, Jekyll will correctly assume root.
94- run : bundle exec jekyll build --trace
95-
9673 - name : Setup Pages
9774 # This action configures the GitHub Pages environment for deployment.
9875 # It sets up necessary environment variables like GITHUB_PAGES_URL.
76+ id : pages_setup # Added an ID to access its outputs
9977 uses : actions/configure-pages@v3
10078
79+ - name : Build Jekyll site
80+ # CRITICAL FIX: Explicitly pass the baseurl to Jekyll build using the output from Setup Pages
81+ run : bundle exec jekyll build --trace --baseurl "${{ steps.pages_setup.outputs.base_url }}"
82+
10183 - name : Upload artifact
10284 # Uploads the '_site' directory (your built Jekyll site) as an artifact.
10385 # This artifact will then be used by the deploy-pages action.
@@ -110,36 +92,3 @@ jobs:
11092 # The 'id' allows us to reference its outputs, like the page_url.
11193 id : deployment
11294 uses : actions/deploy-pages@v4
113-
114- # Job to perform cleanup for specific manual deployments (not automatically cleaned up by GitHub)
115- cleanup_deployment :
116- # Only run if cleanup_only is true and a target_ref is provided
117- if : github.event_name == 'workflow_dispatch' && github.event.inputs.cleanup_only == true && github.event.inputs.target_ref
118- runs-on : ubuntu-latest
119-
120- permissions :
121- deployments : write # Needed for deleting deployments via the API
122-
123- steps :
124- - name : Determine Cleanup Reference
125- id : determine_cleanup_ref
126- run : |
127- CLEANUP_INPUT="${{ github.event.inputs.target_ref }}"
128- if [[ "$CLEANUP_INPUT" =~ ^[0-9]+$ ]]; then
129- # Input is a PR number, cleanup target is the merge ref
130- CLEANUP_REF="refs/pull/${CLEANUP_INPUT}/merge"
131- else
132- # Input is a branch name, cleanup target is the head ref
133- CLEANUP_REF="refs/heads/${CLEANUP_INPUT}"
134- fi
135- echo "CLEANUP_REF=$CLEANUP_REF" >> $GITHUB_OUTPUT
136- echo "Determined cleanup reference: $CLEANUP_REF"
137-
138- - name : Delete GitHub Pages Deployment
139- # This action deletes a GitHub Pages deployment for a specific reference (branch/PR).
140- # It's crucial for cleaning up manual deployments not tied to a PR lifecycle.
141- uses : strumwolf/delete-deployment-environment@v2
142- with :
143- token : ${{ secrets.GITHUB_TOKEN }}
144- environment : github-pages # The environment name for GitHub Pages
145- ref : ${{ steps.determine_cleanup_ref.outputs.CLEANUP_REF }} # The branch/PR ref whose deployment you want to delete
0 commit comments