-
Notifications
You must be signed in to change notification settings - Fork 1.1k
100 lines (89 loc) · 4.09 KB
/
Copy pathdispatch-pr-build.yml
File metadata and controls
100 lines (89 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Request dispatched PR Build
on:
pull_request:
types: [ opened, reopened, synchronize, edited, labeled ]
# The PR dispatch workflow runs should not cancel each other!
# When opening a PR with labels (e.g., dependabot), we receive one "opened"
# and one or more "labeled" events. If we would cancel the workflow run
# for "opened" when receiving a "labeled", the PR build in
# graylog-project-internal would not be triggered.
#concurrency:
# group: ${{ github.workflow }}-${{ github.ref }}
# cancel-in-progress: true
jobs:
dispatchedPR:
name: Dispatch wait and check
runs-on: ubuntu-slim
steps:
- name: Check if PR edit changed deps string
if: ${{ github.event.action == 'edited' }}
id: pr-string-changed
continue-on-error: true
run: |
if [ "$BASE_CHANGED" = "true" ]; then
echo "PR base branch change detected"
echo "Re-triggering PR build..."
exit 0
fi
old_pr_string=$(grep -P '^/(jenkins-pr-deps|jpd|prd)' <<< "$OLD_PR_BODY" | \
grep -ioP '(Graylog2/\S+?#|https?://github.com/Graylog2/\S+?/pull/)[0-9]+' || true)
new_pr_string=$(grep -P '^/(jenkins-pr-deps|jpd|prd)' <<< "$NEW_PR_BODY" | \
grep -ioP '(Graylog2/\S+?#|https?://github.com/Graylog2/\S+?/pull/)[0-9]+' || true)
if [ "$old_pr_string" != "$new_pr_string" ]; then
echo "PR deps string change detected: \"$old_pr_string\" -> \"$new_pr_string\""
echo "Re-triggering PR build..."
exit 0
fi
exit 1
env:
OLD_PR_BODY: "${{ github.event.changes.body.from }}"
NEW_PR_BODY: "${{ github.event.pull_request.body }}"
BASE_CHANGED: "${{ github.event.changes.base && 'true' || 'false' }}"
- name: Check e2e-tests label
id: e2e-tests
run: |
has_label="$(jq -r '.labels[].name | select(. == "e2e-tests")' <<< "$PR_EVENT")"
{
if [ -n "$has_label" ]; then
echo "run=true"
else
echo "run=false"
fi
} | tee -a "$GITHUB_OUTPUT"
env:
PR_EVENT: "${{ toJSON(github.event.pull_request) }}"
- name: Detect repository
run: |
repo="${{ github.repository }}"
repo_fork=""
# Our workflows require caller_repo to be our own repo. For forks
# github.repository is the PR author's repo.
if ! [[ "${repo,,}" =~ ^graylog2/ ]]; then
repo_fork="$repo"
repo="Graylog2/${repo#*/}"
fi
echo "repo=$repo" | tee -a "$GITHUB_ENV"
echo "repo_fork=$repo_fork" | tee -a "$GITHUB_ENV"
- name: Dispatch job to graylog-project-internal
if: ${{ (github.event.action != 'edited' && (github.event.action != 'labeled' || github.event.label.name == 'e2e-tests')) || steps.pr-string-changed.outcome == 'success' }}
run: >
gh workflow run -R Graylog2/graylog-project-internal pr-build.yml --ref master
-f caller_repo="${{ env.repo }}"
-f caller_repo_fork="${{ env.repo_fork }}"
-f caller_pr_nr=${{ github.event.number }}
-f caller_base_branch="$BASE_BRANCH"
-f caller_head_branch="$HEAD_BRANCH"
-f head_sha=${{ github.event.pull_request.head.sha }}
-f initial_actor="$ACTOR/$TRIGGERING_ACTOR"
-f e2e_tests=${{ steps.e2e-tests.outputs.run }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_GRAYLOG_PROJECT_INTERNAL_WORKFLOW_RW }}
# See: https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks
BASE_BRANCH: "${{ github.base_ref || github.ref_name }}"
HEAD_BRANCH: "${{ github.head_ref }}"
ACTOR: "${{ github.actor }}"
TRIGGERING_ACTOR: "${{ github.triggering_actor }}"
- name: Give dispatched build time to add its status
run: sleep 20
# This is mostly cosmetic. If this workflow finishes before the dispatched
# build creates the status on the PR, the build will show up green for a while.