feat: add e2e-test comment as trigger for e2e test in codebuild #7
Workflow file for this run
This file contains hidden or 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
| name: Trigger AWS CodeBuild (OIDC) | |
| on: | |
| #issue_comment: | |
| #types: [created] | |
| pull_request: | |
| branches: [ "master" ] | |
| jobs: | |
| trigger-build: | |
| # Run only if it's a PR and the comment starts with /test-e2e | |
| #if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/test-e2e') | |
| runs-on: ubuntu-latest | |
| # CRITICAL PERMISSIONS FOR OIDC TO WORK | |
| permissions: | |
| id-token: write # Required to request the OIDC token from GitHub | |
| contents: read # Required to read repo contents | |
| pull-requests: write # Required to post comments on the PR | |
| steps: | |
| # 1. Fetch the specific Commit SHA from the PR | |
| # (Issue comments are not tied to code context, so we must fetch the PR head manually) | |
| - name: Get PR Commit SHA | |
| id: pr_info | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number, | |
| }); | |
| console.log(`Target Commit SHA: ${pr.head.sha}`); | |
| core.setOutput('sha', pr.head.sha); | |
| # 2. Authenticate with AWS using OIDC | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} | |
| aws-region: us-east-1 | |
| # 3. Trigger the CodeBuild project remotely | |
| - name: Trigger AWS CodeBuild | |
| id: build | |
| run: | | |
| echo "🚀 Triggering CodeBuild for commit ${{ steps.pr_info.outputs.sha }}..." | |
| # Start the build pointing to the specific commit SHA | |
| BUILD_ID=$(aws codebuild start-build \ | |
| --project-name clowder-pr-check \ | |
| --source-version ${{ steps.pr_info.outputs.sha }} \ | |
| --query 'build.id' \ | |
| --output text) | |
| echo "build_id=$BUILD_ID" >> $GITHUB_OUTPUT | |
| echo "✅ Build started! ID: $BUILD_ID" | |
| # 4. Post a comment on the PR with the link to AWS Logs | |
| - name: Post Logs Link to PR | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const buildId = '${{ steps.build.outputs.build_id }}'; | |
| const region = 'us-east-1'; // Adjust if using a different region | |
| const url = `https://${region}.console.aws.amazon.com/codesuite/codebuild/projects/clowder-release-test/build/${buildId}/log?region=${region}`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `🚀 **E2E Tests Started via OIDC!**\n\nCodeBuild is running your tests on commit \`${{ steps.pr_info.outputs.sha }}\`.\n\n[🔍 View AWS Logs Here](${url})` | |
| }); |