|
| 1 | +name: "[Rails] Release" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - rails-v* |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry_run: |
| 10 | + description: "Build and test the gem without publishing it" |
| 11 | + type: boolean |
| 12 | + default: true |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + test: |
| 20 | + name: Ruby ${{ matrix.ruby-version }} / ${{ matrix.pipeline }} |
| 21 | + runs-on: ubuntu-24.04 |
| 22 | + timeout-minutes: 30 |
| 23 | + |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + # The boundaries: the floor the gemspec declares, and the newest. |
| 28 | + ruby-version: ["3.2", "4.0"] |
| 29 | + pipeline: [propshaft, sprockets] |
| 30 | + |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v7 |
| 33 | + |
| 34 | + - name: Set up Ruby & Rust |
| 35 | + uses: oxidize-rb/actions/setup-ruby-and-rust@v1.4.4 |
| 36 | + with: |
| 37 | + ruby-version: ${{ matrix.ruby-version }} |
| 38 | + bundler-cache: false |
| 39 | + cargo-cache: true |
| 40 | + cache-version: v1-${{ matrix.ruby-version }} |
| 41 | + working-directory: ./bindings/ruby |
| 42 | + |
| 43 | + # The wrapper depends on the sibling gem by path, so its extension has to |
| 44 | + # exist before the wrapper's bundle resolves. |
| 45 | + - name: Build the native extension |
| 46 | + run: | |
| 47 | + bundle install |
| 48 | + bundle exec rake compile |
| 49 | + working-directory: ./bindings/ruby |
| 50 | + |
| 51 | + - name: Install dependencies |
| 52 | + run: bundle install |
| 53 | + working-directory: ./bindings/ruby/rails |
| 54 | + |
| 55 | + - name: Unit specs |
| 56 | + run: bundle exec rake spec |
| 57 | + working-directory: ./bindings/ruby/rails |
| 58 | + |
| 59 | + - name: Integration spec |
| 60 | + run: bundle exec rspec spec/integration |
| 61 | + working-directory: ./bindings/ruby/rails |
| 62 | + env: |
| 63 | + PIPELINE: ${{ matrix.pipeline }} |
| 64 | + |
| 65 | + rails-release: |
| 66 | + needs: test |
| 67 | + runs-on: ubuntu-24.04 |
| 68 | + env: |
| 69 | + # A manual run from a branch has no version to release. |
| 70 | + PUBLISH: ${{ !inputs.dry_run && startsWith(github.ref, 'refs/tags/') }} |
| 71 | + |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v7 |
| 74 | + |
| 75 | + - name: Set up Ruby |
| 76 | + uses: ruby/setup-ruby@v1 |
| 77 | + with: |
| 78 | + ruby-version: "3.4" |
| 79 | + |
| 80 | + - name: Extract Version |
| 81 | + run: echo "version=${GITHUB_REF#refs/tags/rails-v}" >> $GITHUB_ENV |
| 82 | + |
| 83 | + # Publishing a gem whose version does not match its tag cannot be undone. |
| 84 | + - name: Check the tag matches the gem version |
| 85 | + if: startsWith(github.ref, 'refs/tags/') |
| 86 | + working-directory: ./bindings/ruby/rails |
| 87 | + run: | |
| 88 | + gem_version=$(ruby -r ./lib/css_inline/rails/version -e "print CSSInline::Rails::VERSION") |
| 89 | + if [ "$gem_version" != "${{ env.version }}" ]; then |
| 90 | + echo "::error::Tag says ${{ env.version }}, version.rb says ${gem_version}" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Build gem |
| 95 | + working-directory: ./bindings/ruby/rails |
| 96 | + run: gem build css_inline-rails.gemspec |
| 97 | + |
| 98 | + # `spec.files` is a glob, so a new file in an unlisted directory would be |
| 99 | + # missing from the gem and only fail once someone installed it. |
| 100 | + - name: Check every source file was packaged |
| 101 | + working-directory: ./bindings/ruby/rails |
| 102 | + run: | |
| 103 | + gem spec css_inline-rails-*.gem files | sed -n 's/^- //p' | sort > packaged.txt |
| 104 | + find lib -name '*.rb' | sort > on-disk.txt |
| 105 | + missing=$(comm -13 packaged.txt on-disk.txt) |
| 106 | + if [ -n "$missing" ]; then |
| 107 | + echo "::error::Not packaged by the gemspec:" |
| 108 | + echo "$missing" |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | +
|
| 112 | + - name: GitHub Release |
| 113 | + if: env.PUBLISH == 'true' |
| 114 | + uses: softprops/action-gh-release@v3 |
| 115 | + with: |
| 116 | + make_latest: false |
| 117 | + draft: true |
| 118 | + name: "[Rails] Release ${{ env.version }}" |
| 119 | + files: ./bindings/ruby/rails/*.gem |
| 120 | + |
| 121 | + - name: Publish to RubyGems |
| 122 | + if: env.PUBLISH == 'true' |
| 123 | + working-directory: ./bindings/ruby/rails |
| 124 | + run: | |
| 125 | + mkdir -p $HOME/.gem |
| 126 | + touch $HOME/.gem/credentials |
| 127 | + chmod 0600 $HOME/.gem/credentials |
| 128 | + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials |
| 129 | + gem push css_inline-rails-*.gem |
| 130 | + env: |
| 131 | + GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}" |
| 132 | + |
| 133 | + - name: Upload gem (no publish) |
| 134 | + if: env.PUBLISH != 'true' |
| 135 | + uses: actions/upload-artifact@v7 |
| 136 | + with: |
| 137 | + name: gem |
| 138 | + path: ./bindings/ruby/rails/*.gem |
| 139 | + if-no-files-found: error |
0 commit comments