Skip to content

Commit

Permalink
Merge pull request #1 from netodevel/feat/create-ga
Browse files Browse the repository at this point in the history
feat: #0000 - Adds initial commit
  • Loading branch information
netodevel authored Feb 3, 2023
2 parents 89d0ed5 + 88ec07d commit 070c0a2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/conventional-commits-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Commit Lint"
on:
pull_request:
branches:
- main
- development
- staging
types:
- opened
- reopened
- labeled
- unlabeled
- edited
- synchronize
jobs:
custom_test:
runs-on: ubuntu-latest
name: We test it locally with act
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- name: Conventional Commits Checker
uses: ./ # Uses an action in the root directory
id: commits-check
with:
target-branch: ${{ github.event.pull_request.base.ref }}
current-branch: ${{ github.event.pull_request.head.ref }}
- name: Get the Result
run: echo "${{ steps.commits-check.outputs.commit-checker }}"
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Base image
FROM alpine:latest

RUN apk add --no-cache \
bash \
ca-certificates \
curl \
git

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# action.yaml
name: 'Conventional Commits Checker'
description: 'Check that all pull request commits are following conventional commits'
inputs:
target-branch:
description: 'target branch'
required: true
default: 'main'
current-branch:
description: 'current-branch'
required: true
default: 'main'
outputs:
commit-checker:
description: 'true or false'
runs:
using: docker
image: Dockerfile
args:
- ${{ inputs.target-branch }}
- ${{ inputs.current-branch }}
47 changes: 47 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e

git config --global --add safe.directory /github/workspace

# Define the branch names
main_branch=main=$1

echo $1
echo $2

# Get all commit messages from the feature branch that are not in the main branch
commits=($(git log --pretty="%s EON" origin/$2 ^origin/$1))

pattern="(feat|fix|ci|chore|docs|test|style|refactor): +#([0-9]+) -.{1,}$"

# Loop through the array and create other structure data
commits_struct=()
for commit in "${commits[@]}"; do
if [ $commit != "EON" ]; then
commit_msg+=" $commit"
fi
if [ $commit == "EON" ]; then
commits_struct+=("${commit_msg}")
commit_msg=""
fi
done

all_commits_ok="true"
echo "| commit | status"
for msg in "${commits_struct[@]}"; do
if [[ $msg =~ $pattern ]]; then
echo "$msg | ok"
else
echo "$msg | invalid"
all_commits_ok="false"
fi
echo "--"
done

if [ $all_commits_ok == "true" ]; then
echo "commit-checker=true" >>$GITHUB_OUTPUT
exit 0
else
echo "commit-checker=false" >>$GITHUB_OUTPUT
exit 1
fi

0 comments on commit 070c0a2

Please sign in to comment.