1- name : " Deploy Jekyll with GitHub Pages (robust)"
1+ # .github/workflows/jekyll-pages.yml
2+ name : Deploy Jekyll with GitHub Pages (robust)
23
34on :
45 push :
5- branches :
6- - main
7- - master
6+ branches : [ main, master ]
87 workflow_dispatch : {}
98 schedule :
10- # Run daily at 3:00 AM IST (21:30 UTC previous day)
11- - cron : ' 30 21 * * *'
9+ # Daily at 3:00 AM IST (21:30 UTC previous day)
10+ - cron : " 30 21 * * *"
1211
12+ # Least privilege for Pages
1313permissions :
1414 contents : read
1515 pages : write
1616 id-token : write
1717
18+ # Prevent overlapping deploys per ref
1819concurrency :
19- group : " pages-${{ github.ref }}"
20+ group : pages-${{ github.ref }}
2021 cancel-in-progress : false
2122
2223jobs :
2324 build :
25+ # 🚫 Never run from forks / external PRs
26+ if : >
27+ github.repository == 'Someshdiwan/JavaEvolution-Learning-Growing-Mastering' &&
28+ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
2429 name : Build site (Jekyll)
2530 runs-on : ubuntu-latest
2631 timeout-minutes : 30
32+
2733 steps :
28- - name : Checkout repository
34+ - name : Checkout
2935 uses : actions/checkout@v4
3036 with :
3137 submodules : true
3238 fetch-depth : 0
3339
34- - name : Setup Pages (configure Pages environment)
40+ - name : Configure Pages
3541 uses : actions/configure-pages@v5
3642
3743 - name : Detect Gemfile location
38- id : detect_gemfile
44+ id : detect
45+ shell : bash
3946 run : |
4047 if [ -f "site/Gemfile" ]; then
41- echo "gem_dir=site" >> $GITHUB_OUTPUT
48+ echo "gem_dir=site" >> " $GITHUB_OUTPUT"
4249 echo "Found Gemfile in site/"
4350 elif [ -f "Gemfile" ]; then
44- echo "gem_dir=." >> $GITHUB_OUTPUT
51+ echo "gem_dir=." >> " $GITHUB_OUTPUT"
4552 echo "Found Gemfile in repo root"
4653 else
47- echo "gem_dir=NONE" >> $GITHUB_OUTPUT
48- echo "No Gemfile found in site/ or repo root — will use Jekyll builder action fallback."
54+ echo "gem_dir=NONE" >> " $GITHUB_OUTPUT"
55+ echo "No Gemfile found; will use jekyll-build-pages fallback."
4956 fi
5057
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' }}
58+ # Fast path: use the repo's Gemfile (caches automatically)
59+ - name : Setup Ruby (bundler cache )
60+ if : ${{ steps.detect .outputs.gem_dir != 'NONE' }}
5461 uses : ruby/setup-ruby@v1
5562 with :
5663 ruby-version : ' 3.2'
57- bundler-cache : false
58-
59- - name : Cache bundler gems (only when Gemfile present)
60- if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
61- uses : actions/cache@v4
62- id : cache-bundler
63- with :
64- path : vendor/bundle
65- key : ${{ runner.os }}-gems-${{ steps.detect_gemfile.outputs.gem_dir }}-${{ hashFiles(format('{0}/Gemfile.lock', steps.detect_gemfile.outputs.gem_dir)) }}
66- restore-keys : |
67- ${{ runner.os }}-gems-${{ steps.detect_gemfile.outputs.gem_dir }}-
68-
69- - name : Install Ruby gems with Bundler (only when Gemfile present)
70- if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
71- run : |
72- echo "Using Gemfile from: ${{ steps.detect_gemfile.outputs.gem_dir }}"
73- cd ${{ steps.detect_gemfile.outputs.gem_dir }}
74- bundle config set --local path 'vendor/bundle'
75- # retry logic to cope with transient network errors
76- bundle install --jobs 4 --retry 3
77- shell : bash
64+ bundler-cache : true
65+ # cache & install are scoped to where the Gemfile lives
66+ working-directory : ${{ steps.detect.outputs.gem_dir }}
7867
79- - name : Build site with Bundler (only when Gemfile present)
80- if : ${{ steps.detect_gemfile.outputs.gem_dir != 'NONE' }}
81- run : |
82- cd ${{ steps.detect_gemfile.outputs.gem_dir }}
83- echo "Building Jekyll with bundle exec..."
84- bundle exec jekyll build --source . --destination ../_site
68+ - name : Build with bundle exec
69+ if : ${{ steps.detect.outputs.gem_dir != 'NONE' }}
70+ working-directory : ${{ steps.detect.outputs.gem_dir }}
8571 env :
8672 JEKYLL_ENV : production
8773 shell : bash
74+ run : |
75+ echo "Building Jekyll from $(pwd)…"
76+ bundle exec jekyll build --source . --destination "${GITHUB_WORKSPACE}/_site"
8877
89- # Fallback: if there's no Gemfile, use the jekyll-build-pages action (best-effort )
78+ # Fallback: no Gemfile; use the official builder (looks in ./site by default )
9079 - name : Build with actions/jekyll-build-pages (fallback)
91- if : ${{ steps.detect_gemfile .outputs.gem_dir == 'NONE' }}
80+ if : ${{ steps.detect .outputs.gem_dir == 'NONE' }}
9281 uses : actions/jekyll-build-pages@v1
9382 with :
9483 source : ./site
9584 destination : ./_site
9685
9786 - name : Validate _site exists
87+ shell : bash
9888 run : |
9989 if [ ! -d "_site" ]; then
100- echo "_site wasn't generated — failing the job ."
90+ echo "::error:: _site was not generated ."
10191 ls -la
10292 exit 1
10393 fi
94+ echo "✅ _site generated."
10495
10596 - name : Upload Pages artifact
10697 uses : actions/upload-pages-artifact@v3
@@ -109,17 +100,21 @@ jobs:
109100 name : java-evolution-pages
110101
111102 deploy :
103+ # 🚫 Never run from forks / external PRs
104+ if : >
105+ github.repository == 'Someshdiwan/JavaEvolution-Learning-Growing-Mastering' &&
106+ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false)
112107 name : Deploy to GitHub Pages
113108 needs : build
114109 runs-on : ubuntu-latest
115110 environment :
116111 name : github-pages
117112 steps :
118- - name : Deploy to GitHub Pages
113+ - name : Deploy
119114 id : deployment
120115 uses : actions/deploy-pages@v4
121116 with :
122117 artifact_name : java-evolution-pages
123118
124- - name : Output deploy URL
119+ - name : Show URL
125120 run : echo "Deployed to ${{ steps.deployment.outputs.page_url }}"
0 commit comments