Skip to content

Commit a465ea8

Browse files
committed
WIP
1 parent 2f08742 commit a465ea8

File tree

2 files changed

+27
-56
lines changed

2 files changed

+27
-56
lines changed

.github/workflows/external-message.yml

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
branches:
1212
- main
1313

14+
pull_request:
15+
types: [opened, synchronize]
16+
1417

1518
jobs:
1619
comment-on-pr:
@@ -19,73 +22,39 @@ jobs:
1922
pull-requests: write
2023

2124
steps:
22-
# NOTE: The following checks may not be accurate depending on Org or Repo settings.
23-
- name: Check user and potential secret access
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
2434
id: check-secrets-access
2535
env:
26-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
PR_NUMBER: ${{ github.event.pull_request.number }}
2738
run: |
28-
USER_LOGIN="${{ github.event.pull_request.user.login }}"
29-
REPO_OWNER="${{ github.repository_owner }}"
30-
REPO_NAME="${{ github.event.repository.name }}"
39+
comment_found=$(gh pr view $PR_NUMBER --json comments \
40+
--jq '.comments[].body | select(startswith("<!-- INTEGRATION_TESTS -->"))' \
41+
--repo ${{ github.repository }})
3142
32-
echo "Pull request opened by: $USER_LOGIN"
33-
34-
# Check if PR is from a fork
35-
IS_FORK=$([[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]] && echo "true" || echo "false")
36-
37-
HAS_ACCESS="false"
38-
39-
# Check user's permission level on the repository
40-
USER_PERMISSION=$(gh api repos/$REPO_OWNER/$REPO_NAME/collaborators/$USER_LOGIN/permission --jq '.permission')
41-
42-
if [[ "$USER_PERMISSION" == "admin" || "$USER_PERMISSION" == "write" ]]; then
43-
HAS_ACCESS="true"
44-
elif [[ "$USER_PERMISSION" == "read" ]]; then
45-
# For read access, we need to check if the user has been explicitly granted secret access
46-
# This information is not directly available via API, so we'll make an assumption
47-
# that read access does not imply secret access
48-
HAS_ACCESS="false"
49-
fi
50-
51-
# Check if repo owner is an organization
52-
IS_ORG=$(gh api users/$REPO_OWNER --jq '.type == "Organization"')
53-
54-
if [[ "$IS_ORG" == "true" && "$HAS_ACCESS" == "false" ]]; then
55-
# Check if user is a member of any team with write or admin access to the repo
56-
TEAMS_WITH_ACCESS=$(gh api repos/$REPO_OWNER/$REPO_NAME/teams --jq '.[] | select(.permission == "push" or .permission == "admin") | .slug')
57-
for team in $TEAMS_WITH_ACCESS; do
58-
IS_TEAM_MEMBER=$(gh api orgs/$REPO_OWNER/teams/$team/memberships/$USER_LOGIN --silent && echo "true" || echo "false")
59-
if [[ "$IS_TEAM_MEMBER" == "true" ]]; then
60-
HAS_ACCESS="true"
61-
break
62-
fi
63-
done
64-
fi
65-
66-
# If it's a fork, set HAS_ACCESS to false regardless of other checks
67-
if [[ "$IS_FORK" == "true" ]]; then
68-
HAS_ACCESS="false"
69-
fi
70-
71-
echo "has_secrets_access=$HAS_ACCESS" >> $GITHUB_OUTPUT
72-
if [[ "$HAS_ACCESS" == "true" ]]; then
73-
echo "User $USER_LOGIN likely has access to secrets"
43+
if [ -n "$comment_found" ]; then
44+
echo "has_secrets_access=true" >> $GITHUB_OUTPUT
7445
else
75-
echo "User $USER_LOGIN likely does not have access to secrets"
46+
echo "has_secrets_access=false" >> $GITHUB_OUTPUT
7647
fi
7748
78-
79-
- uses: actions/checkout@v4
80-
49+
# If not found, write a comment for manual execution
8150
- name: Delete old comments
8251
if: steps.check-secrets-access.outputs.has_secrets_access != 'true'
8352
env:
8453
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8554
run: |
8655
# Delete previous comment if it exists
8756
previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
88-
--jq '.[] | select(.body | startswith("<!-- INTEGRATION_TESTS -->")) | .id')
57+
--jq '.[] | select(.body | startswith("<!-- INTEGRATION_TESTS_MANUAL -->")) | .id')
8958
echo "Previous comment IDs: $previous_comment_ids"
9059
# Iterate over each comment ID and delete the comment
9160
if [ ! -z "$previous_comment_ids" ]; then
@@ -102,7 +71,7 @@ jobs:
10271
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
10372
run: |
10473
gh pr comment ${{ github.event.pull_request.number }} --body \
105-
"<!-- INTEGRATION_TESTS -->
74+
"<!-- INTEGRATION_TESTS_MANUAL -->
10675
Run integration tests manually:
10776
[go/deco-tests-run/sdk-java](https://go/deco-tests-run/sdk-java)
10877

.github/workflows/integration-tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ jobs:
2020
echo "GITHUB_TOKEN is empty. User has no access to tokens."
2121
echo "::set-output name=has_token::false"
2222
else
23-
echo "GITHUB_TOKEN is set. User has no access to tokens."
24-
echo "::set-output name=has_token::true"
23+
echo "GITHUB_TOKEN is set. User has access to tokens."
24+
echo "::set-output name=has_token::false"
2525
fi
2626
2727
trigger-tests:
2828
name: Trigger Tests
2929
runs-on: ubuntu-latest
3030
needs: check-token
3131
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'
3234
environment: "test-trigger-is"
3335
steps:
3436
- uses: actions/checkout@v3

0 commit comments

Comments
 (0)