blob: 02d1e6713a09a3c496c7e8c1f3a474b15bbab8a0 [file] [log] [blame]
mariecwhited1fa3232023-04-08 02:10:43 +10001# 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 Todd900ec672024-05-22 10:25:40 -07006
mariecwhited1fa3232023-04-08 02:10:43 +10007# 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
11name: Setup
12
13on:
14 workflow_call:
15 outputs:
Geoffrey Martin-Noble8ae0f522023-07-10 16:46:08 -070016 enabled-jobs:
mariecwhited1fa3232023-04-08 02:10:43 +100017 description: |
Geoffrey Martin-Noble8ae0f522023-07-10 16:46:08 -070018 Which jobs should run.
19 value: ${{ jobs.setup.outputs.enabled-jobs }}
mariecwhited1fa3232023-04-08 02:10:43 +100020 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 }}
mariecwhited1fa3232023-04-08 02:10:43 +100036
Marius Brehlera8731a32024-04-17 21:31:17 +020037permissions:
38 contents: read
mariecwhited1fa3232023-04-08 02:10:43 +100039
mariecwhited1fa3232023-04-08 02:10:43 +100040jobs:
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-Noble8ae0f522023-07-10 16:46:08 -070048 enabled-jobs: ${{ steps.configure.outputs.enabled-jobs }}
mariecwhited1fa3232023-04-08 02:10:43 +100049 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 }}
mariecwhited1fa3232023-04-08 02:10:43 +100053 steps:
54 - name: "Checking out repository"
Marius Brehlerb78def22024-09-06 18:53:11 +020055 uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
mariecwhited1fa3232023-04-08 02:10:43 +100056 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 Todd3f51a552024-04-19 11:00:27 -070065 # See https://github.com/iree-org/iree/issues/10042#issuecomment-1449250094
mariecwhited1fa3232023-04-08 02:10:43 +100066 # 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 Wuad65e562023-04-26 22:30:17 +000080 echo "pr-branch=$(jq '.head.ref' ${PR_JSON})" >> "${GITHUB_OUTPUT}"
mariecwhited1fa3232023-04-08 02:10:43 +100081 # 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 Wuad65e562023-04-26 22:30:17 +000089 PR_BRANCH: ${{ fromJSON(steps.fetch-pr.outputs.pr-branch || '""') }}
mariecwhited1fa3232023-04-08 02:10:43 +100090 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-Noble8ae0f522023-07-10 16:46:08 -0700103 - name: "Show enabled options"
mariecwhited1fa3232023-04-08 02:10:43 +1000104 env:
Geoffrey Martin-Noble8ae0f522023-07-10 16:46:08 -0700105 ENABLED_JOBS: ${{ join(fromJson(steps.configure.outputs.enabled-jobs)) || 'None' }}
mariecwhited1fa3232023-04-08 02:10:43 +1000106 run: |
Geoffrey Martin-Noble8ae0f522023-07-10 16:46:08 -0700107 echo ":green_circle: Enabled jobs: \`${ENABLED_JOBS}\`" \
108 >> "${GITHUB_STEP_SUMMARY}"