summaryrefslogtreecommitdiff
path: root/.github/actions/launchable/setup/action.yml
blob: 164eb1db5d3a0d4551b697117ba73fb14c45a61d (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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 }}