forked from NVIDIA/cccl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Split workflow into multiple dispatch groups to avoid skipped jobs.
- Loading branch information
1 parent
8b5bf66
commit d415ef8
Showing
13 changed files
with
531 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
.github/actions/workflow-build/prepare-workflow-dispatch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This script prepares a full workflow for GHA dispatch. | ||
To avoid skipped jobs from cluttering the GHA UI, this script splits the full workflow.json into multiple workflows | ||
that don't require large numbers of skipped jobs in the workflow implementation. | ||
""" | ||
|
||
import argparse | ||
import json | ||
import os | ||
import sys | ||
|
||
|
||
def write_json_file(filename, json_object): | ||
with open(filename, 'w') as f: | ||
json.dump(json_object, f, indent=2) | ||
|
||
|
||
def is_windows(job): | ||
return job['runner'].startswith('windows') | ||
|
||
|
||
def split_workflow(workflow): | ||
linux_standalone = {} | ||
linux_two_stage = {} | ||
windows_standalone = {} | ||
windows_two_stage = {} | ||
|
||
def strip_extra_info(job): | ||
del job['origin'] | ||
|
||
for group_name, group_json in workflow.items(): | ||
standalone = group_json['standalone'] if 'standalone' in group_json else [] | ||
two_stage = group_json['two_stage'] if 'two_stage' in group_json else [] | ||
|
||
if len(standalone) > 0: | ||
for job in standalone: | ||
strip_extra_info(job) | ||
|
||
if is_windows(standalone[0]): | ||
windows_standalone[group_name] = standalone | ||
else: | ||
linux_standalone[group_name] = standalone | ||
|
||
if len(two_stage) > 0: | ||
for ts in two_stage: | ||
for job in ts['producers']: | ||
strip_extra_info(job) | ||
for job in ts['consumers']: | ||
strip_extra_info(job) | ||
|
||
if is_windows(two_stage[0]['producers'][0]): | ||
windows_two_stage[group_name] = two_stage | ||
else: | ||
linux_two_stage[group_name] = two_stage | ||
|
||
dispatch = { | ||
'linux_standalone': { | ||
'keys': list(linux_standalone.keys()), | ||
'jobs': linux_standalone}, | ||
'linux_two_stage': { | ||
'keys': list(linux_two_stage.keys()), | ||
'jobs': linux_two_stage}, | ||
'windows_standalone': { | ||
'keys': list(windows_standalone.keys()), | ||
'jobs': windows_standalone}, | ||
'windows_two_stage': { | ||
'keys': list(windows_two_stage.keys()), | ||
'jobs': windows_two_stage} | ||
} | ||
|
||
os.makedirs('dispatch', exist_ok=True) | ||
write_json_file('dispatch/dispatch.json', dispatch) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Prepare a full workflow for GHA dispatch.') | ||
parser.add_argument('workflow_json', help='Path to the full workflow.json file') | ||
args = parser.parse_args() | ||
|
||
# Check if the workflow file exists | ||
if not os.path.isfile(args.workflow_json): | ||
print(f"Error: Matrix file '{args.workflow_json}' not found.") | ||
sys.exit(1) | ||
|
||
with open(args.workflow_json) as f: | ||
workflow = json.load(f) | ||
|
||
split_workflow(workflow) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
name: "Run Linux Job" | ||
description: "Run a job on a Linux runner." | ||
|
||
inputs: | ||
id: | ||
description: "A unique identifier." | ||
required: true | ||
command: | ||
description: "The command to run." | ||
required: true | ||
image: | ||
description: "The Docker image to use." | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
path: ${{github.event.repository.name}} | ||
persist-credentials: false | ||
- name: Link files to coder user home directory | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
ln -s "$(pwd)/${{github.event.repository.name}}" /home/coder/${{github.event.repository.name}} | ||
chown -R coder:coder ${{github.event.repository.name}} | ||
chown -R coder:coder /home/coder/${{github.event.repository.name}} | ||
- name: Add NVCC problem matcher | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
echo "::add-matcher::${{github.event.repository.name}}/.github/problem-matchers/problem-matcher.json" | ||
- name: Get AWS credentials for sccache bucket | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
role-to-assume: arn:aws:iam::279114543810:role/gha-oidc-NVIDIA | ||
aws-region: us-east-2 | ||
role-duration-seconds: 43200 # 12 hours) | ||
- name: Set environment variables | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
echo "SCCACHE_BUCKET=rapids-sccache-devs" >> $GITHUB_ENV | ||
echo "SCCACHE_REGION=us-east-2" >> $GITHUB_ENV | ||
echo "SCCACHE_IDLE_TIMEOUT=32768" >> $GITHUB_ENV | ||
echo "SCCACHE_S3_USE_SSL=true" >> $GITHUB_ENV | ||
echo "SCCACHE_S3_NO_CREDENTIALS=false" >> $GITHUB_ENV | ||
- name: Run command # Do not change this step's name, it is checked in parse-job-times.py | ||
shell: su coder {0} | ||
env: | ||
# Dereferencing the command from and env var instead of a GHA input avoids issues with escaping | ||
# semicolons and other special characters (e.g. `-arch "60;70;80"`). | ||
COMMAND: ${{inputs.command}} | ||
run: | | ||
set -eo pipefail | ||
cd ~/${{github.event.repository.name}} | ||
echo -e "\e[1;34mRunning as 'coder' user in $(pwd):\e[0m" | ||
echo -e "\e[1;34m${COMMAND}\e[0m" | ||
eval "${COMMAND}" || exit_code=$? | ||
if [ ! -z "$exit_code" ]; then | ||
echo -e "::group::️❗ \e[1;31mInstructions to Reproduce CI Failure Locally\e[0m" | ||
echo "::error:: To replicate this failure locally, follow the steps below:" | ||
echo "1. Clone the repository, and navigate to the correct branch and commit:" | ||
echo " git clone --branch $GITHUB_REF_NAME --single-branch https://github.com/$GITHUB_REPOSITORY.git && cd $(echo $GITHUB_REPOSITORY | cut -d'/' -f2) && git checkout $GITHUB_SHA" | ||
echo "" | ||
echo "2. Run the failed command inside the same Docker container used by the CI:" | ||
echo " docker run --rm -it --gpus all --pull=always --volume \$PWD:/repo --workdir /repo ${{ inputs.image }} ${COMMAND}" | ||
echo "" | ||
echo "For additional information, see:" | ||
echo " - DevContainer Documentation: https://github.com/NVIDIA/cccl/blob/main/.devcontainer/README.md" | ||
echo " - Continuous Integration (CI) Overview: https://github.com/NVIDIA/cccl/blob/main/ci-overview.md" | ||
exit $exit_code | ||
fi | ||
- name: Prepare job artifacts | ||
id: done | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
echo "SUCCESS=true" | tee -a "${GITHUB_OUTPUT}" | ||
result_dir="jobs/${{inputs.id}}" | ||
mkdir -p "$result_dir" | ||
touch "$result_dir/success" | ||
# Finds a matching file in the repo directory and copies it to the results directory. | ||
find_and_copy() { | ||
filename="$1" | ||
filepath="$(find ${{github.event.repository.name}} -name "${filename}" -print -quit)" | ||
if [[ -z "$filepath" ]]; then | ||
echo "${filename} does not exist in repo directory." | ||
return 1 | ||
fi | ||
cp -v "$filepath" "$result_dir" | ||
} | ||
find_and_copy "sccache_stats.json" || true # Ignore failures | ||
echo "::group::Job artifacts" | ||
tree "$result_dir" | ||
echo "::endgroup::" | ||
- name: Upload job artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: jobs | ||
path: jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: "Run Linux Job" | ||
description: "Run a job on a Linux runner." | ||
|
||
inputs: | ||
image: { type: string, required: true } | ||
command: { type: string, required: true } | ||
id: { type: string, required: true } | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Get AWS credentials for sccache bucket | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
role-to-assume: arn:aws:iam::279114543810:role/gha-oidc-NVIDIA | ||
aws-region: us-east-2 | ||
role-duration-seconds: 43200 # 12 hours | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
path: ${{github.event.repository.name}} | ||
persist-credentials: false | ||
- name: Fetch ${{ inputs.image }} | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: docker pull ${{ inputs.image }} | ||
- name: Prepare paths for docker | ||
id: paths | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
echo "HOST_REPO=${{ github.workspace }}\${{ github.event.repository.name }}".Replace('\', '/') | Out-File -FilePath $env:GITHUB_OUTPUT -Append | ||
echo "MOUNT_REPO=C:/${{ github.event.repository.name }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Append | ||
cat $env:GITHUB_OUTPUT | ||
shell: powershell | ||
- name: Run command # Do not change this step's name, it is checked in parse-job-times.py | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
docker run \ | ||
--mount type=bind,source="${{steps.paths.outputs.HOST_REPO}}",target="${{steps.paths.outputs.MOUNT_REPO}}" \ | ||
--workdir "${{steps.paths.outputs.MOUNT_REPO}}" \ | ||
${{ inputs.image }} \ | ||
powershell -c " | ||
[System.Environment]::SetEnvironmentVariable('AWS_ACCESS_KEY_ID','${{env.AWS_ACCESS_KEY_ID}}'); | ||
[System.Environment]::SetEnvironmentVariable('AWS_SECRET_ACCESS_KEY','${{env.AWS_SECRET_ACCESS_KEY}}'); | ||
[System.Environment]::SetEnvironmentVariable('AWS_SESSION_TOKEN','${{env.AWS_SESSION_TOKEN }}'); | ||
[System.Environment]::SetEnvironmentVariable('SCCACHE_BUCKET','${{env.SCCACHE_BUCKET}}'); | ||
[System.Environment]::SetEnvironmentVariable('SCCACHE_REGION','${{env.SCCACHE_REGION}}'); | ||
[System.Environment]::SetEnvironmentVariable('SCCACHE_IDLE_TIMEOUT','${{env.SCCACHE_IDLE_TIMEOUT}}'); | ||
[System.Environment]::SetEnvironmentVariable('SCCACHE_S3_USE_SSL','${{env.SCCACHE_S3_USE_SSL}}'); | ||
[System.Environment]::SetEnvironmentVariable('SCCACHE_S3_NO_CREDENTIALS','${{env.SCCACHE_S3_NO_CREDENTIALS}}'); | ||
git config --global --add safe.directory '${{steps.paths.outputs.MOUNT_REPO}}'; | ||
${{inputs.command}}" | ||
- name: Prepare job artifacts | ||
id: done | ||
shell: bash --noprofile --norc -euo pipefail {0} | ||
run: | | ||
echo "SUCCESS=true" | tee -a "${GITHUB_OUTPUT}" | ||
result_dir="jobs/${{inputs.id}}" | ||
mkdir -p "$result_dir" | ||
touch "$result_dir/success" | ||
# Finds a matching file in the repo directory and copies it to the results directory. | ||
find_and_copy() { | ||
filename="$1" | ||
filepath="$(find ${{github.event.repository.name}} -name "${filename}" -print -quit)" | ||
if [[ -z "$filepath" ]]; then | ||
echo "${filename} does not exist in repo directory." | ||
return 1 | ||
fi | ||
cp -v "$filepath" "$result_dir" | ||
} | ||
find_and_copy "sccache_stats.json" || true # Ignore failures | ||
echo "::group::Job artifacts" | ||
find "$result_dir" # Tree not available in this image. | ||
echo "::endgroup::" | ||
- name: Upload job artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: jobs | ||
path: jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.