Skip to content

Commit 070c0a2

Browse files
authored
Merge pull request #1 from netodevel/feat/create-ga
feat: #0000 - Adds initial commit
2 parents 89d0ed5 + 88ec07d commit 070c0a2

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Commit Lint"
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
- development
7+
- staging
8+
types:
9+
- opened
10+
- reopened
11+
- labeled
12+
- unlabeled
13+
- edited
14+
- synchronize
15+
jobs:
16+
custom_test:
17+
runs-on: ubuntu-latest
18+
name: We test it locally with act
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
token: ${{ secrets.PAT }}
23+
fetch-depth: 0
24+
- name: Conventional Commits Checker
25+
uses: ./ # Uses an action in the root directory
26+
id: commits-check
27+
with:
28+
target-branch: ${{ github.event.pull_request.base.ref }}
29+
current-branch: ${{ github.event.pull_request.head.ref }}
30+
- name: Get the Result
31+
run: echo "${{ steps.commits-check.outputs.commit-checker }}"

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Base image
2+
FROM alpine:latest
3+
4+
RUN apk add --no-cache \
5+
bash \
6+
ca-certificates \
7+
curl \
8+
git
9+
10+
COPY entrypoint.sh /entrypoint.sh
11+
12+
RUN chmod +x /entrypoint.sh
13+
14+
ENTRYPOINT ["/entrypoint.sh"]

action.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# action.yaml
2+
name: 'Conventional Commits Checker'
3+
description: 'Check that all pull request commits are following conventional commits'
4+
inputs:
5+
target-branch:
6+
description: 'target branch'
7+
required: true
8+
default: 'main'
9+
current-branch:
10+
description: 'current-branch'
11+
required: true
12+
default: 'main'
13+
outputs:
14+
commit-checker:
15+
description: 'true or false'
16+
runs:
17+
using: docker
18+
image: Dockerfile
19+
args:
20+
- ${{ inputs.target-branch }}
21+
- ${{ inputs.current-branch }}

entrypoint.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -e
3+
4+
git config --global --add safe.directory /github/workspace
5+
6+
# Define the branch names
7+
main_branch=main=$1
8+
9+
echo $1
10+
echo $2
11+
12+
# Get all commit messages from the feature branch that are not in the main branch
13+
commits=($(git log --pretty="%s EON" origin/$2 ^origin/$1))
14+
15+
pattern="(feat|fix|ci|chore|docs|test|style|refactor): +#([0-9]+) -.{1,}$"
16+
17+
# Loop through the array and create other structure data
18+
commits_struct=()
19+
for commit in "${commits[@]}"; do
20+
if [ $commit != "EON" ]; then
21+
commit_msg+=" $commit"
22+
fi
23+
if [ $commit == "EON" ]; then
24+
commits_struct+=("${commit_msg}")
25+
commit_msg=""
26+
fi
27+
done
28+
29+
all_commits_ok="true"
30+
echo "| commit | status"
31+
for msg in "${commits_struct[@]}"; do
32+
if [[ $msg =~ $pattern ]]; then
33+
echo "$msg | ok"
34+
else
35+
echo "$msg | invalid"
36+
all_commits_ok="false"
37+
fi
38+
echo "--"
39+
done
40+
41+
if [ $all_commits_ok == "true" ]; then
42+
echo "commit-checker=true" >>$GITHUB_OUTPUT
43+
exit 0
44+
else
45+
echo "commit-checker=false" >>$GITHUB_OUTPUT
46+
exit 1
47+
fi

0 commit comments

Comments
 (0)