|
1 | | -# This workflow uses actions that are not certified by GitHub. |
2 | | -# They are provided by a third-party and are governed by |
3 | | -# separate terms of service, privacy policy, and support |
4 | | -# documentation. |
5 | | - |
6 | | -# Sample workflow for building and deploying a Jekyll site to GitHub Pages |
7 | 1 | name: Deploy Jekyll site to Pages |
8 | 2 |
|
9 | 3 | on: |
10 | | - # Runs on pushes targeting the default branch |
11 | 4 | push: |
12 | 5 | branches: ["master"] |
13 | | - |
14 | | - # Allows you to run this workflow manually from the Actions tab |
15 | 6 | workflow_dispatch: |
16 | 7 |
|
17 | | -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
18 | 8 | permissions: |
19 | 9 | contents: read |
20 | 10 | pages: write |
21 | 11 | id-token: write |
22 | 12 |
|
23 | | -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
24 | | -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
25 | 13 | concurrency: |
26 | 14 | group: "pages" |
27 | 15 | cancel-in-progress: false |
28 | 16 |
|
| 17 | +env: |
| 18 | + RUBY_VERSION_FULL: "3.1.4" # exact version we’ll place in toolcache |
| 19 | + RUBY_VERSION_SHORT: "3.1" # what bundler/setup-ruby will request |
| 20 | + TOOLCACHE_DIR: "${{ env.RUNNER_TOOL_CACHE || '/opt/hostedtoolcache' }}" |
| 21 | + |
29 | 22 | jobs: |
30 | | - # Build job |
31 | 23 | build: |
32 | | - runs-on: ubuntu-latest |
| 24 | + # If you truly must run on your Ubuntu 24.04 self-hosted label, keep it. |
| 25 | + # For GitHub-hosted 24.04, use: runs-on: ubuntu-24.04 |
| 26 | + runs-on: ubuntu-24.04 |
33 | 27 | steps: |
34 | 28 | - name: Checkout |
35 | 29 | uses: actions/checkout@v4 |
| 30 | + |
| 31 | + # --- Bootstrap Ruby into toolcache if needed (self-hosted-detected case) --- |
| 32 | + - name: Ensure Ruby in toolcache (self-hosted safe) |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | + RUBY_DIR="$TOOLCACHE_DIR/Ruby/$RUBY_VERSION_FULL/x64" |
| 37 | + SENTINEL="$RUBY_DIR.complete" |
| 38 | + LOCK="/var/tmp/ruby-${RUBY_VERSION_FULL}.lock" |
| 39 | + echo "Toolcache dir: $TOOLCACHE_DIR" |
| 40 | + echo "Target Ruby dir: $RUBY_DIR" |
| 41 | +
|
| 42 | + if [ -f "$SENTINEL" ]; then |
| 43 | + echo "Ruby $RUBY_VERSION_FULL already present (sentinel found)." |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + # If the runner already has a working Ruby matching the short version, don't rebuild. |
| 48 | + if command -v ruby >/dev/null 2>&1; then |
| 49 | + INSTALLED="$(ruby -e 'print RUBY_VERSION' || true)" |
| 50 | + if [[ "${INSTALLED:-}" == ${RUBY_VERSION_SHORT}.* ]]; then |
| 51 | + echo "A matching Ruby ${INSTALLED} is already available on PATH; skipping toolcache build." |
| 52 | + # Let setup-ruby use this one. |
| 53 | + exit 0 |
| 54 | + fi |
| 55 | + fi |
| 56 | +
|
| 57 | + sudo mkdir -p "$RUBY_DIR" |
| 58 | + sudo chown -R "$USER":"$USER" "$TOOLCACHE_DIR" |
| 59 | +
|
| 60 | + # Serialize builds across parallel jobs |
| 61 | + exec 9>"$LOCK" |
| 62 | + if ! flock -n 9; then |
| 63 | + echo "Another job is building Ruby. Waiting on lock..." |
| 64 | + flock 9 |
| 65 | + fi |
| 66 | +
|
| 67 | + # Double-check after acquiring lock. |
| 68 | + if [ -f "$SENTINEL" ]; then |
| 69 | + echo "Ruby $RUBY_VERSION_FULL now present (sentinel found after lock)." |
| 70 | + exit 0 |
| 71 | + fi |
| 72 | +
|
| 73 | + echo "Installing build prerequisites..." |
| 74 | + sudo apt-get update -y |
| 75 | + sudo apt-get install -y \ |
| 76 | + build-essential autoconf bison \ |
| 77 | + libssl-dev zlib1g-dev libreadline-dev libyaml-dev \ |
| 78 | + libxml2-dev libxslt1-dev libffi-dev libgdbm-dev \ |
| 79 | + libdb-dev uuid-dev |
| 80 | +
|
| 81 | + echo "Installing ruby-build..." |
| 82 | + if ! command -v ruby-build >/dev/null 2>&1; then |
| 83 | + git clone --depth=1 https://github.com/rbenv/ruby-build.git |
| 84 | + sudo ./ruby-build/install.sh |
| 85 | + fi |
| 86 | +
|
| 87 | + echo "Building Ruby $RUBY_VERSION_FULL into toolcache..." |
| 88 | + ruby-build "$RUBY_VERSION_FULL" "$RUBY_DIR" |
| 89 | +
|
| 90 | + # Setup toolcache layout for setup-ruby |
| 91 | + # (create a version file; some tools look for this) |
| 92 | + echo "$RUBY_VERSION_FULL" > "$RUBY_DIR.version" |
| 93 | +
|
| 94 | + # Mark complete so other jobs don't rebuild |
| 95 | + touch "$SENTINEL" |
| 96 | +
|
| 97 | + echo "Ruby $RUBY_VERSION_FULL installed at $RUBY_DIR" |
| 98 | +
|
36 | 99 | - name: Setup Ruby |
37 | | - uses: ruby/setup-ruby@8575951200e472d5f2d95c625da0c7bec8217c42 # v1.161.0 |
| 100 | + uses: ruby/setup-ruby@v1 |
38 | 101 | with: |
39 | | - ruby-version: '3.1' # Not needed with a .ruby-version file |
40 | | - bundler-cache: true # runs 'bundle install' and caches installed gems automatically |
41 | | - cache-version: 0 # Increment this number if you need to re-download cached gems |
| 102 | + ruby-version: ${{ env.RUBY_VERSION_SHORT }} # '3.1' |
| 103 | + bundler-cache: true |
| 104 | + cache-version: 0 |
| 105 | + |
42 | 106 | - name: Setup Pages |
43 | 107 | id: pages |
44 | 108 | uses: actions/configure-pages@v4 |
| 109 | + |
45 | 110 | - name: Build with Jekyll |
46 | | - # Outputs to the './_site' directory by default |
47 | 111 | run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" |
48 | 112 | env: |
49 | 113 | JEKYLL_ENV: production |
| 114 | + |
50 | 115 | - name: Upload artifact |
51 | | - # Automatically uploads an artifact from the './_site' directory by default |
52 | 116 | uses: actions/upload-pages-artifact@v3 |
53 | 117 |
|
54 | | - # Deployment job |
55 | 118 | deploy: |
56 | 119 | environment: |
57 | 120 | name: github-pages |
58 | 121 | url: ${{ steps.deployment.outputs.page_url }} |
59 | | - runs-on: ubuntu-latest |
| 122 | + runs-on: ubuntu-24.04 |
60 | 123 | needs: build |
61 | 124 | steps: |
62 | 125 | - name: Deploy to GitHub Pages |
|
0 commit comments