Skip to content

Commit c3d15b3

Browse files
Warashit-kikuc
andauthored
Add check target to the makefile for convenience (#5846)
* Add check and lint targets to Makefile Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Add GitHub Actions workflow for first-time contributors Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Update ensure-check.sh to clarify PR comment instructions Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Add DCO check to Makefile and implement ensure-dco script Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Enhance ensure-dco script to provide guidance for missing Signed-off-by lines Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Use check workflow for non-maintainers not only the first time contributors Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Refactor to move type check to on.pull_request_target Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Improve the tempdir usage Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Enhance the comment to include the mention of the author Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Update .github/workflows/non_maintainer_check.yaml Co-authored-by: Tetsuya KIKUCHI <[email protected]> Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Add mention to the pr author Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> --------- Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> Co-authored-by: Tetsuya KIKUCHI <[email protected]>
1 parent 750e0ce commit c3d15b3

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: check for non-maintainers
2+
3+
on:
4+
pull_request_target:
5+
branches: [ master ]
6+
types: [ opened ]
7+
issue_comment:
8+
types: [ created ]
9+
10+
jobs:
11+
greeting:
12+
runs-on: ubuntu-24.04
13+
permissions:
14+
pull-requests: write
15+
if: >-
16+
(github.event_name == 'pull_request_target') &&
17+
(github.event.pull_request.author_association != 'COLLABORATOR') &&
18+
(github.event.pull_request.author_association != 'MANNEQUIN') &&
19+
(github.event.pull_request.author_association != 'MEMBER') &&
20+
(github.event.pull_request.author_association != 'OWNER')
21+
steps:
22+
- name: Greeting
23+
env:
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
AUTHOR: ${{ github.event.pull_request.user.login }}
26+
PR_NUMBER: ${{ github.event.pull_request.number }}
27+
TEMP_DIR: ${{ runner.temp }}
28+
run: |
29+
cat <<EOF > "${TEMP_DIR}/greeting.md"
30+
@${AUTHOR}
31+
Thank you for your contribution! We look forward to seeing more from you.
32+
Please run the `make check` command to ensure your changes will pass the CI.
33+
After successfully running the command on your local machine, the instructions will be printed out.
34+
Please follow them to commit your changes.
35+
If the check has not passed, please fix the issues and push the changes to your branch.
36+
Then, please run the `make check` command again to ensure the issues are fixed.
37+
EOF
38+
39+
gh pr comment "${PR_NUMBER}" --body-file "${TEMP_DIR}/greeting.md"
40+
41+
check:
42+
if: github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/check-commit')
43+
runs-on: ubuntu-24.04
44+
permissions:
45+
pull-requests: write
46+
steps:
47+
- name: Check if the hash is valid
48+
env:
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
COMMENT_BODY: ${{ github.event.comment.body }}
51+
REPO_NAME: ${{ github.event.repository.full_name }}
52+
PR_NUMBER: ${{ github.event.issue.number }}
53+
TEMP_DIR: ${{ runner.temp }}
54+
run: |
55+
COMMENT_HASH=$(echo "${COMMENT_BODY}" | cut -d' ' -f2)
56+
if [ -z "${COMMENT_HASH}" ]; then
57+
echo "No hash provided"
58+
exit 1
59+
fi
60+
61+
PR="$(gh api "/repos/${REPO_NAME}/pulls/${PR_NUMBER}")"
62+
AUTHOR="$(echo "$PR" | jq -r '.user.login')"
63+
HEAD_SHA="$(echo "$PR" | jq -r '.head.sha')"
64+
HEAD_REF="$(echo "$PR" | jq -r '.head.ref')"
65+
66+
EXPECTED_HASH="$(echo "$HEAD_REF/$HEAD_SHA" | sha256sum | cut -d' ' -f1)"
67+
68+
if [ "${COMMENT_HASH}" != "${EXPECTED_HASH}" ]; then
69+
echo "Invalid hash"
70+
exit 1
71+
fi
72+
73+
echo "Valid hash"
74+
75+
cat <<EOF > "${TEMP_DIR}/comment.md"
76+
@${AUTHOR}
77+
The check has passed.
78+
Thank you for your contribution!
79+
EOF
80+
81+
gh pr comment "${PR_NUMBER}" --body-file "${TEMP_DIR}/comment.md"

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
####################
22
# All make commands are following the format as "make action/target"
33
# "action" can be either:
4+
# check: run checks which should be passed before committing
45
# build: build artifacts such as binary, container image, chart
56
# test: execute test
67
# run: run a module locally
@@ -172,6 +173,9 @@ run/site:
172173

173174
# Lint commands
174175

176+
.PHONY: lint
177+
lint: lint/go lint/web lint/helm
178+
175179
.PHONY: lint/go
176180
lint/go: FIX ?= false
177181
lint/go: VERSION ?= sha256:c2f5e6aaa7f89e7ab49f6bd45d8ce4ee5a030b132a5fbcac68b7959914a5a890 # golangci/golangci-lint:v1.64.7
@@ -267,3 +271,17 @@ kind-down:
267271
.PHONY: setup-envtest
268272
setup-envtest: ## Download setup-envtest locally if necessary.
269273
test -s $(GOBIN)/setup-envtest || go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
274+
275+
# Check commands
276+
.PHONY: check
277+
check: build lint test check/gen/code check/dco
278+
./hack/ensure-check.sh
279+
280+
.PHONY: check/gen/code
281+
check/gen: gen/code
282+
git add -N .
283+
git diff --exit-code --quiet HEAD
284+
285+
.PHONY: check/dco
286+
check/dco:
287+
./hack/ensure-dco.sh

hack/ensure-check.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The PipeCD Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
HEAD=$(git rev-parse HEAD)
22+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
23+
24+
CHECK="$(echo "$BRANCH/$HEAD" | sha256sum | cut -d ' ' -f 1)"
25+
26+
echo "Please paste the following to the PR comment and send it to ensure the check is passed:"
27+
echo "/check-commit $CHECK"

hack/ensure-dco.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The PipeCD Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
MERGE_BASE=$(git merge-base HEAD origin/master)
22+
COMMIT_HASHES=$(git log --reverse --format=format:"%H" "$MERGE_BASE..HEAD")
23+
24+
# check if the commit message contains the DCO sign-off
25+
for commit_hash in $COMMIT_HASHES; do
26+
sign_off=$(git log -1 --format="%(trailers:key=Signed-off-by,valueonly)%-C()" "$commit_hash")
27+
if [ -z "$sign_off" ]; then
28+
echo "Error: Commit $commit_hash is missing Signed-off-by line"
29+
echo "Please run 'git rebase --signoff ${commit_hash}~1' to fix it"
30+
exit 1
31+
fi
32+
done
33+
34+
echo "All commits have the DCO sign-off"

0 commit comments

Comments
 (0)