Skip to content

Commit fb64672

Browse files
committed
[Internal] Add test instructions for external contributors (#370)
Add test instructions for external contributors See Go Changes databricks/databricks-sdk-go#1073
1 parent 779b6e3 commit fb64672

File tree

2 files changed

+101
-2
lines changed

2 files changed

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

.github/workflows/integration-tests.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,29 @@ on:
77
merge_group:
88

99
jobs:
10+
check-token:
11+
name: Check secrets access
12+
runs-on: ubuntu-latest
13+
outputs:
14+
has_token: ${{ steps.set-token-status.outputs.has_token }}
15+
steps:
16+
- name: Check if GITHUB_TOKEN is set
17+
id: set-token-status
18+
run: |
19+
if [ -z "${{ secrets.GITHUB_TOKEN }}" ]; then
20+
echo "GITHUB_TOKEN is empty. User has no access to tokens."
21+
echo "::set-output name=has_token::false"
22+
else
23+
echo "GITHUB_TOKEN is set. User has access to tokens."
24+
echo "::set-output name=has_token::false"
25+
fi
26+
1027
trigger-tests:
11-
if: github.event_name == 'pull_request'
1228
name: Trigger Tests
1329
runs-on: ubuntu-latest
30+
needs: check-token
31+
if: github.event_name == 'pull_request' && needs.check-token.outputs.has_token == 'true'
1432
environment: "test-trigger-is"
15-
1633
steps:
1734
- uses: actions/checkout@v3
1835

0 commit comments

Comments
 (0)