|
| 1 | +name: Build Ruby for GitHub Actions |
| 2 | +on: |
| 3 | + push: |
| 4 | + paths-ignore: |
| 5 | + - README.md |
| 6 | +jobs: |
| 7 | + # Build stable releases |
| 8 | + build: |
| 9 | + if: true |
| 10 | + strategy: |
| 11 | + fail-fast: false |
| 12 | + matrix: |
| 13 | + os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-13, macos-14 ] |
| 14 | + ruby: [ruby-3.4.0, ruby-3.4.1] |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - name: Set tag name |
| 19 | + id: info |
| 20 | + run: | |
| 21 | + tag=toolcache |
| 22 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 23 | + - name: Set platform |
| 24 | + id: platform |
| 25 | + run: | |
| 26 | + platform=${{ matrix.os }} |
| 27 | + platform=${platform/macos-13/macos-latest} |
| 28 | + platform=${platform/macos-14/macos-13-arm64} |
| 29 | + echo "platform=$platform" >> $GITHUB_OUTPUT |
| 30 | + - name: Set ruby |
| 31 | + id: ruby |
| 32 | + run: | |
| 33 | + ruby=${{ matrix.ruby }} |
| 34 | + if [[ "$ruby" == [0-9]* ]]; then |
| 35 | + ruby="ruby-$ruby" |
| 36 | + fi |
| 37 | + echo "ruby=$ruby" >> $GITHUB_OUTPUT |
| 38 | + echo "archive=$ruby-${{ steps.platform.outputs.platform }}.tar.gz" >> $GITHUB_OUTPUT |
| 39 | + - name: Check if already built |
| 40 | + run: '! curl -s -L --head --fail https://github.com/ruby/ruby-builder/releases/download/${{ steps.info.outputs.tag }}/${{ steps.ruby.outputs.archive }}' |
| 41 | + |
| 42 | + - name: Set NO_DOCUMENT |
| 43 | + run: | |
| 44 | + if [[ "${{ steps.ruby.outputs.ruby }}" == ruby-1.9* ]]; then |
| 45 | + echo "NO_DOCUMENT=--no-ri --no-rdoc" >> $GITHUB_ENV |
| 46 | + else |
| 47 | + echo "NO_DOCUMENT=--no-document" >> $GITHUB_ENV |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Clone ruby-build |
| 51 | + run: git clone https://github.com/rbenv/ruby-build.git |
| 52 | + - name: Install ruby-build |
| 53 | + run: sudo ./ruby-build/install.sh |
| 54 | + |
| 55 | + - name: List versions |
| 56 | + run: ruby-build --definitions |
| 57 | + |
| 58 | + # Install packages |
| 59 | + - run: sudo apt-get install -y --no-install-recommends libyaml-dev libgdbm-dev libreadline-dev libncurses5-dev |
| 60 | + if: startsWith(matrix.os, 'ubuntu') && startsWith(steps.ruby.outputs.ruby, 'ruby-') |
| 61 | + - run: sudo apt-get install -y --no-install-recommends libyaml-dev |
| 62 | + if: startsWith(matrix.os, 'ubuntu') && startsWith(steps.ruby.outputs.ruby, 'truffleruby') |
| 63 | + |
| 64 | + - name: Install system ruby for ruby-2.5.2 |
| 65 | + run: sudo apt-get install -y --no-install-recommends ruby |
| 66 | + if: startsWith(matrix.os, 'ubuntu') && steps.ruby.outputs.ruby == 'ruby-2.5.2' |
| 67 | + |
| 68 | + - name: Set PREFIX |
| 69 | + run: | |
| 70 | + ruby="${{ steps.ruby.outputs.ruby }}" |
| 71 | + if [[ $ruby == ruby-* ]]; then |
| 72 | + # See https://github.com/ruby/setup-ruby/issues/98 |
| 73 | + arch=$(node -e 'console.log(os.arch())') |
| 74 | + echo "PREFIX=$RUNNER_TOOL_CACHE/Ruby/${ruby#ruby-}/$arch" >> $GITHUB_ENV |
| 75 | + else |
| 76 | + echo "PREFIX=$HOME/.rubies/$ruby" >> $GITHUB_ENV |
| 77 | + fi |
| 78 | + - run: rm -rf $PREFIX |
| 79 | + |
| 80 | + # macOS runners seem to default to -Werror=implicit-function-declaration, but extconf.rb expects it to be not fatal |
| 81 | + # See https://bugs.ruby-lang.org/issues/17777 for 2.6.7 |
| 82 | + - name: Set warnflags for Ruby <= 2.2 |
| 83 | + run: echo "warnflags=-Wno-error=implicit-function-declaration" >> $GITHUB_ENV |
| 84 | + if: startsWith(steps.ruby.outputs.ruby, 'ruby-1.9') || startsWith(steps.ruby.outputs.ruby, 'ruby-2.0') || startsWith(steps.ruby.outputs.ruby, 'ruby-2.1') || startsWith(steps.ruby.outputs.ruby, 'ruby-2.2') || steps.ruby.outputs.ruby == 'ruby-2.6.7' |
| 85 | + |
| 86 | + - name: Set RUBY_CONFIGURE_OPTS |
| 87 | + run: echo 'RUBY_CONFIGURE_OPTS=--enable-shared --disable-install-doc' >> $GITHUB_ENV |
| 88 | + # https://github.com/rbenv/ruby-build/discussions/1961#discussioncomment-4031745 |
| 89 | + - name: Override RUBY_CONFIGURE_OPTS if macos-arm64 ruby-3.1 |
| 90 | + run: echo 'RUBY_CONFIGURE_OPTS=--disable-shared --disable-install-doc' >> $GITHUB_ENV |
| 91 | + if: matrix.os == 'macos-14' && startsWith(steps.ruby.outputs.ruby, 'ruby-3.1') |
| 92 | + |
| 93 | + - name: Build Ruby |
| 94 | + run: ruby-build --verbose ${{ steps.ruby.outputs.ruby }} $PREFIX |
| 95 | + env: |
| 96 | + CPPFLAGS: "-DENABLE_PATH_CHECK=0" # https://github.com/actions/virtual-environments/issues/267 |
| 97 | + - name: Create archive |
| 98 | + run: tar czf ${{ steps.ruby.outputs.archive }} -C $(dirname $PREFIX) $(basename $PREFIX) |
| 99 | + - name: Install Bundler if needed |
| 100 | + run: | |
| 101 | + if [ ! -e $PREFIX/bin/bundle ]; then |
| 102 | + export PATH="$PREFIX/bin:$PATH" |
| 103 | + gem install bundler -v '~> 1' $NO_DOCUMENT |
| 104 | + fi |
| 105 | +
|
| 106 | + - run: echo "$PREFIX/bin" >> $GITHUB_PATH |
| 107 | + - run: ruby --version |
| 108 | + - run: ruby -ropen-uri -e 'puts URI.send(:open, %{https://rubygems.org/}) { |f| f.read(1024) }' |
| 109 | + - name: Install JSON gem |
| 110 | + run: gem install json -v '2.2.0' $NO_DOCUMENT |
| 111 | + - run: bundle --version |
| 112 | + - run: bundle install |
| 113 | + - run: bundle exec rake --version |
| 114 | + - run: ruby test_subprocess.rb |
| 115 | + |
| 116 | + - name: Upload Built Ruby |
| 117 | + env: |
| 118 | + GH_TOKEN: ${{ github.token }} |
| 119 | + GH_REPO: ${{ github.repository }} |
| 120 | + run: gh release upload "toolcache" "${{ steps.ruby.outputs.archive }}" |
| 121 | + |
| 122 | + buildJRubyWindows: |
| 123 | + if: false |
| 124 | + strategy: |
| 125 | + fail-fast: false |
| 126 | + matrix: |
| 127 | + os: [ windows-2019 ] |
| 128 | + jruby-version: [9.4.9.0] |
| 129 | + runs-on: ${{ matrix.os }} |
| 130 | + steps: |
| 131 | + - uses: actions/checkout@v4 |
| 132 | + - name: Set tag name |
| 133 | + id: info |
| 134 | + run: | |
| 135 | + tag=toolcache |
| 136 | + echo "tag=$tag" >> $GITHUB_OUTPUT |
| 137 | + shell: bash |
| 138 | + - name: Set platform |
| 139 | + id: platform |
| 140 | + run: | |
| 141 | + platform=${{ matrix.os }} |
| 142 | + platform=${platform/windows-*/windows-latest} |
| 143 | + echo "platform=$platform" >> $GITHUB_OUTPUT |
| 144 | + shell: bash |
| 145 | + - name: Set ruby |
| 146 | + id: ruby |
| 147 | + run: | |
| 148 | + ruby=jruby-${{ matrix.jruby-version }} |
| 149 | + echo "ruby=$ruby" >> $GITHUB_OUTPUT |
| 150 | + echo "archive=$ruby-${{ steps.platform.outputs.platform }}.tar.gz" >> $GITHUB_OUTPUT |
| 151 | + shell: bash |
| 152 | + - name: Check if already built |
| 153 | + run: '! curl -s -L --head --fail https://github.com/ruby/ruby-builder/releases/download/${{ steps.info.outputs.tag }}/${{ steps.ruby.outputs.archive }}' |
| 154 | + shell: bash |
| 155 | + |
| 156 | + - name: Set PREFIX |
| 157 | + run: echo "PREFIX=$HOME/.rubies/${{ steps.ruby.outputs.ruby }}" >> $GITHUB_ENV |
| 158 | + shell: bash |
| 159 | + - run: curl --fail -L -O 'https://repo1.maven.org/maven2/org/jruby/jruby-dist/${{ matrix.jruby-version }}/jruby-dist-${{ matrix.jruby-version }}-bin.tar.gz' |
| 160 | + shell: bash |
| 161 | + - name: Build JRuby |
| 162 | + shell: bash |
| 163 | + run: | |
| 164 | + mkdir $(dirname $PREFIX) |
| 165 | + tar xf jruby-dist-${{ matrix.jruby-version }}-bin.tar.gz -C $(dirname $PREFIX) |
| 166 | + cd $PREFIX/bin |
| 167 | + # Copy bash launcher, so 'ruby' works in bash |
| 168 | + cp jruby ruby |
| 169 | + # Create ruby.bat, so 'ruby' works in pwsh |
| 170 | + echo -en "@ECHO OFF\r\n@\"%~dp0jruby.exe\" %*\r\n" > ruby.bat |
| 171 | + - name: Create archive |
| 172 | + run: tar czf ${{ steps.ruby.outputs.archive }} -C $(dirname $PREFIX) $(basename $PREFIX) |
| 173 | + shell: bash |
| 174 | + - name: Install Bundler if needed |
| 175 | + shell: bash |
| 176 | + run: | |
| 177 | + if [ ! -e $PREFIX/bin/bundle ]; then |
| 178 | + export PATH="$PREFIX/bin:$PATH" |
| 179 | + gem install bundler -v '~> 1' --no-document |
| 180 | + fi |
| 181 | +
|
| 182 | + - run: echo "$Env:UserProfile\.rubies\${{ steps.ruby.outputs.ruby }}\bin" >> $Env:GITHUB_PATH |
| 183 | + - run: echo $Env:PATH |
| 184 | + |
| 185 | + - run: ruby --version |
| 186 | + - run: ruby -ropen-uri -e 'puts URI.send(:open, %{https://rubygems.org/}) { |f| f.read(1024) }' |
| 187 | + - run: gem install json:2.2.0 --no-document |
| 188 | + - run: bundle --version |
| 189 | + - run: bundle install |
| 190 | + - run: bundle exec rake --version |
| 191 | + |
| 192 | + - run: ruby --version |
| 193 | + shell: bash |
| 194 | + - run: ruby -ropen-uri -e 'puts URI.send(:open, %{https://rubygems.org/}) { |f| f.read(1024) }' |
| 195 | + shell: bash |
| 196 | + - run: gem install json:2.2.0 --no-document |
| 197 | + shell: bash |
| 198 | + - run: bundle --version |
| 199 | + shell: bash |
| 200 | + - run: bundle install |
| 201 | + shell: bash |
| 202 | + - run: bundle exec rake --version |
| 203 | + shell: bash |
| 204 | + |
| 205 | + - name: Upload Built Ruby |
| 206 | + env: |
| 207 | + GH_TOKEN: ${{ github.token }} |
| 208 | + GH_REPO: ${{ github.repository }} |
| 209 | + run: gh release upload "toolcache" "${{ steps.ruby.outputs.archive }}" |
| 210 | + |
| 211 | + |
| 212 | + createPullRequest: |
| 213 | + name: Create PR to setup-ruby |
| 214 | + needs: [build] |
| 215 | + if: startsWith(github.event.head_commit.message, 'Build ') |
| 216 | + runs-on: ubuntu-latest |
| 217 | + steps: |
| 218 | + - name: Set versions |
| 219 | + id: versions |
| 220 | + env: |
| 221 | + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} |
| 222 | + run: | |
| 223 | + commit_message="$COMMIT_MESSAGE" |
| 224 | + if [[ "$commit_message" =~ ^Build\ * ]]; then |
| 225 | + versions=${commit_message#* } |
| 226 | + echo "versions=$versions" >> $GITHUB_OUTPUT |
| 227 | + else |
| 228 | + exit 2 |
| 229 | + fi |
| 230 | + - uses: ruby/ruby-builder/.github/actions/create-pr-to-setup-ruby@master |
| 231 | + with: |
| 232 | + versions: ${{ steps.versions.outputs.versions }} |
| 233 | + title: Add ${{ steps.versions.outputs.versions }} |
| 234 | + token: ${{ secrets.CHECK_NEW_RELEASES_TOKEN }} |
0 commit comments