11# SPDX-License-Identifier: Apache-2.0
22
3- name : " Run 'fast' marked unit tests via Tox::pytest"
3+ name : " Run unit tests via Tox::pytest"
44# This tests should run only those tests that are marked as 'fast.'
55# The opposite are those that would require the mark 'slow,' which would
66# include longer-running integration and smoke tests.
@@ -10,12 +10,33 @@ name: "Run 'fast' marked unit tests via Tox::pytest"
1010# to verify integration correctness.
1111
1212on :
13- pull_request :
14- types : [opened, reopened, synchronize]
13+ # run against every merge commit to 'main' and release branches
1514 push :
1615 branches :
17- - " main"
18- - " release-**"
16+ - main
17+ - release-*
18+ # only run on PRs that touch certain regex paths
19+ pull_request_target :
20+ branches :
21+ - main
22+ - release-*
23+ paths :
24+ # note this should match the merging criteria in 'mergify.yml'
25+ - " **.py"
26+ - " pyproject.toml"
27+ - " requirements**.txt"
28+ - " .github/workflows/unit-tests.yaml" # This workflow
29+
30+ concurrency :
31+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
32+ cancel-in-progress : true
33+
34+ permissions :
35+ contents : read
36+
37+ defaults :
38+ run :
39+ shell : bash
1940
2041env :
2142 pytest_mark : " fast"
2647 runs-on : ubuntu-latest
2748 outputs :
2849 label : ${{ steps.start-ec2-runner.outputs.label }}
29- ec2-instance-id : ${{ steps.start-ec2-runner.outputs.label }}
50+ ec2-instance-id : ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
3051
3152 steps :
3253 - name : " Harden runner"
@@ -48,13 +69,13 @@ jobs:
4869 mode : start
4970 github-token : ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
5071 ec2-image-id : ${{ vars.AWS_EC2_AMI }}
51- ec2-instance-type : ${{ vars.AWS_REGION }}
72+ ec2-instance-type : ${{ env.ec2_runner_variant }}
5273 subnet-id : subnet-024298cefa3bedd61
5374 security-group-id : sg-06300447c4a5fbef3
5475 iam-role-name : instructlab-ci-runner
5576 aws-resource-tags : >
5677 [
57- {"Key": "Name", "Value": "instructlab-ci-github-large -runner"},
78+ {"Key": "Name", "Value": "instructlab-ci-github-unittest -runner"},
5879 {"Key": "GitHubRepository", "Value": "${{ github.repository }}"},
5980 {"Key": "GitHubRef", "Value": "${{ github.ref }}"},
6081 {"Key": "GitHubPR", "Value": "${{ github.event.number }}"}
6485 needs :
6586 - start-ec2-runner
6687 runs-on : ${{needs.start-ec2-runner.outputs.label}}
67- # This job MUST HAVE NO PERMISSIONS and no access to any secrets
68- # because it'll run incoming user code without discretion.
69- permissions : {} # this syntax disables permissions for all available options.
88+ # It is important that this job has no write permissions and has
89+ # no access to any secrets. This part is where we are running
90+ # untrusted code from PRs.
91+ permissions : {}
7092 steps :
7193 - name : " Harden runner"
7294 uses : step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.1
@@ -83,13 +105,6 @@ jobs:
83105 with :
84106 fetch-depth : 0
85107
86- - name : " Verify environment variables are setup correctly"
87- run : |
88- export CUDA_HOME="/usr/local/cuda"
89- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
90- export PATH="$PATH:$CUDA_HOME/bin"
91- nvidia-smi
92-
93108 # installs in $GITHUB_WORKSPACE/venv.
94109 # only has to install Tox because Tox will do the other virtual environment management.
95110 - name : " Setup Python virtual environment"
@@ -104,6 +119,7 @@ jobs:
104119
105120 - name : " Run unit tests with Tox and Pytest"
106121 run : |
122+ source venv/bin/activate
107123 tox -e py3-unit -- -m ${{env.pytest_mark}}
108124
109125 - name : " Show disk utilization AFTER tests"
@@ -115,11 +131,13 @@ jobs:
115131 - start-ec2-runner
116132 - run-unit-tests
117133 runs-on : ubuntu-latest
134+ if : ${{ always() }}
118135 steps :
119136 - name : " Harden runner"
120137 uses : step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.1
121138 with :
122139 egress-policy : audit
140+
123141 - name : " Configure AWS credentials"
124142 uses : " aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502" # v4.0.2
125143 with :
@@ -128,10 +146,9 @@ jobs:
128146 aws-region : ${{ vars.AWS_REGION }}
129147
130148 - name : " Stop EC2 runner"
131- id : start-ec2-runner
132149 uses : machulav/ec2-github-runner@1827d6ca7544d7044ddbd2e9360564651b463da2 # v2.3.7
133150 with :
134151 mode : stop
135152 github-token : ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
136153 label : ${{ needs.start-ec2-runner.outputs.label }}
137- ec2-instance-type : ${{ env.ec2_runner_variant }}
154+ ec2-instance-id : ${{ needs.start-ec2-runner.outputs.ec2-instance-id }}
0 commit comments