-
Notifications
You must be signed in to change notification settings - Fork 42
95 lines (82 loc) · 2.74 KB
/
ruby.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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