minify-html/.github/workflows/ruby.yml

117 lines
4.2 KiB
YAML

name: Build and publish Ruby gem
on:
create:
tags:
- 'v*'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
ruby: [2.5.7, 2.6.5, 2.7.0]
include:
- os: ubuntu-latest
NAME: linux
FILE: 'libhyperbuild_ruby_lib.so'
- os: macos-latest
NAME: macos
FILE: 'libhyperbuild_ruby_lib.dylib'
steps:
- uses: actions/checkout@v1
- name: Get version
id: version
shell: bash
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}
# Install Ruby manually as actions/setup-ruby@v1 does not compile with `--enable-shared`.
- name: Prepare for rbenv
run: |
cat << 'EOF' >> "$HOME/.bash_profile"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
EOF
- name: Get native module file name
id: native_file
shell: bash
env:
RUBY_VERSION: ${{ matrix.ruby }}
# PowerShell doesn't support `${...}` syntax.
run: echo ::set-output name=NAME::${{ matrix.NAME }}-ruby${RUBY_VERSION%.*}
- name: Set up rbenv (macOS)
if: runner.os == 'macOS'
shell: bash -l {0}
run: |
brew install openssl libyaml libffi
brew install rbenv
- name: Set up rbenv (Linux)
if: runner.os == 'Linux'
shell: bash -l {0}
# rbenv-installer now uses Linux brew to install Ruby, which we do not want.
run: |
sudo apt install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
mkdir -p "$HOME/.rbenv/plugins"
git clone https://github.com/rbenv/ruby-build.git "$HOME/.rbenv/plugins/ruby-build"
- name: Set up Ruby
shell: bash -l {0}
run: |
rbenv install ${{ matrix.ruby }}
rbenv global ${{ matrix.ruby }}
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.39.0
profile: minimal
default: true
- name: Build Ruby native library
shell: bash -l {0}
run: cargo build --release
working-directory: ./ruby
- name: Install B2 CLI (macOS, Linux)
if: runner.os != 'Windows'
run: |
sudo pip install setuptools
sudo pip install --upgrade b2
- name: Install B2 CLI (Windows)
if: runner.os == 'Windows'
run: |
pip install --upgrade b2
- name: Upload to B2
run: |
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
b2 upload-file --contentType ${{ matrix.MIME }} ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./ruby/target/release/${{ matrix.FILE }} hyperbuild/bin/ruby/${{ steps.version.outputs.VERSION }}/${{ steps.native_file.outputs.NAME }}
package:
runs-on: ubuntu-latest
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}
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: '2.5'
- name: Install B2 CLI
run: |
sudo pip install setuptools
sudo pip install --upgrade b2
- name: Pack and publish gem
working-directory: ./ruby
run: |
cp ../README.md .
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
b2 sync b2://${{ secrets.CICD_CLI_B2_BUCKET_NAME }}/hyperbuild/bin/ruby/${{ steps.version.outputs.VERSION }}/ ./lib/.
gem build hyperbuild.gemspec
mkdir -p "$HOME/.gem"
cat << 'EOF' > "$HOME/.gem/credentials"
---
:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}
EOF
chmod 0600 "$HOME/.gem/credentials"
gem push hyperbuild-${{ steps.version.outputs.VERSION }}.gem