1+ name : Submodule PR Checks
2+ on :
3+ pull_request_target :
4+ branches :
5+ - " master-v3"
6+ paths :
7+ - ' sagemaker_train/**'
8+ - ' sagemaker_utils/**'
9+
10+ concurrency :
11+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.head_ref }}
12+ cancel-in-progress : true
13+
14+ permissions :
15+ id-token : write
16+
17+ jobs :
18+ collab-check :
19+ runs-on : ubuntu-latest
20+ outputs :
21+ approval-env : ${{ steps.collab-check.outputs.result }}
22+ steps :
23+ - name : Collaborator Check
24+ uses : actions/github-script@v7
25+ id : collab-check
26+ with :
27+ github-token : ${{ secrets.COLLAB_CHECK_TOKEN }}
28+ result-encoding : string
29+ script : |
30+ try {
31+ const res = await github.rest.repos.checkCollaborator({
32+ owner: context.repo.owner,
33+ repo: context.repo.repo,
34+ username: "${{ github.event.pull_request.user.login }}",
35+ });
36+ console.log("Verifed ${{ github.event.pull_request.user.login }} is a repo collaborator. Auto Approving PR Checks.")
37+ return res.status == "204" ? "auto-approve" : "manual-approval"
38+ } catch (error) {
39+ console.log("${{ github.event.pull_request.user.login }} is not a collaborator. Requiring Manual Approval to run PR Checks.")
40+ return "manual-approval"
41+ }
42+ wait-for-approval :
43+ runs-on : ubuntu-latest
44+ needs : [ collab-check ]
45+ environment : ${{ needs.collab-check.outputs.approval-env }}
46+ steps :
47+ - run : echo "Workflow Approved! Starting PR Checks."
48+ detect-changes :
49+ runs-on : ubuntu-latest
50+ needs : [wait-for-approval]
51+ outputs :
52+ submodules : ${{ steps.check-changes.outputs.submodules }}
53+ steps :
54+ - uses : actions/checkout@v3
55+ with :
56+ fetch-depth : 0
57+ token : ${{ secrets.REPO_ACCESS_KEY }} # or use appropriate token
58+ ref : ${{ github.event.pull_request.base.ref }} # Target branch (master-v3)
59+ - name : Detect Changes
60+ id : check-changes
61+ run : |
62+ set -e # Exit on error
63+
64+ # Debug information
65+ echo "Target Branch: ${{ github.event.pull_request.base.ref }}"
66+ echo "Current Target SHA: $(git rev-parse HEAD)"
67+ echo "PR Number: ${{ github.event.pull_request.number }}"
68+ echo "PR Latest SHA: ${{ github.event.pull_request.head.sha }}"
69+ # Fetch PR without creating a branch
70+ git fetch origin pull/${{ github.event.pull_request.number }}/head
71+ CHANGES=$(git diff --name-only HEAD FETCH_HEAD)
72+
73+ echo "Changed files:"
74+ echo "$CHANGES"
75+
76+ SUBMODULES=[]
77+
78+ if echo "$CHANGES" | grep -q "^sagemaker_train/"; then
79+ SUBMODULES='["sagemaker_train"]'
80+ fi
81+ if echo "$CHANGES" | grep -q "^sagemaker_utils/"; then
82+ if [ "$SUBMODULES" = '[]' ]; then
83+ SUBMODULES='["sagemaker_utils"]'
84+ else
85+ SUBMODULES='["sagemaker_train","sagemaker_utils"]'
86+ fi
87+ fi
88+ echo "Final SUBMODULES: $SUBMODULES"
89+ echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT
90+
91+ submodule-codestyle-doc-tests :
92+ runs-on : ubuntu-latest
93+ needs : [detect-changes]
94+ if : needs.detect-changes.outputs.submodules != '[]'
95+ strategy :
96+ matrix :
97+ submodule : ${{ fromJson(needs.detect-changes.outputs.submodules) }}
98+ steps :
99+ - name : Configure AWS Credentials
100+ uses : aws-actions/configure-aws-credentials@v4
101+ with :
102+ role-to-assume : ${{ secrets.CI_AWS_ROLE_ARN }}
103+ aws-region : us-west-2
104+ role-duration-seconds : 10800
105+
106+ - name : Run CodeBuild for ${{ matrix.submodule }}
107+ uses : aws-actions/aws-codebuild-run-build@v1
108+ with :
109+ project-name : ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-codestyle-doc-tests
110+ source-version-override : ' refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'
111+
112+ submodule-unit-tests :
113+ runs-on : ubuntu-latest
114+ needs : [detect-changes]
115+ if : needs.detect-changes.outputs.submodules != '[]'
116+ strategy :
117+ fail-fast : false
118+ matrix :
119+ submodule : ${{ fromJson(needs.detect-changes.outputs.submodules) }}
120+ steps :
121+ - name : Configure AWS Credentials
122+ uses : aws-actions/configure-aws-credentials@v4
123+ with :
124+ role-to-assume : ${{ secrets.CI_AWS_ROLE_ARN }}
125+ aws-region : us-west-2
126+ role-duration-seconds : 10800
127+
128+ - name : Run Unit Tests for ${{ matrix.submodule }}
129+ uses : aws-actions/aws-codebuild-run-build@v1
130+ with :
131+ project-name : ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-unit-tests
132+ source-version-override : ' refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'
133+
134+ submodule-integ-tests :
135+ runs-on : ubuntu-latest
136+ needs : [detect-changes]
137+ if : needs.detect-changes.outputs.submodules != '[]'
138+ strategy :
139+ matrix :
140+ submodule : ${{ fromJson(needs.detect-changes.outputs.submodules) }}
141+ steps :
142+ - name : Configure AWS Credentials
143+ uses : aws-actions/configure-aws-credentials@v4
144+ with :
145+ role-to-assume : ${{ secrets.CI_AWS_ROLE_ARN }}
146+ aws-region : us-west-2
147+ role-duration-seconds : 10800
148+
149+ - name : Run Integ Tests for ${{ matrix.submodule }}
150+ uses : aws-actions/aws-codebuild-run-build@v1
151+ with :
152+ project-name : ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-integ-tests
153+ source-version-override : ' refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'
0 commit comments