mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 1 | # Copyright 2022 The IREE Authors |
| 2 | # |
| 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Scott Todd | 900ec67 | 2024-05-22 10:25:40 -0700 | [diff] [blame] | 6 | |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 7 | # Sets up a github workflow. |
| 8 | # It is designed to be called from a parent workflow. |
| 9 | # The concurrency of this workflow is controlled by the caller's job. |
| 10 | |
| 11 | name: Setup |
| 12 | |
| 13 | on: |
| 14 | workflow_call: |
| 15 | outputs: |
Geoffrey Martin-Noble | 8ae0f52 | 2023-07-10 16:46:08 -0700 | [diff] [blame] | 16 | enabled-jobs: |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 17 | description: | |
Geoffrey Martin-Noble | 8ae0f52 | 2023-07-10 16:46:08 -0700 | [diff] [blame] | 18 | Which jobs should run. |
| 19 | value: ${{ jobs.setup.outputs.enabled-jobs }} |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 20 | is-pr: |
| 21 | description: | |
| 22 | Whether the workflow has been triggered by a pull request. |
| 23 | value: ${{ jobs.setup.outputs.is-pr }} |
| 24 | runner-env: |
| 25 | description: | |
| 26 | The runner environment to use. |
| 27 | value: ${{ jobs.setup.outputs.runner-env }} |
| 28 | runner-group: |
| 29 | description: | |
| 30 | The runner group to use. |
| 31 | value: ${{ jobs.setup.outputs.runner-group }} |
| 32 | write-caches: |
| 33 | description: | |
| 34 | Whether to write to caches. |
| 35 | value: ${{ jobs.setup.outputs.write-caches }} |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 36 | |
Marius Brehler | a8731a3 | 2024-04-17 21:31:17 +0200 | [diff] [blame] | 37 | permissions: |
| 38 | contents: read |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 39 | |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 40 | jobs: |
| 41 | setup: |
| 42 | runs-on: ubuntu-20.04 |
| 43 | env: |
| 44 | # The commit being checked out is the merge commit for the PR. Its first |
| 45 | # parent will be the tip of main. |
| 46 | BASE_REF: HEAD^ |
| 47 | outputs: |
Geoffrey Martin-Noble | 8ae0f52 | 2023-07-10 16:46:08 -0700 | [diff] [blame] | 48 | enabled-jobs: ${{ steps.configure.outputs.enabled-jobs }} |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 49 | is-pr: ${{ steps.configure.outputs.is-pr }} |
| 50 | runner-env: ${{ steps.configure.outputs.runner-env }} |
| 51 | runner-group: ${{ steps.configure.outputs.runner-group }} |
| 52 | write-caches: ${{ steps.configure.outputs.write-caches }} |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 53 | steps: |
| 54 | - name: "Checking out repository" |
Marius Brehler | b78def2 | 2024-09-06 18:53:11 +0200 | [diff] [blame] | 55 | uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 56 | with: |
| 57 | # We need the parent commit to do a diff |
| 58 | fetch-depth: 2 |
| 59 | - name: "Fetching PR description" |
| 60 | # We fetch the latest pull request data (description, labels, ...) from |
| 61 | # API instead of using stale one from pull_request event. This makes it |
| 62 | # possible to update the trailers, labels on the pull request and re-run |
| 63 | # the workflow to make them take effect. |
| 64 | # This is majorly for triggering benchmarks without pushing new commits. |
Scott Todd | 3f51a55 | 2024-04-19 11:00:27 -0700 | [diff] [blame] | 65 | # See https://github.com/iree-org/iree/issues/10042#issuecomment-1449250094 |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 66 | # for more details. |
| 67 | id: fetch-pr |
| 68 | if: github.event_name == 'pull_request' |
| 69 | env: |
| 70 | PR_NUMBER: ${{ github.event.number }} |
| 71 | PR_JSON: pull_request.json |
| 72 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | run: | |
| 74 | gh api "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" > "${PR_JSON}" |
| 75 | # It requires delimiter to pass multiline strings through |
| 76 | # GITHUB_OUTPUT. Since these are already escaped JSON strings, pass |
| 77 | # the JSON strings and later use fromJSON to decode them. |
| 78 | echo "pr-title=$(jq '.title' ${PR_JSON})" >> "${GITHUB_OUTPUT}" |
| 79 | echo "pr-body=$(jq '.body' ${PR_JSON})" >> "${GITHUB_OUTPUT}" |
Jerry Wu | ad65e56 | 2023-04-26 22:30:17 +0000 | [diff] [blame] | 80 | echo "pr-branch=$(jq '.head.ref' ${PR_JSON})" >> "${GITHUB_OUTPUT}" |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 81 | # Use --compact-output to avoid multiline JSON. |
| 82 | echo "pr-labels=$(jq --compact-output '.labels | map(.name)' \ |
| 83 | ${PR_JSON})" >> "${GITHUB_OUTPUT}" |
| 84 | - name: "Configuring CI options" |
| 85 | id: configure |
| 86 | env: |
| 87 | PR_TITLE: ${{ fromJSON(steps.fetch-pr.outputs.pr-title || '""') }} |
| 88 | PR_BODY: ${{ fromJSON(steps.fetch-pr.outputs.pr-body || '""') }} |
Jerry Wu | ad65e56 | 2023-04-26 22:30:17 +0000 | [diff] [blame] | 89 | PR_BRANCH: ${{ fromJSON(steps.fetch-pr.outputs.pr-branch || '""') }} |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 90 | PR_LABELS: ${{ steps.fetch-pr.outputs.pr-labels || '[]' }} |
| 91 | ORIGINAL_PR_TITLE: ${{ github.event.pull_request.title }} |
| 92 | ORIGINAL_PR_BODY: ${{ github.event.pull_request.body }} |
| 93 | ORIGINAL_PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} |
| 94 | run: | |
| 95 | # Just informative logging. There should only be two commits in the |
| 96 | # history here, but limiting the depth helps when copying from a local |
| 97 | # repo instead of using checkout, e.g. with |
| 98 | # https://github.com/nektos/act where there will be more. |
| 99 | git log --oneline --graph --max-count=3 |
| 100 | |
| 101 | ./build_tools/github_actions/configure_ci.py |
| 102 | |
Geoffrey Martin-Noble | 8ae0f52 | 2023-07-10 16:46:08 -0700 | [diff] [blame] | 103 | - name: "Show enabled options" |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 104 | env: |
Geoffrey Martin-Noble | 8ae0f52 | 2023-07-10 16:46:08 -0700 | [diff] [blame] | 105 | ENABLED_JOBS: ${{ join(fromJson(steps.configure.outputs.enabled-jobs)) || 'None' }} |
mariecwhite | d1fa323 | 2023-04-08 02:10:43 +1000 | [diff] [blame] | 106 | run: | |
Geoffrey Martin-Noble | 8ae0f52 | 2023-07-10 16:46:08 -0700 | [diff] [blame] | 107 | echo ":green_circle: Enabled jobs: \`${ENABLED_JOBS}\`" \ |
| 108 | >> "${GITHUB_STEP_SUMMARY}" |