Skip to content

Commit 4ddafce

Browse files
authored
Merge pull request #15 from shopify-playground/ec-test-command-config
Allow to customize the test command running:
2 parents 9b8f37e + 92df445 commit 4ddafce

File tree

6 files changed

+227
-1
lines changed

6 files changed

+227
-1
lines changed

.github/actions/easy_compile/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ inputs:
1212
token:
1313
description: "TODO this is needed to install the Easy Compile gem from the GitHub repo. Can be removed "
1414
required: false
15+
test-command:
16+
description: "The command to run the test suite. By default Easy Compile will run either `bundle exec rake test` or `bundle exec rake spec` depending on the test framework used."
17+
required: false
18+
default: "easy_compile test"
1519

1620
runs:
1721
using: "composite"
@@ -70,7 +74,7 @@ runs:
7074
if: "${{ startsWith(inputs.step, 'test') }}"
7175
working-directory: ${{ inputs.working-directory }}
7276
shell: bash
73-
run: easy_compile test # TODO This should be configurable
77+
run: ${{ inputs.test-command }}
7478
- name: "Download tarball for platform"
7579
if: "${{ inputs.step == 'install' }}"
7680
uses: actions/download-artifact@v5

lib/easy_compile/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def clobber
9090
and determine what Ruby versions needs to be used for precompiling a "fat gem".
9191
MSG
9292
method_option "working-directory", type: "string", required: false, desc: "If your gem lives outside of the repository root, specify where."
93+
method_option "test-command", type: "string", required: false, desc: "The test command to run. Defaults to running `bundle exec rake test` and `bundle exec rake spec`."
9394
def ci_template
9495
# os = ["macos-latest", "macos-15-intel", "ubuntu-latest", "windows-latest"]
9596
os = ["macos-latest", "ubuntu-latest"] # Just this for now because the CI takes too long otherwise.

lib/easy_compile/templates/.github/workflows/easy-compile.yaml.tt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ jobs:
6363
<%- if options['working-directory'] -%>
6464
working-directory: "<%= options['working-directory'] %>"
6565
<%- end -%>
66+
<%- if options['test-command'] -%>
67+
test-command: "<%= options['test-command'] %>"
68+
<%- end -%>
6669
install:
6770
timeout-minutes: 5
6871
name: "Verify the gem can be installed"

test/cli_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ def test_ci_template_when_passed_a_working_directory
9090
FileUtils.rm_rf("test/fixtures/dummy_gem/.github")
9191
end
9292

