name: Set up Launchable description: >- Install the required dependencies and execute the necessary Launchable commands for test recording inputs: os: required: true description: The operating system that CI runs on. This value is used in Launchable flavor. test-opts: default: none required: false description: >- Test options that determine how tests are run. This value is used in the Launchable flavor. launchable-token: required: false description: >- Launchable token is needed if you want to run Launchable on your forked repository. See https://github.com/ruby/ruby/wiki/CI-Servers#launchable-ci for details. builddir: required: false default: ${{ github.workspace }} description: >- Directory to create Launchable report file. srcdir: required: false default: ${{ github.workspace }} description: >- Directory to (re-)checkout source codes. Launchable retrieves the commit information from the directory. test-task: required: false default: ${{ matrix.test_task }} description: >- Specifies a single test task to be executed. This value is used in the Launchable flavor. Either 'test-task' or 'multi-test-tasks' must be configured. test-tasks: required: false default: '[]' description: >- Specifies an array of multiple test tasks to be executed. For example: '["test", "test-all"]'. If you want to run a single test task, use the 'test-task' input instead. is-yjit: required: false default: 'false' description: >- Whether this workflow is executed on YJIT. runs: using: composite steps: - name: Enable Launchable conditionally id: enable-launchable run: echo "enable-launchable=true" >> $GITHUB_OUTPUT shell: bash if: >- ${{ (github.repository == 'ruby/ruby' || (github.repository != 'ruby/ruby' && env.LAUNCHABLE_TOKEN)) && (inputs.test-task == 'check' || inputs.test-task == 'test-all' || inputs.test-task == 'test' || contains(fromJSON(inputs.test-tasks), 'test-all') || contains(fromJSON(inputs.test-tasks), 'test')) }} # 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 global vars id: global shell: bash run: | test_all_enabled="${{ inputs.test-task == 'check' || inputs.test-task == 'test-all' || contains(fromJSON(inputs.test-tasks), 'test-all') }}" btest_enabled="${{ inputs.test-task == 'check' || inputs.test-task == 'test' || contains(fromJSON(inputs.test-tasks), 'test') }}" test_spec_enabled="${{ inputs.test-task == 'check' || inputs.test-task == 'test-spec' || contains(fromJSON(inputs.test-tasks), 'test-spec') }}" echo test_all_enabled="${test_all_enabled}" >> $GITHUB_OUTPUT echo btest_enabled="${btest_enabled}" >> $GITHUB_OUTPUT echo test_spec_enabled="${test_spec_enabled}" >> $GITHUB_OUTPUT echo test_all_session_file='launchable_test_all_session.txt' >> $GITHUB_OUTPUT echo btest_session_file='launchable_btest_session.txt' >> $GITHUB_OUTPUT echo test_spec_session_file='launchable_test_spec_session.txt' >> $GITHUB_OUTPUT echo test_all_report_file='launchable_test_all_report.json' >> $GITHUB_OUTPUT echo btest_report_file='launchable_btest_report.json' >> $GITHUB_OUTPUT echo test_spec_report_dir='launchable_test_spec_report' >> $GITHUB_OUTPUT 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 echo "LAUNCHABLE_TOKEN=${{ inputs.launchable-token }}" >> $GITHUB_ENV if: steps.enable-launchable.outputs.enable-launchable - name: Set up path shell: bash working-directory: ${{ inputs.srcdir }} # Since updated PATH variable will be available in only subsequent actions, we need to add the path beforehand. # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path run: echo "$(python -msite --user-base)/bin" >> $GITHUB_PATH if: steps.enable-launchable.outputs.enable-launchable && startsWith(inputs.os, 'macos') - name: Set up Launchable shell: bash working-directory: ${{ inputs.srcdir }} run: | set -x pip install --user launchable : # The build name cannot include a slash, so we replace the string here. github_ref="${{ github.ref }}" github_ref="${github_ref//\//_}" : # With the --name option, we need to configure a unique identifier for this build. : # To avoid setting the same build name as the CI which runs on other branches, we use the branch name here. build_name="${github_ref}_${GITHUB_PR_HEAD_SHA}" test_opts="${{ inputs.test-opts }}" test_opts="${test_opts// /}" test_opts="${test_opts//=/:}" test_all_test_suite='test-all' btest_test_suite='btest' test_spec_test_suite='test-spec' if [ "${{ inputs.is-yjit }}" = "true" ]; then test_all_test_suite="yjit-${test_all_test_suite}" btest_test_suite="yjit-${btest_test_suite}" test_spec_test_suite="yjit-${test_spec_test_suite}" fi launchable record build --name "${build_name}" if [ "${test_all_enabled}" = "true" ]; then launchable record session \ --build "${build_name}" \ --flavor os=${{ inputs.os }} \ --flavor test_task=${{ inputs.test-task }} \ --flavor test_opts=${test_opts} \ --test-suite ${test_all_test_suite} \ > "${test_all_session_file}" echo "TESTS=${TESTS} --launchable-test-reports=${test_all_report_file}" >> $GITHUB_ENV fi if [ "${btest_enabled}" = "true" ]; then launchable record session \ --build "${build_name}" \ --flavor os=${{ inputs.os }} \ --flavor test_task=${{ inputs.test-task }} \ --flavor test_opts=${test_opts} \ --test-suite ${btest_test_suite} \ > "${btest_session_file}" echo "BTESTS=${BTESTS} --launchable-test-reports=${btest_report_file}" >> $GITHUB_ENV fi if [ "${test_spec_enabled}" = "true" ]; then launchable record session \ --build "${build_name}" \ --flavor os=${{ inputs.os }} \ --flavor test_task=${{ inputs.test-task }} \ --flavor test_opts=${test_opts} \ --test-suite ${test_spec_test_suite} \ > "${test_spec_session_file}" echo "SPECOPTS=${SPECOPTS} --launchable-test-reports=${test_spec_report_dir}" >> $GITHUB_ENV fi if: steps.enable-launchable.outputs.enable-launchable env: test_all_enabled: ${{ steps.global.outputs.test_all_enabled }} btest_enabled: ${{ steps.global.outputs.btest_enabled }} test_spec_enabled: ${{ steps.global.outputs.test_spec_enabled }} test_all_session_file: ${{ steps.global.outputs.test_all_session_file }} btest_session_file: ${{ steps.global.outputs.btest_session_file }} test_spec_session_file: ${{ steps.global.outputs.test_spec_session_file }} test_all_report_file: ${{ steps.global.outputs.test_all_report_file }} btest_report_file: ${{ steps.global.outputs.btest_report_file }} test_spec_report_dir: ${{ steps.global.outputs.test_spec_report_dir }} - name: Variables to report Launchable id: variables shell: bash working-directory: ${{ inputs.srcdir }} run: | set -x : # report-path from srcdir if [ "${srcdir}" = "${{ github.workspace }}" ]; then dir= else # srcdir must be equal to or under workspace dir=$(echo ${srcdir:+${srcdir}/} | sed 's:[^/][^/]*/:../:g') fi if [ "${test_all_enabled}" = "true" ]; then test_report_path="${dir}${builddir:+${builddir}/}${test_all_report_file}" echo test_report_path="${test_report_path}" >> $GITHUB_OUTPUT fi if [ "${btest_enabled}" = "true" ]; then btest_report_path="${dir}${builddir:+${builddir}/}${btest_report_file}" echo btest_report_path="${btest_report_path}" >> $GITHUB_OUTPUT fi if [ "${test_spec_enabled}" = "true" ]; then test_spec_report_path="${dir}${builddir:+${builddir}/}${test_spec_report_dir}" mkdir "${test_spec_report_path}" echo test_spec_report_path="${test_spec_report_path}" >> $GITHUB_OUTPUT fi if: steps.enable-launchable.outputs.enable-launchable env: srcdir: ${{ inputs.srcdir }} builddir: ${{ inputs.builddir }} test_all_enabled: ${{ steps.global.outputs.test_all_enabled }} btest_enabled: ${{ steps.global.outputs.btest_enabled }} test_spec_enabled: ${{ steps.global.outputs.test_spec_enabled }} test_all_report_file: ${{ steps.global.outputs.test_all_report_file }} btest_report_file: ${{ steps.global.outputs.btest_report_file }} test_spec_report_dir: ${{ steps.global.outputs.test_spec_report_dir }} - name: Record test results in Launchable uses: gacts/run-and-post-run@674528335da98a7afc80915ff2b4b860a0b3553a # v1.4.0 with: shell: bash working-directory: ${{ inputs.srcdir }} post: | [[ "${test_all_enabled}" = "true" ]] && \ launchable record tests \ --session "$(cat "${test_all_session_file}")" \ raw "${test_report_path}" || true [[ "${btest_enabled}" = "true" ]] && \ launchable record tests \ --session "$(cat "${btest_session_file}")" \ raw "${btest_report_path}" || true [[ "${test_spec_enabled}" = "true" ]] && \ launchable record tests \ --session "$(cat "${test_spec_session_file}")" \ raw ${test_spec_report_path}/* || true rm -f "${test_all_session_file}" rm -f "${btest_session_file}" rm -f "${test_spec_session_file}" rm -f "${test_report_path}" rm -f "${btest_report_path}" rm -fr "${test_spec_report_path}" if: ${{ always() && steps.enable-launchable.outputs.enable-launchable }} env: test_report_path: ${{ steps.variables.outputs.test_report_path }} btest_report_path: ${{ steps.variables.outputs.btest_report_path }} test_spec_report_path: ${{ steps.variables.outputs.test_spec_report_path }} test_all_enabled: ${{ steps.global.outputs.test_all_enabled }} btest_enabled: ${{ steps.global.outputs.btest_enabled }} test_spec_enabled: ${{ steps.global.outputs.test_spec_enabled }} test_all_session_file: ${{ steps.global.outputs.test_all_session_file }} btest_session_file: ${{ steps.global.outputs.btest_session_file }} test_spec_session_file: ${{ steps.global.outputs.test_spec_session_file }}