|
| 1 | +name: Install Ruby |
| 2 | + |
| 3 | +inputs: |
| 4 | + version: |
| 5 | + description: 'The version of Ruby to install' |
| 6 | + required: true |
| 7 | + openssl-version: |
| 8 | + description: 'The version of OpenSSL used' |
| 9 | + required: true |
| 10 | + |
| 11 | +runs: |
| 12 | + using: 'composite' |
| 13 | + steps: |
| 14 | + - name: Restore cached Ruby installation |
| 15 | + id: cache-ruby-restore |
| 16 | + uses: actions/cache/restore@v4 |
| 17 | + with: |
| 18 | + path: ~/rubies/ruby-${{ inputs.version }} |
| 19 | + key: ruby-${{ inputs.version }}-with-openssl-${{ inputs.openssl-version }} |
| 20 | + |
| 21 | + - name: Install Ruby |
| 22 | + if: steps.cache-ruby-restore.outputs.cache-hit != 'true' |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + latest_patch=$(curl -s https://cache.ruby-lang.org/pub/ruby/${{ inputs.version }}/ \ |
| 26 | + | grep -oP "ruby-${{ inputs.version }}\.\d+\.tar\.xz" \ |
| 27 | + | grep -oP "\d+(?=\.tar\.xz)" \ |
| 28 | + | sort -V | tail -n 1) |
| 29 | + wget https://cache.ruby-lang.org/pub/ruby/${{ inputs.version }}/ruby-${{ inputs.version }}.${latest_patch}.tar.xz |
| 30 | + tar -xJvf ruby-${{ inputs.version }}.${latest_patch}.tar.xz |
| 31 | + cd ruby-${{ inputs.version }}.${latest_patch} |
| 32 | + ./configure --prefix=$HOME/rubies/ruby-${{ inputs.version }} --with-openssl-dir=$HOME/openssl |
| 33 | + make |
| 34 | + make install |
| 35 | +
|
| 36 | + - name: Update PATH |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + echo "~/rubies/ruby-${{ inputs.version }}/bin" >> $GITHUB_PATH |
| 40 | +
|
| 41 | + - name: Install Bundler |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + case ${{ inputs.version }} in |
| 45 | + 2.7* | 3.*) |
| 46 | + echo "Skipping Bundler installation for Ruby ${{ inputs.version }}" |
| 47 | + ;; |
| 48 | + 2.5* | 2.6*) |
| 49 | + gem install bundler -v '~> 2.3.0' |
| 50 | + ;; |
| 51 | + *) |
| 52 | + echo "Don't know how to install Bundler for Ruby ${{ inputs.version }}" |
| 53 | + ;; |
| 54 | + esac |
| 55 | +
|
| 56 | + - name: Save Ruby installation cache |
| 57 | + if: steps.cache-ruby-restore.outputs.cache-hit != 'true' |
| 58 | + id: cache-ruby-save |
| 59 | + uses: actions/cache/save@v4 |
| 60 | + with: |
| 61 | + path: ~/rubies/ruby-${{ inputs.version }} |
| 62 | + key: ${{ steps.cache-ruby-restore.outputs.cache-primary-key }} |
| 63 | + |
| 64 | + - name: Cache Bundler Install |
| 65 | + id: cache-bundler-restore |
| 66 | + uses: actions/cache/restore@v4 |
| 67 | + env: |
| 68 | + GEMFILE: ${{ env.BUNDLE_GEMFILE || 'Gemfile' }} |
| 69 | + with: |
| 70 | + path: ~/bundler/cache |
| 71 | + key: bundler-ruby-${{ inputs.version }}-${{ inputs.openssl-version }}-${{ hashFiles(env.Gemfile, 'webauthn.gemspec') }} |
| 72 | + |
| 73 | + - name: Install dependencies |
| 74 | + shell: bash |
| 75 | + run: | |
| 76 | + bundle config set --local path ~/bundler/cache |
| 77 | + bundle install |
| 78 | +
|
| 79 | + - name: Save Bundler Install cache |
| 80 | + id: cache-bundler-save |
| 81 | + uses: actions/cache/save@v4 |
| 82 | + with: |
| 83 | + path: ~/bundler/cache |
| 84 | + key: ${{ steps.cache-bundler-restore.outputs.cache-primary-key }} |
0 commit comments