Skip to content

Commit

Permalink
Add Launchable in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ono-max authored and ko1 committed Mar 11, 2024
1 parent 3564601 commit 6e9a127
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/actions/launchable/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Set up Launchable
description: >-
Install the required dependencies and execute the necessary Launchable commands for test recording
inputs:
report-path:
default: launchable_reports.json
required: true
description: The file path of the test report for uploading to Launchable

test-task:
default: none
required: true
description: >-
Test task that determine how tests are run.
This value is used in the Launchable flavor.
runs:
using: composite

steps:
- name: Enable Launchable conditionally
id: enable-launchable
run: echo "enable-launchable=true" >> $GITHUB_OUTPUT
shell: bash
if: ${{ github.repository == 'ruby/debug' }}

# Launchable CLI requires Python and Java.
# https://www.launchableinc.com/docs/resources/cli-reference/
- name: Set up Python
uses: actions/setup-python@871daa956ca9ea99f3c3e30acb424b7960676734 # v5.0.0
with:
python-version: "3.x"
if: ${{ steps.enable-launchable.outputs.enable-launchable }}

- name: Set up Java
uses: actions/setup-java@7a445ee88d4e23b52c33fdc7601e40278616c7f8 # v4.0.0
with:
distribution: 'temurin'
java-version: '17'
if: ${{ steps.enable-launchable.outputs.enable-launchable }}

- name: Set environment variables for Launchable
shell: bash
run: |
: # GITHUB_PULL_REQUEST_URL are used for commenting test reports in Launchable Github App.
: # https://github.com/launchableinc/cli/blob/v1.80.1/launchable/utils/link.py#L42
echo "GITHUB_PULL_REQUEST_URL=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV
: # The following envs are necessary in Launchable tokenless authentication.
: # https://github.com/launchableinc/cli/blob/v1.80.1/launchable/utils/authentication.py#L20
echo "LAUNCHABLE_ORGANIZATION=${{ github.repository_owner }}" >> $GITHUB_ENV
echo "LAUNCHABLE_WORKSPACE=${{ github.event.repository.name }}" >> $GITHUB_ENV
: # https://github.com/launchableinc/cli/blob/v1.80.1/launchable/utils/authentication.py#L71
echo "GITHUB_PR_HEAD_SHA=${{ github.event.pull_request.head.sha || github.sha }}" >> $GITHUB_ENV
if: ${{ steps.enable-launchable.outputs.enable-launchable }}

- name: Set up Launchable
shell: bash
run: |
set -x
PATH=$PATH:$(python -msite --user-base)/bin
echo "PATH=$PATH" >> $GITHUB_ENV
pip install --user launchable
launchable verify
: # The build name cannot include a slash, so we replace the string here.
github_ref="${{ github.ref }}"
github_ref="${github_ref//\//_}"
launchable record build --name ${github_ref}_${GITHUB_PR_HEAD_SHA}
echo "TESTOPTS=${TESTOPTS} --runner=launchable --launchable-test-report-json=${{ inputs.report-path }}" >> $GITHUB_ENV
if: ${{ steps.enable-launchable.outputs.enable-launchable }}

- name: Record test results in Launchable
uses: gacts/run-and-post-run@674528335da98a7afc80915ff2b4b860a0b3553a # v1.4.0
with:
shell: bash
post: |
launchable record tests --flavor os=${{ inputs.os }} --flavor test_task=${{ inputs.test-task }} raw ${{ inputs.report-path }}
rm -f ${{ inputs.report-path }}
if: ${{ always() && steps.enable-launchable.outputs.enable-launchable }}
8 changes: 8 additions & 0 deletions .github/workflows/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# Set fetch-depth: 10 so that Launchable can receive commits information.
fetch-depth: 10
- name: Set up Launchable
uses: ./.github/actions/launchable/setup
with:
os: ubuntu-latest
test-task: test_protocol
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ruby-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# Set fetch-depth: 10 so that Launchable can receive commits information.
fetch-depth: 10
- name: Set up Launchable
uses: ./.github/actions/launchable/setup
with:
os: macos-latest
test-task: test_console
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# Set fetch-depth: 10 so that Launchable can receive commits information.
fetch-depth: 10
- name: Set up Launchable
uses: ./.github/actions/launchable/setup
with:
os: ubuntu-latest
test-task: test_console
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# Set fetch-depth: 10 so that Launchable can receive commits information.
fetch-depth: 10
- name: Set up Launchable
uses: ./.github/actions/launchable/setup
with:
os: ubuntu-latest
test-task: test_test
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ gem "rake-compiler"
gem "test-unit", "~> 3.0"
gem "test-unit-rr"
gem "json-schema"
gem "test-unit-launchable"
7 changes: 7 additions & 0 deletions test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

require_relative 'assertions'

# Load this library only in the debug CI to prevent LoadError
# when these tests are executed in ruby/ruby.
if ENV['LAUNCHABLE_ORGANIZATION'] && ENV['LAUNCHABLE_WORKSPACE']
# "test/unit/runner/launchable" is used for uploading test result to Launchable.
require "test/unit/runner/launchable"
end

module DEBUGGER__
class TestCase < Test::Unit::TestCase
TestInfo = Struct.new(:queue, :mode, :prompt_pattern, :remote_info,
Expand Down

0 comments on commit 6e9a127

Please sign in to comment.