Skip to content

Commit 141b942

Browse files
committed
ci(pages): robust GitHub Actions workflow for Jekyll build & Pages deploy
- Use ruby/setup-ruby and Bundler for reproducible builds - Cache gems (actions/cache) and add retry logic - Build site from site/ to _site/ and upload artifact - Deploy artifact with actions/deploy-pages - Support main/master, schedule and manual dispatch Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 5cd67ad commit 141b942

File tree

1 file changed

+67
-19
lines changed

1 file changed

+67
-19
lines changed
Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,98 @@
1-
name: "Deploy Jekyll with GitHub Pages"
1+
# .github/workflows/deploy-pages.yml
2+
name: "Deploy Jekyll with GitHub Pages (robust)"
23

4+
# Triggers: push to main/master, manual dispatch, and periodic schedule (UTC)
35
on:
46
push:
5-
branches: ["master"]
6-
workflow_dispatch:
7+
branches:
8+
- main
9+
- master
10+
workflow_dispatch: {}
711
schedule:
8-
- cron: '0 12 * * *'
12+
- cron: '0 12 * * *' # daily at 12:00 UTC (adjust if needed)
913

14+
# Least privilege for required tokens
1015
permissions:
11-
contents: read
12-
pages: write
13-
id-token: write
16+
contents: read # read repo contents to build
17+
pages: write # allow publishing to GitHub Pages
18+
id-token: write # for OIDC if you need it later (optional)
1419

20+
# Prevent concurrent runs for the same ref (avoids race conditions)
1521
concurrency:
16-
group: "pages"
22+
group: "pages-${{ github.ref }}" # isolate per-branch/ref
1723
cancel-in-progress: false
1824

1925
jobs:
2026
build:
27+
name: Build site (Jekyll)
2128
runs-on: ubuntu-latest
29+
outputs:
30+
page_artifact: ${{ steps.upload-artifact.outputs.artifact-path || '' }}
2231
steps:
23-
- name: Checkout
32+
- name: Checkout repository
2433
uses: actions/checkout@v4
34+
with:
35+
submodules: true
36+
fetch-depth: 0
2537

26-
- name: Setup Pages
27-
uses: actions/configure-pages@v5
38+
- name: Set up Ruby (for Jekyll)
39+
uses: ruby/setup-ruby@v1
40+
with:
41+
ruby-version: '3.2' # pick an appropriate Ruby version for your site
42+
bundler-cache: true # optional: automatically caches gems (fallback)
2843

29-
- name: Build with Jekyll
30-
uses: actions/jekyll-build-pages@v1
44+
# If you prefer explicit caching control, here's a cache step for vendor/bundle:
45+
- name: Cache bundler gems
46+
uses: actions/cache@v4
3147
with:
32-
source: ./site # Your site folder
33-
destination: ./_site # Output folder
48+
path: vendor/bundle
49+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
50+
restore-keys: |
51+
${{ runner.os }}-gems-
52+
53+
- name: Configure Bundler & install dependencies
54+
run: |
55+
# Use vendor/bundle for reproducible builds and to make cache effective
56+
bundle config set --local path 'vendor/bundle'
57+
# Install with retries for network resilience
58+
bundle install --jobs 4 --retry 3
59+
60+
- name: Build Jekyll site
61+
run: |
62+
# Explicit source/destination keeps things deterministic
63+
bundle exec jekyll build --source site --destination _site
64+
env:
65+
# Ensure Jekyll sees production-like environment
66+
JEKYLL_ENV: production
67+
68+
- name: Validate _site exists
69+
run: |
70+
if [ ! -d "_site" ]; then
71+
echo "_site wasn't generated — failing the job."
72+
exit 1
73+
fi
3474
3575
- name: Upload GitHub Pages artifact
36-
uses: actions/upload-pages-artifact@v3
76+
id: upload-artifact
77+
uses: actions/upload-pages-artifact@v1
3778
with:
38-
name: github-pages # <-- Only ONE job should use this name
3979
path: ./_site
80+
# name is not required to be unique across repos; keep conservative naming
81+
name: java-evolution-pages
4082

4183
deploy:
84+
name: Deploy to GitHub Pages
4285
needs: build
4386
runs-on: ubuntu-latest
4487
environment:
4588
name: github-pages
46-
url: ${{ steps.deployment.outputs.page_url }}
89+
url: ${{ steps.deploy.outputs.page_url || '' }}
4790
steps:
4891
- name: Deploy to GitHub Pages
49-
id: deployment
92+
id: deploy
5093
uses: actions/deploy-pages@v4
94+
with:
95+
artifact_name: java-evolution-pages
96+
97+
- name: Output deploy URL
98+
run: echo "Deployed to ${{ steps.deploy.outputs.page_url }}"

0 commit comments

Comments
 (0)