Skip to content

Commit 6af6fb1

Browse files
committed
fix(workflow): dynamically set environment
Updated the GitHub Actions workflow to dynamically set the environment based on the event type and user permissions. Added a step to check if the user is an admin using the GitHub API and set the environment accordingly. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 7fd3e22 commit 6af6fb1

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

.github/workflows/kind-e2e-tests.yaml

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
name: E2E Tests on Kind
22

33
on:
4-
schedule:
5-
- cron: "0 5 * * *"
6-
workflow_dispatch:
7-
inputs:
8-
debug_enabled:
9-
type: boolean
10-
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
11-
required: false
12-
default: false
134
pull_request:
145
types: [opened, synchronize, reopened]
156
paths:
@@ -22,6 +13,9 @@ jobs:
2213
cancel-in-progress: true
2314
name: e2e tests
2415
runs-on: ubuntu-latest
16+
if: >
17+
(github.event_name == 'pull_request_target' || github.event_name == 'pull_request_target') &&
18+
contains(fromJson('["chmouel", "zakisk"]'), github.event.pull_request.user.login)
2519
strategy:
2620
matrix:
2721
provider: [providers, gitea_others]
@@ -57,6 +51,31 @@ jobs:
5751
with:
5852
ref: ${{ github.event.pull_request.head.sha }}
5953

54+
- name: Check if user is an admin
55+
id: check-permissions
56+
run: |
57+
set -x
58+
USER_LOGIN="${{ github.event.pull_request.user.login }}"
59+
REPO_FULL_NAME="${{ github.repository }}"
60+
echo "Checking permissions for user: $USER_LOGIN in repo: $REPO_FULL_NAME"
61+
62+
# Fetch user permissions using GitHub API
63+
PERMISSIONS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
64+
"https://api.github.com/repos/$REPO_FULL_NAME/collaborators/$USER_LOGIN/permission")
65+
66+
# Extract the permission level
67+
PERMISSION_LEVEL=$(echo "$PERMISSIONS" | jq -r '.permission')
68+
69+
# Set output variable to indicate if the user is an admin
70+
if [[ "$PERMISSION_LEVEL" == "admin" ]]; then
71+
echo "User is an admin."
72+
echo "is-admin=true" >> $GITHUB_OUTPUT
73+
else
74+
echo "User is not an admin."
75+
echo "is-admin=false" >> $GITHUB_OUTPUT
76+
fi
77+
shell: bash
78+
6079
- uses: actions/setup-go@v5
6180
with:
6281
go-version-file: "go.mod"
@@ -102,26 +121,7 @@ jobs:
102121
./hack/gh-workflow-ci.sh create_second_github_app_controller_on_ghe
103122
104123
- name: Run E2E Tests on pull_request
105-
if: ${{ github.event_name != 'schedule' }}
106-
env:
107-
TEST_PROVIDER: ${{ matrix.provider }}
108-
TEST_BITBUCKET_CLOUD_TOKEN: ${{ secrets.BITBUCKET_CLOUD_TOKEN }}
109-
TEST_EL_WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
110-
TEST_GITEA_SMEEURL: ${{ secrets.TEST_GITEA_SMEEURL }}
111-
TEST_GITHUB_REPO_INSTALLATION_ID: ${{ secrets.INSTALLATION_ID }}
112-
TEST_GITHUB_TOKEN: ${{ secrets.GH_APPS_TOKEN }}
113-
TEST_GITHUB_SECOND_TOKEN: ${{ secrets.TEST_GITHUB_SECOND_TOKEN }}
114-
TEST_GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
115-
TEST_BITBUCKET_SERVER_TOKEN: ${{ secrets.BITBUCKET_SERVER_TOKEN }}
116-
TEST_BITBUCKET_SERVER_API_URL: ${{ secrets.BITBUCKET_SERVER_API_URL }}
117-
TEST_BITBUCKET_SERVER_WEBHOOK_SECRET: ${{ secrets.BITBUCKET_SERVER_WEBHOOK_SECRET }}
118-
run: |
119-
./hack/gh-workflow-ci.sh run_e2e_tests
120-
121-
- name: Run E2E Tests on nightly
122-
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
123124
env:
124-
NIGHTLY_E2E_TEST: "true"
125125
TEST_PROVIDER: ${{ matrix.provider }}
126126
TEST_BITBUCKET_CLOUD_TOKEN: ${{ secrets.BITBUCKET_CLOUD_TOKEN }}
127127
TEST_EL_WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
@@ -150,12 +150,3 @@ jobs:
150150
with:
151151
name: logs-e2e-tests-${{ matrix.provider }}
152152
path: /tmp/logs
153-
154-
- name: Report Status
155-
if: ${{ always() && github.ref_name == 'main' && github.event_name == 'schedule' }}
156-
uses: ravsamhq/notify-slack-action@v2
157-
with:
158-
status: ${{ job.status }}
159-
notify_when: "failure"
160-
env:
161-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

0 commit comments

Comments
 (0)