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

118 lines
4.0 KiB
YAML
Raw Normal View History

name: Build and publish Ruby gem
2020-01-19 03:19:33 -05:00
on:
2021-08-05 22:22:24 -04:00
push:
2020-01-19 03:19:33 -05:00
tags:
- 'v*'
2021-08-05 22:22:24 -04:00
workflow_dispatch:
2020-01-19 03:19:33 -05:00
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-11.0]
2020-01-20 01:48:17 -05:00
ruby: [2.5.7, 2.6.5, 2.7.0]
2020-01-19 03:19:33 -05:00
include:
- os: ubuntu-20.04
2020-01-19 03:19:33 -05:00
NAME: linux
2020-07-11 11:29:34 -04:00
FILE: 'libminify_html_ruby_lib.so'
2021-04-06 04:50:24 -04:00
- os: macos-11.0
2020-01-19 03:19:33 -05:00
NAME: macos
2020-07-11 11:29:34 -04:00
FILE: 'libminify_html_ruby_lib.dylib'
2020-01-19 03:19:33 -05:00
steps:
- uses: actions/checkout@v1
2020-07-24 04:30:59 -04:00
- name: Get version
id: version
shell: bash
2020-06-18 22:22:28 -04:00
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
2020-07-24 04:30:25 -04:00
- name: Get native module file name
id: native_file
shell: bash
env:
RUBY_VERSION: ${{ matrix.ruby }}
run: echo ::set-output name=NAME::${{ matrix.NAME }}-ruby${RUBY_VERSION%.*}
2020-07-24 04:30:25 -04:00
2020-07-24 05:12:43 -04:00
# Install Ruby manually as actions/setup-ruby@v1 does not compile with `--enable-shared`.
- name: Install rbenv dependencies (macOS)
if: runner.os == 'macOS'
2020-07-24 05:21:53 -04:00
run: brew install openssl libyaml libffi
2020-07-24 04:30:25 -04:00
2020-07-24 05:12:43 -04:00
- name: Install rbenv dependencies (Linux)
2020-01-20 01:48:17 -05:00
if: runner.os == 'Linux'
2020-07-24 05:21:53 -04:00
run: sudo apt install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
2020-07-24 05:12:43 -04:00
- name: Install rbenv
# rbenv-installer now uses Linux brew to install Ruby, which we do not want.
run: |
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
mkdir -p "$HOME/.rbenv/plugins"
git clone https://github.com/rbenv/ruby-build.git "$HOME/.rbenv/plugins/ruby-build"
2020-07-24 04:30:25 -04:00
2020-01-20 01:48:17 -05:00
- name: Set up Ruby
run: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
2020-01-20 01:48:17 -05:00
rbenv install ${{ matrix.ruby }}
rbenv global ${{ matrix.ruby }}
2020-07-24 04:30:25 -04:00
2020-07-24 05:12:43 -04:00
- name: Set up Rust
2020-01-19 03:19:33 -05:00
uses: actions-rs/toolchain@v1
with:
toolchain: stable
2020-01-19 03:19:33 -05:00
profile: minimal
default: true
2020-07-24 04:30:25 -04:00
- name: Run prebuild steps
shell: bash
run: bash ./prebuild.sh
2020-07-24 04:30:25 -04:00
2020-01-19 03:19:33 -05:00
- name: Build Ruby native library
run: |
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
cargo build -vvv --release
2020-01-19 03:19:33 -05:00
working-directory: ./ruby
2020-07-24 04:30:25 -04:00
- name: Set up Backblaze B2 CLI
uses: wilsonzlin/setup-b2@v3
2020-07-24 04:30:25 -04:00
2020-06-18 19:49:48 -04:00
- name: Upload to B2
run: |
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
2020-07-11 11:29:34 -04:00
b2 upload-file ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./ruby/target/release/${{ matrix.FILE }} minify-html/bin/ruby/${{ steps.version.outputs.VERSION }}/${{ steps.native_file.outputs.NAME }}
2020-07-24 05:12:43 -04:00
2020-01-19 03:19:33 -05:00
package:
runs-on: ubuntu-20.04
2020-01-19 03:19:33 -05:00
needs: build
steps:
- uses: actions/checkout@v1
- name: Get version
id: version
shell: bash
2020-06-18 22:22:28 -04:00
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
2020-01-19 03:25:11 -05:00
- name: Set up Ruby
2020-01-19 03:19:33 -05:00
uses: actions/setup-ruby@v1
with:
ruby-version: '2.5'
- name: Set up Backblaze B2 CLI
uses: wilsonzlin/setup-b2@v3
- name: Pack and publish gem
2020-01-19 03:19:33 -05:00
working-directory: ./ruby
run: |
2020-01-19 09:13:21 -05:00
cp ../README.md .
2020-06-18 19:49:48 -04:00
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
2020-07-11 11:29:34 -04:00
b2 sync b2://${{ secrets.CICD_CLI_B2_BUCKET_NAME }}/minify-html/bin/ruby/${{ steps.version.outputs.VERSION }}/ ./lib/.
gem build minify_html.gemspec
2020-01-19 08:33:39 -05:00
mkdir -p "$HOME/.gem"
2020-01-19 23:10:34 -05:00
cat << 'EOF' > "$HOME/.gem/credentials"
---
:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}
EOF
chmod 0600 "$HOME/.gem/credentials"
2020-06-18 21:44:54 -04:00
if [[ "${{ steps.version.outputs.VERSION }}" != "0.0.0" ]]; then
2020-07-11 11:29:34 -04:00
gem push minify_html-${{ steps.version.outputs.VERSION }}.gem
2020-06-18 21:44:54 -04:00
fi