93+
def test_ci_template_when_passed_a_test_command
94+
workflow_path = "test/fixtures/dummy_gem/.github/workflows/easy-compile.yaml"
95+
96+
expected_workflow = File.read("test/fixtures/expected_github_workflow_test_command.yml")
97+
Dir.chdir("test/fixtures/dummy_gem") do
98+
capture_subprocess_io do
99+
CLI.start(["ci_template", "--test-command", "bundle exec something"])
100+
end
101+
end
102+
103+
assert(File.exist?(workflow_path))
104+
assert_equal(expected_workflow, File.read(workflow_path))
105+
ensure
106+
FileUtils.rm_rf("test/fixtures/dummy_gem/.github")
107+
end
108+
109+
def test_ci_template_when_passed_a_test_command_and_workdir
110+
workflow_path = "test/fixtures/dummy_gem/.github/workflows/easy-compile.yaml"
111+
112+
expected_workflow = File.read("test/fixtures/expected_github_workflow_test_and_workdir.yml")
113+
Dir.chdir("test/fixtures/dummy_gem") do
114+
capture_subprocess_io do
115+
CLI.start(["ci_template", "--test-command", "bundle exec something", "--working-directory", "foo/bar"])
116+
end
117+
end
118+
119+
assert(File.exist?(workflow_path))
120+
assert_equal(expected_workflow, File.read(workflow_path))
121+
ensure
122+
FileUtils.rm_rf("test/fixtures/dummy_gem/.github")
123+
end
124+
93125
def test_release
94126
FileUtils.touch("tmp/foo.gem")
95127
FileUtils.touch("tmp/bar.gem")
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: "Package gems with precompiled binaries"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
release:
6+
description: "If the whole build passes on all platforms, release the gems on RubyGems.org"
7+
required: false
8+
type: boolean
9+
default: false
10+
jobs:
11+
compile:
12+
timeout-minutes: 20
13+
name: "Cross compile the gem on different ruby versions"
14+
strategy:
15+
matrix:
16+
os: ["macos-latest", "ubuntu-latest"]
17+
runs-on: "${{ matrix.os }}"
18+
steps:
19+
- name: "Checkout code"
20+
uses: "actions/checkout@v5"
21+
- name: "Setup Ruby"
22+
uses: "ruby/setup-ruby@v1"
23+
with:
24+
ruby-version: "3.1.7"
25+
bundler-cache: true
26+
working-directory: "foo/bar"
27+
- name: "Run easy compile"
28+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
29+
with:
30+
step: "compile"
31+
token: ${{ secrets.EASY_COMPILE }} # TODO Remove this before publishing the gem
32+
working-directory: "foo/bar"
33+
test:
34+
timeout-minutes: 20
35+
name: "Run the test suite"
36+
needs: compile
37+
strategy:
38+
matrix:
39+
os: ["macos-latest", "ubuntu-latest"]
40+
rubies: ["3.4.7", "3.3.9", "3.2.9", "3.1.7"]
41+
type: ["cross", "native"]
42+
runs-on: "${{ matrix.os }}"
43+
steps:
44+
- name: "Checkout code"
45+
uses: "actions/checkout@v5"
46+
- name: "Setup Ruby"
47+
uses: "ruby/setup-ruby@v1"
48+
with:
49+
ruby-version: "${{ matrix.rubies }}"
50+
bundler-cache: true
51+
working-directory: "foo/bar"
52+
- name: "Run easy compile"
53+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
54+
with:
55+
step: "test_${{ matrix.type }}"
56+
token: ${{ secrets.EASY_COMPILE }} # TODO Remove this before publishing the gem
57+
working-directory: "foo/bar"
58+
test-command: "bundle exec something"
59+
install:
60+
timeout-minutes: 5
61+
name: "Verify the gem can be installed"
62+
needs: test
63+
strategy:
64+
matrix:
65+
os: ["macos-latest", "ubuntu-latest"]
66+
runs-on: "${{ matrix.os }}"
67+
steps:
68+
- name: "Setup Ruby"
69+
uses: "ruby/setup-ruby@v1"
70+
with:
71+
ruby-version: "3.4.7"
72+
- name: "Run easy compile"
73+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
74+
with:
75+
token: ${{ secrets.EASY_COMPILE }} # TODO Remove this before publishing the gem
76+
step: "install"
77+
release:
78+
permissions:
79+
id-token: write
80+
contents: read
81+
timeout-minutes: 5
82+
if: ${{ inputs.release }}
83+
name: "Release all gems with RubyGems"
84+
needs: install
85+
runs-on: "ubuntu-latest"
86+
steps:
87+
- name: "Setup Ruby"
88+
uses: "ruby/setup-ruby@v1"
89+
with:
90+
ruby-version: "3.4.7"
91+
- name: "Run easy compile"
92+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
93+
with:
94+
step: "release"
95+
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: "Package gems with precompiled binaries"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
release:
6+
description: "If the whole build passes on all platforms, release the gems on RubyGems.org"
7+
required: false
8+
type: boolean
9+
default: false
10+
jobs:
11+
compile:
12+
timeout-minutes: 20
13+
name: "Cross compile the gem on different ruby versions"
14+
strategy:
15+
matrix:
16+
os: ["macos-latest", "ubuntu-latest"]
17+
runs-on: "${{ matrix.os }}"
18+
steps:
19+
- name: "Checkout code"
20+
uses: "actions/checkout@v5"
21+
- name: "Setup Ruby"
22+
uses: "ruby/setup-ruby@v1"
23+
with:
24+
ruby-version: "3.1.7"
25+
bundler-cache: true
26+
- name: "Run easy compile"
27+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
28+
with:
29+
step: "compile"
30+
token: ${{ secrets.EASY_COMPILE }} # TODO Remove this before publishing the gem
31+
test:
32+
timeout-minutes: 20
33+
name: "Run the test suite"
34+
needs: compile
35+
strategy:
36+
matrix:
37+
os: ["macos-latest", "ubuntu-latest"]
38+
rubies: ["3.4.7", "3.3.9", "3.2.9", "3.1.7"]
39+
type: ["cross", "native"]
40+
runs-on: "${{ matrix.os }}"
41+
steps:
42+
- name: "Checkout code"
43+
uses: "actions/checkout@v5"
44+
- name: "Setup Ruby"
45+
uses: "ruby/setup-ruby@v1"
46+
with:
47+
ruby-version: "${{ matrix.rubies }}"
48+
bundler-cache: true
49+
- name: "Run easy compile"
50+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
51+
with:
52+
step: "test_${{ matrix.type }}"
53+
token: ${{ secrets.EASY_COMPILE }} # TODO Remove this before publishing the gem
54+
test-command: "bundle exec something"
55+
install:
56+
timeout-minutes: 5
57+
name: "Verify the gem can be installed"
58+
needs: test
59+
strategy:
60+
matrix:
61+
os: ["macos-latest", "ubuntu-latest"]
62+
runs-on: "${{ matrix.os }}"
63+
steps:
64+
- name: "Setup Ruby"
65+
uses: "ruby/setup-ruby@v1"
66+
with:
67+
ruby-version: "3.4.7"
68+
- name: "Run easy compile"
69+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
70+
with:
71+
token: ${{ secrets.EASY_COMPILE }} # TODO Remove this before publishing the gem
72+
step: "install"
73+
release:
74+
permissions:
75+
id-token: write
76+
contents: read
77+
timeout-minutes: 5
78+
if: ${{ inputs.release }}
79+
name: "Release all gems with RubyGems"
80+
needs: install
81+
runs-on: "ubuntu-latest"
82+
steps:
83+
- name: "Setup Ruby"
84+
uses: "ruby/setup-ruby@v1"
85+
with:
86+
ruby-version: "3.4.7"
87+
- name: "Run easy compile"
88+
uses: "shopify-playground/edouard-playground/.github/actions/easy_compile@main"
89+
with:
90+
step: "release"
91+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)