1- name : " Deploy Jekyll with GitHub Pages (robust: Gemfile auto-detect )"
1+ name : " Deploy Jekyll with GitHub Pages (robust)"
22
33on :
44 push :
77 - master
88 workflow_dispatch : {}
99 schedule :
10- - cron : ' 0 12 * * *'
10+ # Run daily at 3:00 AM IST (21:30 UTC previous day)
11+ - cron : ' 30 21 * * *'
1112
1213permissions :
1314 contents : read
@@ -22,71 +23,82 @@ jobs:
2223 build :
2324 name : Build site (Jekyll)
2425 runs-on : ubuntu-latest
26+ timeout-minutes : 30
2527 steps :
2628 - name : Checkout repository
2729 uses : actions/checkout@v4
2830 with :
2931 submodules : true
3032 fetch-depth : 0
3133
34+ - name : Setup Pages (configure Pages environment)
35+ uses : actions/configure-pages@v5
36+
3237 - name : Detect Gemfile location
33- id : gemfile
38+ id : detect_gemfile
3439 run : |
35- # Prefer site/Gemfile if it exists
3640 if [ -f "site/Gemfile" ]; then
37- echo "gemfile_dir =site" >> $GITHUB_OUTPUT
38- echo "Found Gemfile in site/ directory. "
41+ echo "gem_dir =site" >> $GITHUB_OUTPUT
42+ echo "Found Gemfile in site/"
3943 elif [ -f "Gemfile" ]; then
40- echo "gemfile_dir =." >> $GITHUB_OUTPUT
41- echo "Found Gemfile in repo root. "
44+ echo "gem_dir =." >> $GITHUB_OUTPUT
45+ echo "Found Gemfile in repo root"
4246 else
43- echo "No Gemfile found in repo root or site/ — failing early."
44- ls -la
45- exit 2
47+ echo "gem_dir=NONE" >> $GITHUB_OUTPUT
48+ echo "No Gemfile found in site/ or repo root — will use Jekyll builder action fallback."
4649 fi
4750
48- - name : Setup Ruby (for Jekyll)
51+ # If Gemfile exists, set up Ruby + Bundler and build with bundle exec
52+ - name : Set up Ruby (only when Gemfile present)
53+ if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
4954 uses : ruby/setup-ruby@v1
5055 with :
5156 ruby-version : ' 3.2'
52- bundler-cache : false # we use explicit cache step below
57+ bundler-cache : false
5358
54- - name : Cache bundler gems (auto target)
59+ - name : Cache bundler gems (only when Gemfile present)
60+ if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
5561 uses : actions/cache@v4
5662 id : cache-bundler
5763 with :
5864 path : vendor/bundle
59- # If Gemfile.lock is under site/, use that; else root path is used.
60- key : ${{ runner.os }}-gems-${{ steps.gemfile.outputs.gemfile_dir }}-${{ hashFiles(format('{0}/Gemfile.lock', steps.gemfile.outputs.gemfile_dir)) }}
65+ key : ${{ runner.os }}-gems-${{ steps.detect_gemfile.outputs.gem_dir }}-${{ hashFiles(format('{0}/Gemfile.lock', steps.detect_gemfile.outputs.gem_dir)) }}
6166 restore-keys : |
62- ${{ runner.os }}-gems-${{ steps.gemfile .outputs.gemfile_dir }}-
67+ ${{ runner.os }}-gems-${{ steps.detect_gemfile .outputs.gem_dir }}-
6368
64- - name : Install Ruby gems (bundle install)
69+ - name : Install Ruby gems with Bundler (only when Gemfile present)
70+ if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
6571 run : |
66- echo "Using Gemfile from: ${{ steps.gemfile .outputs.gemfile_dir }}"
67- cd ${{ steps.gemfile .outputs.gemfile_dir }}
72+ echo "Using Gemfile from: ${{ steps.detect_gemfile .outputs.gem_dir }}"
73+ cd ${{ steps.detect_gemfile .outputs.gem_dir }}
6874 bundle config set --local path 'vendor/bundle'
75+ # retry logic to cope with transient network errors
6976 bundle install --jobs 4 --retry 3
7077 shell : bash
7178
72- - name : Build Jekyll site
79+ - name : Build site with Bundler (only when Gemfile present)
80+ if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
7381 run : |
74- echo "Building Jekyll from site/ to _site/"
75- # If your Jekyll source is in 'site', build from there; otherwise build from repository root.
76- if [ "${{ steps.gemfile.outputs.gemfile_dir }}" = "site" ]; then
77- cd site
78- bundle exec jekyll build --source . --destination ../_site
79- else
80- bundle exec jekyll build --source site --destination _site || bundle exec jekyll build --destination _site
81- fi
82+ cd ${{ steps.detect_gemfile.outputs.gem_dir }}
83+ echo "Building Jekyll with bundle exec..."
84+ bundle exec jekyll build --source . --destination ../_site
8285 env :
8386 JEKYLL_ENV : production
8487 shell : bash
8588
86- - name : Validate build
89+ # Fallback: if there's no Gemfile, use the jekyll-build-pages action (best-effort)
90+ - name : Build with actions/jekyll-build-pages (fallback)
91+ if : ${{ steps.detect_gemfile.outputs.gem_dir == 'NONE' }}
92+ uses : actions/jekyll-build-pages@v1
93+ with :
94+ source : ./site
95+ destination : ./_site
96+
97+ - name : Validate _site exists
8798 run : |
8899 if [ ! -d "_site" ]; then
89100 echo "_site wasn't generated — failing the job."
101+ ls -la
90102 exit 1
91103 fi
92104
@@ -104,10 +116,10 @@ jobs:
104116 name : github-pages
105117 steps :
106118 - name : Deploy to GitHub Pages
107- id : deploy
119+ id : deployment
108120 uses : actions/deploy-pages@v4
109121 with :
110122 artifact_name : java-evolution-pages
111123
112- - name : Announce deploy URL
113- run : echo "Deployed to ${{ steps.deploy .outputs.page_url }}"
124+ - name : Output deploy URL
125+ run : echo "Deployed to ${{ steps.deployment .outputs.page_url }}"
0 commit comments