diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml new file mode 100644 index 00000000000..7ba08da00cd --- /dev/null +++ b/.github/workflows/conventional-commits.yml @@ -0,0 +1,73 @@ +name: Conventional Commits + +on: + pull_request: + # Just some events that could involve commit messages + types: [opened, synchronize, reopened] + +permissions: + # Only need read access to repository contents + contents: read + +jobs: + validate-commit-names: + name: Check Commit Names + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout repository + uses: actions/checkout@v5 + with: + # Limit of validation to skip fetching all existing commits + fetch-depth: 100 + + # Validate commit messages + - name: Validate all commit messages + run: | + echo "Validating all commit names in PR #${{ github.event.pull_request.number }}" + + # Get the base branch and the PR branch + BASE_BRANCH="${{ github.event.pull_request.base.ref }}" + + # Fetch the base branch with no verbosity + git fetch --quiet origin "$BASE_BRANCH" + + # Get all commits in the PR (not the base branch ones) + # --pretty=format:"%s" gets only the commit message + mapfile -t commits_array < <(git log origin/$BASE_BRANCH..HEAD --pretty=format:'%s') + + # Regex pattern for valid Conventional Commit + regex='^(docs|fix|feat|chore|refactor|test|style|build|ci): [a-z].{9,}$' + + # Variable to count errors + fail=0 + + echo "Commit list and validation:" + + # Print and validate + for commitmsg in "${commits_array[@]}"; do + echo "$commitmsg" + + # Skip merge and [tx] commits + if [[ "$commitmsg" =~ ^Merge ]] || [[ "$commitmsg" =~ ^\[tx\] ]]; then + echo " 🚫 Ignored commit" + continue + fi + + # Validate Conventional Commit + if ! [[ "$commitmsg" =~ $regex ]]; then + echo " ❌ Invalid commit" + fail=$((fail+1)) + else + echo " ✅ Valid commit" + fi + done + + # Fail the job if there are any invalid commits + if [[ $fail -gt 0 ]]; then + echo "❌ $fail commit(s) do(es) not follow the Conventional Commits convention" + exit 1 + else + echo "✅ All commits follow the Conventional Commits convention" + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index c926a8d96b1..5663b54d8a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ ownCloud admins and users. * Enhancement - Show members of a space: [#4612](https://github.com/owncloud/android/issues/4612) * Enhancement - Set emoji as space image: [#4707](https://github.com/owncloud/android/issues/4707) * Enhancement - Workflow to build APK: [#4751](https://github.com/owncloud/android/pull/4751) +* Enhancement - Workflow to check Conventional Commits: [#4759](https://github.com/owncloud/android/pull/4759) ## Details @@ -98,6 +99,13 @@ ownCloud admins and users. https://github.com/owncloud/android/pull/4751 +* Enhancement - Workflow to check Conventional Commits: [#4759](https://github.com/owncloud/android/pull/4759) + + A new workflow has been added to check that commit names in a PR fits the + Conventional Commits convention. + + https://github.com/owncloud/android/pull/4759 + # Changelog for ownCloud Android Client [4.7.0] (2025-11-17) The following sections list the changes in ownCloud Android Client 4.7.0 relevant to diff --git a/changelog/unreleased/4759 b/changelog/unreleased/4759 new file mode 100644 index 00000000000..e6880b66c78 --- /dev/null +++ b/changelog/unreleased/4759 @@ -0,0 +1,5 @@ +Enhancement: Workflow to check Conventional Commits + +A new workflow has been added to check that commit names in a PR fits the Conventional Commits convention. + +https://github.com/owncloud/android/pull/4759