Skip to content

docs(ci): add GitHub Actions section #3558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ A number of shared configurations are available to install and use with `commitl

> ⚠️ If you want to publish your own shareable config then make sure it has a name aligning with the pattern `commitlint-config-emoji-log` or `commitlint-config-your-config-name` — then in extend all you have to write is `emoji-log` or `your-config-name`.

## Documentation

Check the [main website](https://commitlint.js.org/).

## API

- Alternative, programmatic way to interact with `commitlint`
Expand Down
41 changes: 41 additions & 0 deletions docs/guides-ci-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@ This guide assumes you have already configured `commitlint` for local usage.

Follow the [Getting Started](./?id=getting-started) for basic installation and configuration instructions.

## GitHub Actions

An example of how a GitHub Actions workflow could validate the last commit message or all commit messages inside a Pull Request:

```yml
name: CI

on: [push, pull_request]

jobs:
commitlint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Install required dependencies
run: |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be switched to use the node action?

Something liek this?

    - uses: actions/setup-node@v3
        with:
          node-version: "14"
          cache: "yarn"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I can change it if you want, but:

  • I'm not a fan of that. Reason is that I like CI steps to be copy-pastable by the devs in case they want to try to replicate in their local machines what CI is doing; and that setup-node thing would be a black box
  • I wouldn't have tested it, but the YML I have added comes from a repo of mine which is tested

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, fair enough. Let's go with this then. Thanks for your feedback.

apt update
apt install -y sudo
sudo apt install -y git curl
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo DEBIAN_FRONTEND=noninteractive apt install -y nodejs
- name: Print versions
run: |
git --version
node --version
npm --version
npx commitlint --version
- name: Install commitlint
run: |
npm install conventional-changelog-conventionalcommits
npm install commitlint@latest

- name: Validate current commit (last commit) with commitlint
if: github.event_name == 'push'
run: npx commitlint --from HEAD~1 --to HEAD --verbose

- name: Validate PR commits with commitlint
if: github.event_name == 'pull_request'
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
```

## Travis

```bash
Expand Down