Skip to content

Commit 5d8ebcc

Browse files
committed
feat(ci): Add pull request checks
1 parent 318e5c8 commit 5d8ebcc

File tree

8 files changed

+108
-2
lines changed

8 files changed

+108
-2
lines changed

.github/workflows/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ _Action:_ Append the new release to the Cloud Foundry repository.
2020

2121
_Recovery:_ Manually edit and push the `index.yml` file from [the cloudfoundry branch](https://github.com/DataDog/dd-trace-java/tree/cloudfoundry).
2222

23+
### check-pull-requests [🔗](check-pull-requests.yaml)
24+
25+
_Trigger:_ When creating or updating a pull request.
26+
27+
_Action:_ Check the pull request complies with [the contribution guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md).
28+
29+
_Recovery:_ Manually verify the guideline compliance.
30+
2331
### create-next-milestone [🔗](create-next-milestone.yaml)
2432

2533
_Trigger:_ When closing a milestone.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Check pull requests
2+
on:
3+
pull_request:
4+
types: [opened, reopened, edited, labeled, unlabeled]
5+
branches:
6+
- master
7+
- release/v*
8+
jobs:
9+
check_pull_requests:
10+
name: Check pull requests
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check pull requests
14+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1
15+
with:
16+
script: |
17+
// Skip draft pull requests
18+
if (context.payload.pull_request.draft) {
19+
return
20+
}
21+
// Check at least one type and (component or instrumentation) label is set
22+
const labels = context.payload.pull_request.labels.map(label => label.name)
23+
const ignoreReleaseNotes = labels.filter(label => label == 'tag: no release notes').length > 0
24+
const hasTypeLabel = labels.filter(label => label.startsWith('type:')).length > 0
25+
const hasComponentLabel = labels.filter(label => label.startsWith('comp:')).length > 0
26+
const hasInstrumentationLabel = labels.filter(label => label.startsWith('instr:')).length > 0
27+
if (!ignoreReleaseNotes && (!hasTypeLabel || (!hasComponentLabel && !hasInstrumentationLabel))) {
28+
core.setFailed('Please add at least one type, and one component or instrumentation label to the pull request.')
29+
}
30+
// Check title does not contains tag
31+
const title = context.payload.pull_request.title
32+
if (title.match(/\[.*\]/)) {
33+
core.setFailed('Please remove the tag from the pull request title.')
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"pull_request": {
3+
"draft": true,
4+
"labels": [],
5+
"title": "Adding some new features"
6+
}
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"pull_request": {
3+
"draft": false,
4+
"labels": [
5+
{
6+
"name": "tag: no release notes"
7+
}
8+
],
9+
"title": "Adding some new features"
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pull_request": {
3+
"draft": false,
4+
"labels": [
5+
{
6+
"name": "comp: api"
7+
},
8+
{
9+
"name": "type: enhancement"
10+
}
11+
],
12+
"title": "[API] Adding some new features"
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pull_request": {
3+
"draft": false,
4+
"labels": [
5+
{
6+
"name": "comp: api"
7+
},
8+
{
9+
"name": "type: enhancement"
10+
}
11+
],
12+
"title": "Adding some new features"
13+
}
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
source "$(dirname "$0")/../env.sh"
3+
testworkflow pull_request && \
4+
testworkflow pull_request draft && \
5+
testworkflow pull_request no-release-notes && \
6+
! testworkflow pull_request title-tag

.github/workflows/tests/env.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
function testworkflow() {
44
local EVENT_TYPE=$1
5+
local SCENARIO=$2
56
# Get workflow name
67
local TEST_PATH
78
TEST_PATH=$(dirname "$(readlink -f "${BASH_SOURCE[1]}")")
89
local WORKFLOW_NAME
910
WORKFLOW_NAME=$(basename "$TEST_PATH")
1011
local WORKFLOW_FILE=.github/workflows/${WORKFLOW_NAME}.yaml
11-
local PAYLOAD_FILE=${TEST_PATH}/payload-${EVENT_TYPE//_/-}.json
12+
local PAYLOAD_FILE
13+
PAYLOAD_FILE=${TEST_PATH}/payload-${EVENT_TYPE//_/-}
14+
if [ "$SCENARIO" != "" ]; then
15+
PAYLOAD_FILE=${PAYLOAD_FILE}-${SCENARIO}
16+
fi
17+
PAYLOAD_FILE=${PAYLOAD_FILE}.json
1218
# Move to project root directory
1319
local FILE_PATH
1420
FILE_PATH=$(dirname "$0")
15-
cd "$FILE_PATH/../../../../" || exit 1
21+
pushd "$FILE_PATH/../../../../" || exit 1
1622
# Check if workflow file and payload file exist
1723
if [ ! -f "$WORKFLOW_FILE" ]; then
1824
echo "Workflow file not found: $WORKFLOW_FILE"
@@ -29,4 +35,10 @@ function testworkflow() {
2935
--container-architecture linux/amd64 \
3036
--secret GITHUB_TOKEN="$(gh auth token)" \
3137
--verbose
38+
# Capture the exit code
39+
local EXIT_CODE=$?
40+
# Move back to initial directory
41+
popd || exit 1
42+
# Return the test exit code
43+
return $EXIT_CODE
3244
}

0 commit comments

Comments
 (0)