Skip to content

Commit

Permalink
Factor out build job logic into a "run-as-coder" reusable workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhemstad committed Jul 11, 2023
1 parent 25b7a06 commit 82ce325
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
41 changes: 5 additions & 36 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,11 @@ jobs:
build:
if: inputs.build_script != '' && inputs.build_image != ''
name: Build ${{inputs.compiler}}${{inputs.compiler_version}}/C++${{inputs.std}}
runs-on: linux-${{inputs.cpu}}-cpu16
container:
options: -u root
image: ${{ inputs.build_image }}
permissions:
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: cccl
# In order for sccache to be shared between CI and lcaal devcontainers, code needs to be in the same absolute path
# This ensures the code is in the same path as it is within the devcontainer
- name: Move files to coder user home directory
run: |
cp -R cccl /home/coder/cccl
chown -R coder:coder /home/coder/
- name: Configure credentials and environment variables for sccache
uses: ./cccl/.github/actions/configure_cccl_sccache
- name: Run build script
shell: su coder {0}
run: |
cd ~/cccl
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 --recurse-submodules 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 --recurse-submodules 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
uses: ./.github/workflows/run-as-coder.yml
with:
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 != '' && inputs.run_tests}}
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/run-as-coder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run as coder user

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


on:
workflow_call:
inputs:
image: {type: string, required: true}
runner: {type: string, required: true}
command: {type: string, required: true}

jobs:
run-as-coder:
name: Run ${{inputs.command}}
runs-on: ${{inputs.runner}}
container:
options: -u root
image: ${{inputs.image}}
permissions:
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: cccl
- name: Move files to coder user home directory
run: |
cp -R cccl /home/coder/cccl
chown -R coder:coder /home/coder/
- name: Configure credentials and environment variables for sccache
uses: ./cccl/.github/actions/configure_cccl_sccache
- name: Run command
shell: su coder {0}
run: |
cd ~/cccl
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 --recurse-submodules 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 82ce325

Please sign in to comment.