|
| 1 | +name: Sagemaker PR Checks |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + branches: |
| 5 | + - "master*" |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.head_ref }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + id-token: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + collab-check: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + approval-env: ${{ steps.collab-check.outputs.result }} |
| 19 | + steps: |
| 20 | + - name: Collaborator Check |
| 21 | + uses: actions/github-script@v7 |
| 22 | + id: collab-check |
| 23 | + with: |
| 24 | + github-token: ${{ secrets.COLLAB_CHECK_TOKEN }} |
| 25 | + result-encoding: string |
| 26 | + script: | |
| 27 | + try { |
| 28 | + const res = await github.rest.repos.checkCollaborator({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + username: "${{ github.event.pull_request.user.login }}", |
| 32 | + }); |
| 33 | + console.log("Verifed ${{ github.event.pull_request.user.login }} is a repo collaborator. Auto Approving PR Checks.") |
| 34 | + return res.status == "204" ? "auto-approve" : "manual-approval" |
| 35 | + } catch (error) { |
| 36 | + console.log("${{ github.event.pull_request.user.login }} is not a collaborator. Requiring Manual Approval to run PR Checks.") |
| 37 | + return "manual-approval" |
| 38 | + } |
| 39 | + wait-for-approval: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: [ collab-check ] |
| 42 | + environment: ${{ needs.collab-check.outputs.approval-env }} |
| 43 | + steps: |
| 44 | + - run: echo "Workflow Approved! Starting PR Checks." |
| 45 | + detect-changes: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: [wait-for-approval] |
| 48 | + if: github.event.pull_request.base.ref != 'master-v2' |
| 49 | + outputs: |
| 50 | + submodules: ${{ steps.check-changes.outputs.submodules }} |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v3 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + token: ${{ secrets.GH_PAT }} # or use appropriate token |
| 56 | + ref: ${{ github.event.pull_request.base.ref }} # Target branch (master-v3) |
| 57 | + - name: Detect Changes |
| 58 | + id: check-changes |
| 59 | + run: | |
| 60 | + set -e # Exit on error |
| 61 | + |
| 62 | + # Debug information |
| 63 | + echo "Target Branch: ${{ github.event.pull_request.base.ref }}" |
| 64 | + echo "Current Target SHA: $(git rev-parse HEAD)" |
| 65 | + echo "PR Number: ${{ github.event.pull_request.number }}" |
| 66 | + echo "PR Latest SHA: ${{ github.event.pull_request.head.sha }}" |
| 67 | + # Fetch PR without creating a branch |
| 68 | + git fetch origin pull/${{ github.event.pull_request.number }}/head |
| 69 | + CHANGES=$(git diff --name-only HEAD FETCH_HEAD) |
| 70 | + |
| 71 | + echo "Changed files:" |
| 72 | + echo "$CHANGES" |
| 73 | + |
| 74 | + SUBMODULES=[] |
| 75 | + |
| 76 | + if echo "$CHANGES" | grep -q "^sagemaker-train/"; then |
| 77 | + SUBMODULES='["sagemaker-train"]' |
| 78 | + fi |
| 79 | + if echo "$CHANGES" | grep -q "^sagemaker-serve/"; then |
| 80 | + if [ "$SUBMODULES" = '[]' ]; then |
| 81 | + SUBMODULES='["sagemaker-serve"]' |
| 82 | + else |
| 83 | + SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-serve"\]/') |
| 84 | + fi |
| 85 | + fi |
| 86 | + if echo "$CHANGES" | grep -q "^sagemaker-mlops/"; then |
| 87 | + if [ "$SUBMODULES" = '[]' ]; then |
| 88 | + SUBMODULES='["sagemaker-mlops"]' |
| 89 | + else |
| 90 | + SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-mlops"\]/') |
| 91 | + fi |
| 92 | + fi |
| 93 | + if echo "$CHANGES" | grep -q "^sagemaker-core/"; then |
| 94 | + if [ "$SUBMODULES" = '[]' ]; then |
| 95 | + SUBMODULES='["sagemaker-core"]' |
| 96 | + else |
| 97 | + SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-core"\]/') |
| 98 | + fi |
| 99 | + fi |
| 100 | + echo "Final SUBMODULES: $SUBMODULES" |
| 101 | + echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT |
| 102 | +
|
| 103 | + codestyle-doc-tests: |
| 104 | + runs-on: ubuntu-latest |
| 105 | + needs: [detect-changes] |
| 106 | + if: needs.detect-changes.outputs.submodules != '[]' |
| 107 | + strategy: |
| 108 | + fail-fast: false |
| 109 | + matrix: |
| 110 | + submodule: ${{ fromJson(needs.detect-changes.outputs.submodules) }} |
| 111 | + steps: |
| 112 | + - name: Configure AWS Credentials |
| 113 | + uses: aws-actions/configure-aws-credentials@v4 |
| 114 | + with: |
| 115 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 116 | + aws-region: us-west-2 |
| 117 | + role-duration-seconds: 10800 |
| 118 | + |
| 119 | + - name: Run CodeBuild for ${{ matrix.submodule }} |
| 120 | + uses: aws-actions/aws-codebuild-run-build@v1 |
| 121 | + with: |
| 122 | + project-name: ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-codestyle-doc-tests |
| 123 | + source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}' |
| 124 | + |
| 125 | + codestyle-doc-tests-v2: |
| 126 | + runs-on: ubuntu-latest |
| 127 | + needs: [wait-for-approval] |
| 128 | + if: github.event.pull_request.base.ref == 'master-v2' |
| 129 | + steps: |
| 130 | + - name: Configure AWS Credentials |
| 131 | + uses: aws-actions/configure-aws-credentials@v4 |
| 132 | + with: |
| 133 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 134 | + aws-region: us-west-2 |
| 135 | + role-duration-seconds: 10800 |
| 136 | + - name: Run Codestyle & Doc Tests |
| 137 | + uses: aws-actions/aws-codebuild-run-build@v1 |
| 138 | + with: |
| 139 | + project-name: ${{ github.event.repository.name }}-ci-codestyle-doc-tests |
| 140 | + source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}' |
| 141 | + |
| 142 | + unit-tests: |
| 143 | + runs-on: ubuntu-latest |
| 144 | + needs: [detect-changes] |
| 145 | + if: needs.detect-changes.outputs.submodules != '[]' |
| 146 | + strategy: |
| 147 | + fail-fast: false |
| 148 | + matrix: |
| 149 | + submodule: ${{ fromJson(needs.detect-changes.outputs.submodules) }} |
| 150 | + steps: |
| 151 | + - name: Configure AWS Credentials |
| 152 | + uses: aws-actions/configure-aws-credentials@v4 |
| 153 | + with: |
| 154 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 155 | + aws-region: us-west-2 |
| 156 | + role-duration-seconds: 10800 |
| 157 | + |
| 158 | + - name: Run Unit Tests for ${{ matrix.submodule }} |
| 159 | + uses: aws-actions/aws-codebuild-run-build@v1 |
| 160 | + with: |
| 161 | + project-name: ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-unit-tests |
| 162 | + source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}' |
| 163 | + |
| 164 | + unit-tests-v2: |
| 165 | + runs-on: ubuntu-latest |
| 166 | + needs: [wait-for-approval] |
| 167 | + if: github.event.pull_request.base.ref == 'master-v2' |
| 168 | + strategy: |
| 169 | + fail-fast: false |
| 170 | + matrix: |
| 171 | + python-version: ["py39","py310","py311","py312"] |
| 172 | + steps: |
| 173 | + - name: Configure AWS Credentials |
| 174 | + uses: aws-actions/configure-aws-credentials@v4 |
| 175 | + with: |
| 176 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 177 | + aws-region: us-west-2 |
| 178 | + role-duration-seconds: 10800 |
| 179 | + - name: Run Unit Tests |
| 180 | + uses: aws-actions/aws-codebuild-run-build@v1 |
| 181 | + with: |
| 182 | + project-name: ${{ github.event.repository.name }}-ci-unit-tests |
| 183 | + source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}' |
| 184 | + env-vars-for-codebuild: | |
| 185 | + PY_VERSION |
| 186 | + env: |
| 187 | + PY_VERSION: ${{ matrix.python-version }} |
| 188 | + |
| 189 | + integ-tests: |
| 190 | + runs-on: ubuntu-latest |
| 191 | + needs: [detect-changes] |
| 192 | + if: needs.detect-changes.outputs.submodules != '[]' |
| 193 | + strategy: |
| 194 | + fail-fast: false |
| 195 | + matrix: |
| 196 | + submodule: ${{ fromJson(needs.detect-changes.outputs.submodules) }} |
| 197 | + steps: |
| 198 | + - name: Configure AWS Credentials |
| 199 | + uses: aws-actions/configure-aws-credentials@v4 |
| 200 | + with: |
| 201 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 202 | + aws-region: us-west-2 |
| 203 | + role-duration-seconds: 10800 |
| 204 | + |
| 205 | + - name: Run Integ Tests for ${{ matrix.submodule }} |
| 206 | + uses: aws-actions/aws-codebuild-run-build@v1 |
| 207 | + with: |
| 208 | + project-name: ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-integ-tests |
| 209 | + source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}' |
| 210 | + |
| 211 | + integ-tests-v2: |
| 212 | + runs-on: ubuntu-latest |
| 213 | + needs: [wait-for-approval] |
| 214 | + if: github.event.pull_request.base.ref == 'master-v2' |
| 215 | + steps: |
| 216 | + - name: Configure AWS Credentials |
| 217 | + uses: aws-actions/configure-aws-credentials@v4 |
| 218 | + with: |
| 219 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 220 | + aws-region: us-west-2 |
| 221 | + role-duration-seconds: 10800 |
| 222 | + - name: Run Integ Tests |
| 223 | + uses: aws-actions/aws-codebuild-run-build@v1 |
| 224 | + with: |
| 225 | + project-name: ${{ github.event.repository.name }}-ci-integ-tests |
| 226 | + source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}' |
0 commit comments