Skip to content

Commit 3ac5067

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 3ac5067

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
"

.github/workflows/integration-tests.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@ 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'
32+
needs: check-token
33+
if: github.event_name == 'pull_request' && needs.check-token.outputs.has_token == 'true'
1434
environment: "test-trigger-is"
15-
1635
steps:
1736
- uses: actions/checkout@v3
1837

0 commit comments

Comments
 (0)