blob: 02d1e6713a09a3c496c7e8c1f3a474b15bbab8a0 [file] [log] [blame]
# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Sets up a github workflow.
# It is designed to be called from a parent workflow.
# The concurrency of this workflow is controlled by the caller's job.
name: Setup
on:
workflow_call:
outputs:
enabled-jobs:
description: |
Which jobs should run.
value: ${{ jobs.setup.outputs.enabled-jobs }}
is-pr:
description: |
Whether the workflow has been triggered by a pull request.
value: ${{ jobs.setup.outputs.is-pr }}
runner-env:
description: |
The runner environment to use.
value: ${{ jobs.setup.outputs.runner-env }}
runner-group:
description: |
The runner group to use.
value: ${{ jobs.setup.outputs.runner-group }}
write-caches:
description: |
Whether to write to caches.
value: ${{ jobs.setup.outputs.write-caches }}
permissions:
contents: read
jobs:
setup:
runs-on: ubuntu-20.04
env:
# The commit being checked out is the merge commit for the PR. Its first
# parent will be the tip of main.
BASE_REF: HEAD^
outputs:
enabled-jobs: ${{ steps.configure.outputs.enabled-jobs }}
is-pr: ${{ steps.configure.outputs.is-pr }}
runner-env: ${{ steps.configure.outputs.runner-env }}
runner-group: ${{ steps.configure.outputs.runner-group }}
write-caches: ${{ steps.configure.outputs.write-caches }}
steps:
- name: "Checking out repository"
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# We need the parent commit to do a diff
fetch-depth: 2
- name: "Fetching PR description"
# We fetch the latest pull request data (description, labels, ...) from
# API instead of using stale one from pull_request event. This makes it
# possible to update the trailers, labels on the pull request and re-run
# the workflow to make them take effect.
# This is majorly for triggering benchmarks without pushing new commits.
# See https://github.com/iree-org/iree/issues/10042#issuecomment-1449250094
# for more details.
id: fetch-pr
if: github.event_name == 'pull_request'
env:
PR_NUMBER: ${{ github.event.number }}
PR_JSON: pull_request.json
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" > "${PR_JSON}"
# It requires delimiter to pass multiline strings through
# GITHUB_OUTPUT. Since these are already escaped JSON strings, pass
# the JSON strings and later use fromJSON to decode them.
echo "pr-title=$(jq '.title' ${PR_JSON})" >> "${GITHUB_OUTPUT}"
echo "pr-body=$(jq '.body' ${PR_JSON})" >> "${GITHUB_OUTPUT}"
echo "pr-branch=$(jq '.head.ref' ${PR_JSON})" >> "${GITHUB_OUTPUT}"
# Use --compact-output to avoid multiline JSON.
echo "pr-labels=$(jq --compact-output '.labels | map(.name)' \
${PR_JSON})" >> "${GITHUB_OUTPUT}"
- name: "Configuring CI options"
id: configure
env:
PR_TITLE: ${{ fromJSON(steps.fetch-pr.outputs.pr-title || '""') }}
PR_BODY: ${{ fromJSON(steps.fetch-pr.outputs.pr-body || '""') }}
PR_BRANCH: ${{ fromJSON(steps.fetch-pr.outputs.pr-branch || '""') }}
PR_LABELS: ${{ steps.fetch-pr.outputs.pr-labels || '[]' }}
ORIGINAL_PR_TITLE: ${{ github.event.pull_request.title }}
ORIGINAL_PR_BODY: ${{ github.event.pull_request.body }}
ORIGINAL_PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
run: |
# Just informative logging. There should only be two commits in the
# history here, but limiting the depth helps when copying from a local
# repo instead of using checkout, e.g. with
# https://github.com/nektos/act where there will be more.
git log --oneline --graph --max-count=3
./build_tools/github_actions/configure_ci.py
- name: "Show enabled options"
env:
ENABLED_JOBS: ${{ join(fromJson(steps.configure.outputs.enabled-jobs)) || 'None' }}
run: |
echo ":green_circle: Enabled jobs: \`${ENABLED_JOBS}\`" \
>> "${GITHUB_STEP_SUMMARY}"