|
| 1 | +name: PR Comment |
| 2 | + |
| 3 | +# WARNING: |
| 4 | +# THIS WORKFLOW ALWAYS RUNS FOR EXTERNAL CONTRIBUTORS WITHOUT ANY APPROVAL. |
| 5 | +# THIS WORKFLOW RUNS FROM MAIN BRANCH, NOT FROM THE PR BRANCH. |
| 6 | +# DO NOT PULL THE PR OR EXECUTE ANY CODE FROM THE PR. |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request_target: |
| 10 | + types: [opened, reopened, synchronize] |
| 11 | + branches: |
| 12 | + - main |
| 13 | + |
| 14 | + pull_request: |
| 15 | + types: [opened, synchronize] |
| 16 | + |
| 17 | + |
| 18 | +jobs: |
| 19 | + comment-on-pr: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + pull-requests: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + |
| 27 | + # If the user has a token, the integration-tests.yml workflow will write a message. Wait |
| 28 | + # and check if the message is present. |
| 29 | + - name: Wait for 30 seconds |
| 30 | + run: sleep 30 |
| 31 | + shell: bash |
| 32 | + |
| 33 | + - name: Check for integration tests comment |
| 34 | + id: check-secrets-access |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 38 | + run: | |
| 39 | + comment_found=$(gh pr view $PR_NUMBER --json comments \ |
| 40 | + --jq '.comments[].body | select(startswith("<!-- INTEGRATION_TESTS -->"))' \ |
| 41 | + --repo ${{ github.repository }}) |
| 42 | + |
| 43 | + if [ -n "$comment_found" ]; then |
| 44 | + echo "has_secrets_access=true" >> $GITHUB_OUTPUT |
| 45 | + else |
| 46 | + echo "has_secrets_access=false" >> $GITHUB_OUTPUT |
| 47 | + fi |
| 48 | +
|
| 49 | + # If not found, write a comment for manual execution |
| 50 | + - name: Delete old comments |
| 51 | + if: steps.check-secrets-access.outputs.has_secrets_access != 'true' |
| 52 | + env: |
| 53 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + run: | |
| 55 | + # Delete previous comment if it exists |
| 56 | + previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ |
| 57 | + --jq '.[] | select(.body | startswith("<!-- INTEGRATION_TESTS_MANUAL -->")) | .id') |
| 58 | + echo "Previous comment IDs: $previous_comment_ids" |
| 59 | + # Iterate over each comment ID and delete the comment |
| 60 | + if [ ! -z "$previous_comment_ids" ]; then |
| 61 | + echo "$previous_comment_ids" | while read -r comment_id; do |
| 62 | + echo "Deleting comment with ID: $comment_id" |
| 63 | + gh api "repos/${{ github.repository }}/issues/comments/$comment_id" -X DELETE |
| 64 | + done |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Comment on PR |
| 68 | + if: steps.check-secrets-access.outputs.has_secrets_access != 'true' |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + COMMIT_SHA: ${{ github.event.pull_request.head.sha }} |
| 72 | + run: | |
| 73 | + gh pr comment ${{ github.event.pull_request.number }} --body \ |
| 74 | + "<!-- INTEGRATION_TESTS_MANUAL --> |
| 75 | + Run integration tests manually: |
| 76 | + [go/deco-tests-run/sdk-java](https://go/deco-tests-run/sdk-java) |
| 77 | +
|
| 78 | + Inputs: |
| 79 | + * PR number: ${{github.event.pull_request.number}} |
| 80 | + * Commit SHA: \`${{ env.COMMIT_SHA }}\` |
| 81 | + |
| 82 | + Checks will be approved automatically on success. |
| 83 | + " |
0 commit comments