-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out build job logic into a "run-as-coder" reusable workflow.
- Loading branch information
Showing
2 changed files
with
51 additions
and
36 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
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,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 | ||