|
1 | | -name: "Deploy Jekyll with GitHub Pages" |
| 1 | +# .github/workflows/deploy-pages.yml |
| 2 | +name: "Deploy Jekyll with GitHub Pages (robust)" |
2 | 3 |
|
| 4 | +# Triggers: push to main/master, manual dispatch, and periodic schedule (UTC) |
3 | 5 | on: |
4 | 6 | push: |
5 | | - branches: ["master"] |
6 | | - workflow_dispatch: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - master |
| 10 | + workflow_dispatch: {} |
7 | 11 | schedule: |
8 | | - - cron: '0 12 * * *' |
| 12 | + - cron: '0 12 * * *' # daily at 12:00 UTC (adjust if needed) |
9 | 13 |
|
| 14 | +# Least privilege for required tokens |
10 | 15 | 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) |
14 | 19 |
|
| 20 | +# Prevent concurrent runs for the same ref (avoids race conditions) |
15 | 21 | concurrency: |
16 | | - group: "pages" |
| 22 | + group: "pages-${{ github.ref }}" # isolate per-branch/ref |
17 | 23 | cancel-in-progress: false |
18 | 24 |
|
19 | 25 | jobs: |
20 | 26 | build: |
| 27 | + name: Build site (Jekyll) |
21 | 28 | runs-on: ubuntu-latest |
| 29 | + outputs: |
| 30 | + page_artifact: ${{ steps.upload-artifact.outputs.artifact-path || '' }} |
22 | 31 | steps: |
23 | | - - name: Checkout |
| 32 | + - name: Checkout repository |
24 | 33 | uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + submodules: true |
| 36 | + fetch-depth: 0 |
25 | 37 |
|
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) |
28 | 43 |
|
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 |
31 | 47 | 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 |
34 | 74 |
|
35 | 75 | - name: Upload GitHub Pages artifact |
36 | | - uses: actions/upload-pages-artifact@v3 |
| 76 | + id: upload-artifact |
| 77 | + uses: actions/upload-pages-artifact@v1 |
37 | 78 | with: |
38 | | - name: github-pages # <-- Only ONE job should use this name |
39 | 79 | path: ./_site |
| 80 | + # name is not required to be unique across repos; keep conservative naming |
| 81 | + name: java-evolution-pages |
40 | 82 |
|
41 | 83 | deploy: |
| 84 | + name: Deploy to GitHub Pages |
42 | 85 | needs: build |
43 | 86 | runs-on: ubuntu-latest |
44 | 87 | environment: |
45 | 88 | name: github-pages |
46 | | - url: ${{ steps.deployment.outputs.page_url }} |
| 89 | + url: ${{ steps.deploy.outputs.page_url || '' }} |
47 | 90 | steps: |
48 | 91 | - name: Deploy to GitHub Pages |
49 | | - id: deployment |
| 92 | + id: deploy |
50 | 93 | 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