Build and publish Ruby gem #151
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and publish Ruby gem | |
on: | |
push: | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
strategy: | |
matrix: | |
platform: | |
- x86_64-linux | |
- aarch64-linux | |
- x86_64-darwin | |
- arm64-darwin | |
- x64-mingw-ucrt | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Patches | |
run: | | |
# Name must match or else `RbSys::PackageNotFoundError: Could not find Cargo package metadata for nil. Please check that nil matches the crate name in your Cargo.toml.` | |
# We edit it here instead of just updating our repo code as Cargo workspace names must be different. | |
sed -i 's%^name = ".*$%name = "minify_html"%' ./minify-html-ruby/ext/minify_html/Cargo.toml | |
# This is required or else `error: could not find `Cargo.toml` in `/home/runner/work/.../minify-html-ruby` or any parent directory`. | |
cat <<'EOD'>./minify-html-ruby/Cargo.toml | |
[workspace] | |
members = ["ext/minify_html"] | |
EOD | |
cp ./README.md ./minify-html-ruby/. | |
# https://github.com/oxidize-rb/actions/tree/main/cross-gem | |
- name: Set up Ruby and Rust | |
uses: oxidize-rb/actions/setup-ruby-and-rust@main | |
with: | |
ruby-version: "3.2" | |
bundler-cache: false | |
cargo-cache: true | |
cargo-vendor: true | |
cache-version: v0-${{ matrix.platform }} | |
- name: Cross compile | |
id: gem | |
uses: oxidize-rb/actions/cross-gem@v1 | |
with: | |
platform: ${{ matrix.platform }} | |
ruby-versions: "2.7,3.0,3.1,3.2" | |
working-directory: ./minify-html-ruby | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: minify_html_${{ matrix.platform }} | |
path: ${{ steps.gem.outputs.gem-path }} | |
package: | |
runs-on: ubuntu-20.04 | |
needs: build | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Get version | |
id: version | |
shell: bash | |
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')" | |
- name: Set up Ruby | |
uses: actions/setup-ruby@v1 | |
with: | |
ruby-version: '2.5' | |
- name: Download built libraries | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./minify-html-ruby/pkg | |
merge-multiple: true | |
- name: Pack and publish gem | |
working-directory: ./minify-html-ruby | |
run: | | |
mkdir -p "$HOME/.gem" | |
cat << 'EOF' > "$HOME/.gem/credentials" | |
--- | |
:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }} | |
EOF | |
chmod 0600 "$HOME/.gem/credentials" | |
if [[ "${{ steps.version.outputs.VERSION }}" != "0.0.0" ]]; then | |
gem push pkg/*.gem | |
else | |
tree | |
fi |