Skip to content

Commit

Permalink
Factor out build/test logic into reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeepyjack committed Jul 15, 2023
1 parent 674063f commit 14a38f4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 56 deletions.
72 changes: 16 additions & 56 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,23 @@ jobs:
build:
if: inputs.build_script != '' && inputs.build_image != ''
name: Build ${{inputs.compiler}}${{inputs.compiler_version}}/C++${{inputs.std}}
runs-on: ${{ (inputs.os == 'windows' && 'windows-latest') || format('linux-{0}-cpu16', inputs.cpu) }}
container:
options: -u root
image: ${{ inputs.build_image }}
permissions:
id-token: write
steps:
- name: Echo git version
run: git --version
- name: Checkout repo
uses: actions/checkout@v3
- name: Configure credentials and environment variables for sccache
uses: ./.github/actions/configure_cccl_sccache
- name: Run build script
run: |
sccache -s > sccache_before.txt
cmd="${{ inputs.build_script }} \"${{inputs.compiler_exe}}\" \"${{inputs.std}}\" \"${{inputs.gpu_build_archs}}\""
eval $cmd || exit_code=$?
if [ ! -z "$exit_code" ]; then
echo "::error::Build failed! To checkout the corresponding code and reproduce this build locally, run the following commands:"
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 "docker run --rm -it --gpus all --pull=always --volume \$PWD:/repo --workdir /repo ${{ inputs.build_image }} $cmd"
echo "Alternatively, for a more convenient, interactive environment to reproduce the issue, you can launch a devcontainer in vscode:"
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 ".devcontainer/launch.sh ${{inputs.cuda_version}} ${{inputs.compiler}}${{inputs.compiler_version}}"
echo "Then, open a terminal inside vscode (ctrl+shift+\`) and run:"
echo "$cmd"
exit $exit_code
fi
sccache -s > sccache_after.txt
- name: Calculate sccache hit rate
run: |
hit_rate=$(./ci/sccache_hit_rate.sh sccache_before.txt sccache_after.txt 2>&1 >/dev/null)
echo "sccache hit rate: $hit_rate" >> $GITHUB_STEP_SUMMARY
uses: ./.github/workflows/run-as-coder.yml
with:
name: Build ${{inputs.compiler}}${{inputs.compiler_version}}/C++${{inputs.std}}
runner: linux-${{inputs.cpu}}-cpu16
image: ${{inputs.build_image}}
command: |
${{ inputs.build_script }} "${{inputs.compiler_exe}}" "${{inputs.std}}" "${{inputs.gpu_build_archs}}"
test:
needs: build
if: ${{ !cancelled() && ( needs.build.result == 'success' || needs.build.result == 'skipped' ) && inputs.test_script != '' && inputs.test_image != '' }}
name: Test ${{inputs.compiler}}${{inputs.compiler_version}}/C++${{inputs.std}}
runs-on: linux-${{inputs.cpu}}-gpu-v100-latest-1
container:
options: -u root
image: ${{ inputs.test_image }}
env:
NVIDIA_VISIBLE_DEVICES: ${{ env.NVIDIA_VISIBLE_DEVICES }}
permissions:
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Configure credentials and environment variables for sccache
uses: ./.github/actions/configure_cccl_sccache
- name: Run test script
run: |
sccache -s > sccache_before.txt
time ./${{ inputs.test_script }} "${{inputs.compiler_exe}}" "${{inputs.std}}" "${{inputs.gpu_build_archs}}"
sccache -s > sccache_after.txt
- name: Calculate sccache hit rate
run: |
hit_rate=$(./ci/sccache_hit_rate.sh sccache_before.txt sccache_after.txt 2>&1 >/dev/null)
echo "sccache hit rate: $hit_rate" >> $GITHUB_STEP_SUMMARY
uses: ./.github/workflows/run-as-coder.yml
with:
name: Test ${{inputs.compiler}}${{inputs.compiler_version}}/C++${{inputs.std}}
runner: linux-${{inputs.cpu}}-gpu-v100-latest-1
image: ${{inputs.test_image}}
command: |
nvidia-smi
${{ inputs.test_script }} "${{inputs.compiler_exe}}" "${{inputs.std}}" "${{inputs.gpu_build_archs}}"
50 changes: 50 additions & 0 deletions .github/workflows/run-as-coder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Run as coder user

defaults:
run:
shell: bash -exo pipefail {0}


on:
workflow_call:
inputs:
name: {type: string, required: true}
image: {type: string, required: true}
runner: {type: string, required: true}
command: {type: string, required: true}
env: { type: string, required: false, default: "" }

jobs:
run-as-coder:
name: ${{inputs.name}}
runs-on: ${{inputs.runner}}
container:
options: -u root
image: ${{inputs.image}}
env:
NVIDIA_VISIBLE_DEVICES: ${{ env.NVIDIA_VISIBLE_DEVICES }}
permissions:
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: cuCollections
persist-credentials: false
- name: Move files to coder user home directory
run: |
cp -R cuCollections /home/coder/cuCollections
chown -R coder:coder /home/coder/
- name: Configure credentials and environment variables for sccache
uses: ./cuCollections/.github/actions/configure_cccl_sccache
- name: Run command
shell: su coder {0}
run: |
cd ~/cuCollections
eval "${{inputs.command}}" || exit_code=$?
if [ ! -z "$exit_code" ]; then
echo "::error::Error! To checkout the corresponding code and reproduce locally, run the following commands:"
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 "docker run --rm -it --gpus all --pull=always --volume \$PWD:/repo --workdir /repo ${{ inputs.image }} ${{inputs.command}}"
exit $exit_code
fi

0 comments on commit 14a38f4

Please sign in to comment.