Skip to content

ci(pages): update GitHub Actions to artifact-v4-compatible workflow #1533

ci(pages): update GitHub Actions to artifact-v4-compatible workflow

ci(pages): update GitHub Actions to artifact-v4-compatible workflow #1533

name: "Deploy Jekyll with GitHub Pages (robust: Gemfile auto-detect)"
on:
push:
branches:
- main
- master
workflow_dispatch: {}
schedule:
- cron: '0 12 * * *'
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages-${{ github.ref }}"
cancel-in-progress: false
jobs:
build:
name: Build site (Jekyll)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Detect Gemfile location
id: gemfile
run: |
# Prefer site/Gemfile if it exists
if [ -f "site/Gemfile" ]; then
echo "gemfile_dir=site" >> $GITHUB_OUTPUT
echo "Found Gemfile in site/ directory."
elif [ -f "Gemfile" ]; then
echo "gemfile_dir=." >> $GITHUB_OUTPUT
echo "Found Gemfile in repo root."
else
echo "No Gemfile found in repo root or site/ — failing early."
ls -la
exit 2
fi
- name: Setup Ruby (for Jekyll)
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: false # we use explicit cache step below
- name: Cache bundler gems (auto target)
uses: actions/cache@v4
id: cache-bundler
with:
path: vendor/bundle
# If Gemfile.lock is under site/, use that; else root path is used.
key: ${{ runner.os }}-gems-${{ steps.gemfile.outputs.gemfile_dir }}-${{ hashFiles(format('{0}/Gemfile.lock', steps.gemfile.outputs.gemfile_dir)) }}
restore-keys: |
${{ runner.os }}-gems-${{ steps.gemfile.outputs.gemfile_dir }}-
- name: Install Ruby gems (bundle install)
run: |
echo "Using Gemfile from: ${{ steps.gemfile.outputs.gemfile_dir }}"
cd ${{ steps.gemfile.outputs.gemfile_dir }}
bundle config set --local path 'vendor/bundle'
bundle install --jobs 4 --retry 3
shell: bash
- name: Build Jekyll site
run: |
echo "Building Jekyll from site/ to _site/"
# If your Jekyll source is in 'site', build from there; otherwise build from repository root.
if [ "${{ steps.gemfile.outputs.gemfile_dir }}" = "site" ]; then
cd site
bundle exec jekyll build --source . --destination ../_site
else
bundle exec jekyll build --source site --destination _site || bundle exec jekyll build --destination _site
fi
env:
JEKYLL_ENV: production
shell: bash
- name: Validate build
run: |
if [ ! -d "_site" ]; then
echo "_site wasn't generated — failing the job."
exit 1
fi
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./_site
name: java-evolution-pages
deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
steps:
- name: Deploy to GitHub Pages
id: deploy
uses: actions/deploy-pages@v4
with:
artifact_name: java-evolution-pages
- name: Announce deploy URL
run: echo "Deployed to ${{ steps.deploy.outputs.page_url }}"