From 7ebe0f8626ecb2f0da023b903b82f7332d8afaf6 Mon Sep 17 00:00:00 2001 From: James Couball Date: Wed, 14 May 2025 17:46:38 -0700 Subject: [PATCH 1/5] chore: enforce conventional commit messages with husky and commitlint - Add steps to bin/setup to install husky and the commitlint npm packages - Configure husky to run commitlint via the commit-msg hook - Add commitlint configuration based on my specific preferences - Add npm specific files (node_modules/, package-lock.json) to .gitignore --- .commitlintrc.yml | 38 +++++++++++++++++++++++++ .gitignore | 2 ++ .husky/commit-msg | 1 + CONTRIBUTING.md | 72 +++++++++++++++++++++++++++-------------------- bin/setup | 7 ++++- package.json | 10 +++++++ 6 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 .commitlintrc.yml create mode 100644 .husky/commit-msg create mode 100644 package.json diff --git a/.commitlintrc.yml b/.commitlintrc.yml new file mode 100644 index 00000000..3e08fa81 --- /dev/null +++ b/.commitlintrc.yml @@ -0,0 +1,38 @@ +--- +extends: '@commitlint/config-conventional' + +rules: + # See: https://commitlint.js.org/reference/rules.html + # + # Rules are made up by a name and a configuration array. The configuration + # array contains: + # + # * Severity [0..2]: 0 disable rule, 1 warning if violated, or 2 error if + # violated + # * Applicability [always|never]: never inverts the rule + # * Value: value to use for this rule (if applicable) + # + # Run `npx commitlint --print-config` to see the current setting for all + # rules. + # + header-max-length: [2, always, 100] # Header can not exceed 100 chars + + type-case: [2, always, lower-case] # Type must be lower case + type-empty: [2, never] # Type must not be empty + + # Supported conventional commit types + type-enum: [2, always, [build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test]] + + scope-case: [2, always, lower-case] # Scope must be lower case + + # Error if subject is one of these cases (encourages lower-case) + subject-case: [2, never, [sentence-case, start-case, pascal-case, upper-case]] + subject-empty: [2, never] # Subject must not be empty + subject-full-stop: [2, never, "."] # Subject must not end with a period + + body-leading-blank: [2, always] # Body must have a blank line before it + body-max-line-length: [2, always, 100] # Body lines can not exceed 100 chars + + footer-leading-blank: [2, always] # Footer must have a blank line before it + footer-max-line-length: [2, always, 100] # Footer lines can not exceed 100 chars + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 611ed70c..13dcea11 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ doc pkg rdoc Gemfile.lock +node_modules +package-lock.json \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 00000000..70bd3dd2 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no-install commitlint --edit "$1" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 10793a4a..9a7a4e35 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,28 +5,28 @@ # Contributing to the git gem -* [Summary](#summary) -* [How to contribute](#how-to-contribute) -* [How to report an issue or request a feature](#how-to-report-an-issue-or-request-a-feature) -* [How to submit a code or documentation change](#how-to-submit-a-code-or-documentation-change) - * [Commit your changes to a fork of `ruby-git`](#commit-your-changes-to-a-fork-of-ruby-git) - * [Create a pull request](#create-a-pull-request) - * [Get your pull request reviewed](#get-your-pull-request-reviewed) -* [Design philosophy](#design-philosophy) - * [Direct mapping to git commands](#direct-mapping-to-git-commands) - * [Parameter naming](#parameter-naming) - * [Output processing](#output-processing) -* [Coding standards](#coding-standards) - * [1 PR = 1 Commit](#1-pr--1-commit) - * [Unit tests](#unit-tests) - * [Continuous integration](#continuous-integration) - * [Documentation](#documentation) -* [Building a specific version of the Git command-line](#building-a-specific-version-of-the-git-command-line) - * [Install pre-requisites](#install-pre-requisites) - * [Obtain Git source code](#obtain-git-source-code) - * [Build git](#build-git) - * [Use the new Git version](#use-the-new-git-version) -* [Licensing](#licensing) +- [Summary](#summary) +- [How to contribute](#how-to-contribute) +- [How to report an issue or request a feature](#how-to-report-an-issue-or-request-a-feature) +- [How to submit a code or documentation change](#how-to-submit-a-code-or-documentation-change) + - [Commit your changes to a fork of `ruby-git`](#commit-your-changes-to-a-fork-of-ruby-git) + - [Create a pull request](#create-a-pull-request) + - [Get your pull request reviewed](#get-your-pull-request-reviewed) +- [Design philosophy](#design-philosophy) + - [Direct mapping to git commands](#direct-mapping-to-git-commands) + - [Parameter naming](#parameter-naming) + - [Output processing](#output-processing) +- [Coding standards](#coding-standards) + - [Commit message guidelines](#commit-message-guidelines) + - [Unit tests](#unit-tests) + - [Continuous integration](#continuous-integration) + - [Documentation](#documentation) +- [Building a specific version of the Git command-line](#building-a-specific-version-of-the-git-command-line) + - [Install pre-requisites](#install-pre-requisites) + - [Obtain Git source code](#obtain-git-source-code) + - [Build git](#build-git) + - [Use the new Git version](#use-the-new-git-version) +- [Licensing](#licensing) ## Summary @@ -153,18 +153,30 @@ behavior. To ensure high-quality contributions, all pull requests must meet the following requirements: -### 1 PR = 1 Commit +### Commit message guidelines -* All commits for a PR must be squashed into a single commit. -* To avoid an extra merge commit, the PR must be able to be merged as [a fast-forward - merge](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging). -* The easiest way to ensure a fast-forward merge is to rebase your local branch to - the `ruby-git` master branch. +All commit messages must follow the [Conventional Commits +standard](https://www.conventionalcommits.org/en/v1.0.0/). This helps us maintain a +clear and structured commit history, automate versioning, and generate changelogs +effectively. + +To ensure compliance, this project includes: + +- A git commit-msg hook that validates your commit messages before they are accepted. + + To activate the hook, you must have node installed and run `bin/setup` or + `npm install`. + +- A GitHub Actions workflow that will enforce the Conventional Commit standard as + part of the continuous integration pipeline. + + Any commit message that does not conform to the Conventional Commits standard will + cause the workflow to fail and not allow the PR to be merged. ### Unit tests -* All changes must be accompanied by new or modified unit tests. -* The entire test suite must pass when `bundle exec rake default` is run from the +- All changes must be accompanied by new or modified unit tests. +- The entire test suite must pass when `bundle exec rake default` is run from the project's local working copy. While working on specific features, you can run individual test files or a group of diff --git a/bin/setup b/bin/setup index dce67d86..f16ff654 100755 --- a/bin/setup +++ b/bin/setup @@ -5,4 +5,9 @@ set -vx bundle install -# Do any other automated setup that you need to do here +if [ -x "$(command -v npm)" ]; then + npm install +else + echo "npm is not installed" + echo "Install npm then re-run this script to enable the conventional commit git hook." +fi diff --git a/package.json b/package.json new file mode 100644 index 00000000..2924004f --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "devDependencies": { + "@commitlint/cli": "^19.8.0", + "@commitlint/config-conventional": "^19.8.0", + "husky": "^9.1.7" + }, + "scripts": { + "prepare": "husky" + } +} From 1da4c44620a3264d4e837befd3f40416c5d8f1d8 Mon Sep 17 00:00:00 2001 From: James Couball Date: Wed, 14 May 2025 18:01:49 -0700 Subject: [PATCH 2/5] chore: enforce conventional commit messages with a GitHub action - Add a GitHub Actions workflow to enforce conventional commits - Add commitlint configuration based on my specific preferences --- .../enforce_conventional_commits.yml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/enforce_conventional_commits.yml diff --git a/.github/workflows/enforce_conventional_commits.yml b/.github/workflows/enforce_conventional_commits.yml new file mode 100644 index 00000000..8aaa93f8 --- /dev/null +++ b/.github/workflows/enforce_conventional_commits.yml @@ -0,0 +1,28 @@ +--- +name: Conventional Commits + +permissions: + contents: read + +on: + pull_request: + branches: + - master + +jobs: + commit-lint: + name: Verify Conventional Commits + + # Skip this job if this is a release PR + if: (github.event_name == 'pull_request' && !startsWith(github.event.pull_request.head.ref, 'release-please--')) + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: { fetch-depth: 0 } + + - name: Check Commit Messages + uses: wagoid/commitlint-github-action@v6 + with: { configFile: .commitlintrc.yml } From 06480e65e2441348230ef10e05cc1c563d0e7ea8 Mon Sep 17 00:00:00 2001 From: James Couball Date: Wed, 14 May 2025 20:59:31 -0700 Subject: [PATCH 3/5] build: automate continuous delivery workflow Use googleapis/release-please-action and rubygems/release-gem actions to automate releasing and publishing new gem versions to rubygems. --- .github/workflows/release.yml | 52 +++++++++++++++++++++ .release-please-manifest.json | 3 ++ .yardopts | 1 - RELEASING.md | 85 ----------------------------------- Rakefile | 7 +++ release-please-config.json | 36 +++++++++++++++ 6 files changed, 98 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .release-please-manifest.json delete mode 100644 RELEASING.md create mode 100644 release-please-config.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..607f16ce --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,52 @@ +--- +name: Release Gem + +description: | + This workflow creates a new release on GitHub and publishes the gem to + RubyGems.org. + + The workflow uses the `googleapis/release-please-action` to handle the + release creation process and the `rubygems/release-gem` action to publish + the gem to rubygems.org + +on: + push: + branches: ["main"] + + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + + environment: + name: RubyGems + url: https://rubygems.org/gems/git + + permissions: + contents: write + pull-requests: write + id-token: write + + steps: + - name: Checkout project + uses: actions/checkout@v4 + + - name: Create release + uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{ secrets.AUTO_RELEASE_TOKEN }} + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + + - name: Setup ruby + uses: ruby/setup-ruby@v1 + if: ${{ steps.release.outputs.release_created }} + with: + bundler-cache: true + ruby-version: ruby + + - name: Push to RubyGems.org + uses: rubygems/release-gem@v1 + if: ${{ steps.release.outputs.release_created }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 00000000..d6f54056 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "3.0.1" +} diff --git a/.yardopts b/.yardopts index ce1aff3c..105b79a9 100644 --- a/.yardopts +++ b/.yardopts @@ -7,5 +7,4 @@ README.md CHANGELOG.md CONTRIBUTING.md -RELEASING.md MAINTAINERS.md diff --git a/RELEASING.md b/RELEASING.md deleted file mode 100644 index ead6293a..00000000 --- a/RELEASING.md +++ /dev/null @@ -1,85 +0,0 @@ - - -# How to release a new git.gem - -Releasing a new version of the `git` gem requires these steps: - -* [Install Prerequisites](#install-prerequisites) -* [Determine the SemVer release type](#determine-the-semver-release-type) -* [Create the release](#create-the-release) -* [Review the CHANGELOG and release PR](#review-the-changelog-and-release-pr) -* [Manually merge the release PR](#manually-merge-the-release-pr) -* [Publish the git gem to RubyGems.org](#publish-the-git-gem-to-rubygemsorg) - -## Install Prerequisites - -The following tools need to be installed in order to create the release: - -* [create_githhub_release](https://github.com/main-branch/create_github_release) is used to create the release -* [git](https://git-scm.com) is used by `create-github-release` to interact with the local and remote repositories -* [gh](https://cli.github.com) is used by `create-github-release` to create the release and PR in GitHub - -On a Mac, these tools can be installed using [gem](https://guides.rubygems.org/rubygems-basics/) and [brew](https://brew.sh): - -```shell -$ gem install create_github_release -... -$ brew install git -... -$ brew install gh -... -$ -``` - -## Determine the SemVer release type - -Determine the SemVer version increment that should be applied for the new release: - -* `major`: when the release includes incompatible API or functional changes. -* `minor`: when the release adds functionality in a backward-compatible manner -* `patch`: when the release includes small user-facing changes that are - backward-compatible and do not introduce new functionality. - -## Create the release - -Create the release using the `create-github-release` command. If the release type -is `major`, the command is: - -```shell -create-github-release major -``` - -Follow the directions given by the `create-github-release` command to finish the -release. Where the instructions given by the command differ than the instructions -below, follow the instructions given by the command. - -## Review the CHANGELOG and release PR - -The `create-github-release` command will output a link to the CHANGELOG and the PR -it created for the release. Review the CHANGELOG and have someone review and approve -the release PR. - -## Manually merge the release PR - -It is important to manually merge the PR so a separate merge commit can be avoided. -Use the commands output by the `create-github-release` which will looks like this -if you are creating a 2.0.0 release: - -```shell -git checkout master -git merge --ff-only release-v2.0.0 -git push -``` - -This will automatically close the release PR. - -## Publish the git gem to RubyGems.org - -Finally, publish the git gem to RubyGems.org using the following command: - -```shell -rake release:rubygem_push -``` diff --git a/Rakefile b/Rakefile index e2d8ef2a..72b93352 100644 --- a/Rakefile +++ b/Rakefile @@ -58,3 +58,10 @@ task :'test:gem' => :install do puts 'Gem Test Succeeded' end + +# Make it so that calling `rake release` just calls `rake release:rubygem_push` to +# avoid creating and pushing a new tag. + +Rake::Task['release'].clear +desc 'Customized release task to avoid creating a new tag' +task release: 'release:rubygem_push' diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 00000000..b0c93860 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,36 @@ +{ + "bootstrap-sha": "31374263eafea4e23352494ef4f6bea3ce62c1b5", + "packages": { + ".": { + "release-type": "ruby", + "package-name": "git", + "changelog-path": "CHANGELOG.md", + "version-file": "lib/git/version.rb", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "draft": false, + "prerelease": false, + "include-component-in-tag": false, + "pull-request-title-pattern": "chore: release v${version}", + "changelog-sections": [ + { "type": "feat", "section": "Features", "hidden": false }, + { "type": "fix", "section": "Bug Fixes", "hidden": false }, + { "type": "build", "section": "Other Changes", "hidden": false }, + { "type": "chore", "section": "Other Changes", "hidden": false }, + { "type": "ci", "section": "Other Changes", "hidden": false }, + { "type": "docs", "section": "Other Changes", "hidden": false }, + { "type": "perf", "section": "Other Changes", "hidden": false }, + { "type": "refactor", "section": "Other Changes", "hidden": false }, + { "type": "revert", "section": "Other Changes", "hidden": false }, + { "type": "style", "section": "Other Changes", "hidden": false }, + { "type": "test", "section": "Other Changes", "hidden": false } + ] + } + }, + "plugins": [ + { + "type": "sentence-case" + } + ], + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} From c8611f1e68e73825fd16bd475752a40b0088d4ae Mon Sep 17 00:00:00 2001 From: James Couball Date: Wed, 14 May 2025 21:09:07 -0700 Subject: [PATCH 4/5] fix: trigger the release workflow on a change to 'master' insetad of 'main' --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 607f16ce..eaea43f1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ description: | on: push: - branches: ["main"] + branches: ["master"] workflow_dispatch: From 880d38e4d36e598b47c7d487d49b56c6541ebf66 Mon Sep 17 00:00:00 2001 From: James Couball Date: Wed, 14 May 2025 21:31:07 -0700 Subject: [PATCH 5/5] chore: release v3.0.2 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 14 ++++++++++++++ lib/git/version.rb | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index d6f54056..e28eff59 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "3.0.1" + ".": "3.0.2" } diff --git a/CHANGELOG.md b/CHANGELOG.md index b31fed33..0fec2948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ # Change Log +## [3.0.2](https://github.com/ruby-git/ruby-git/compare/v3.0.1...v3.0.2) (2025-05-15) + + +### Bug Fixes + +* Trigger the release workflow on a change to 'master' insetad of 'main' ([c8611f1](https://github.com/ruby-git/ruby-git/commit/c8611f1e68e73825fd16bd475752a40b0088d4ae)) + + +### Other Changes + +* Automate continuous delivery workflow ([06480e6](https://github.com/ruby-git/ruby-git/commit/06480e65e2441348230ef10e05cc1c563d0e7ea8)) +* Enforce conventional commit messages with a GitHub action ([1da4c44](https://github.com/ruby-git/ruby-git/commit/1da4c44620a3264d4e837befd3f40416c5d8f1d8)) +* Enforce conventional commit messages with husky and commitlint ([7ebe0f8](https://github.com/ruby-git/ruby-git/commit/7ebe0f8626ecb2f0da023b903b82f7332d8afaf6)) + ## v3.0.1 (2025-05-14) [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v3.0.0..v3.0.1) diff --git a/lib/git/version.rb b/lib/git/version.rb index eb507c85..6831d2c1 100644 --- a/lib/git/version.rb +++ b/lib/git/version.rb @@ -3,5 +3,5 @@ module Git # The current gem version # @return [String] the current gem version. - VERSION='3.0.1' + VERSION='3.0.2' end