Skip to content

Commit

Permalink
feat: add commitlint github action
Browse files Browse the repository at this point in the history
* feat: add commitlint github workflow

Signed-off-by: Scott Schreckengaust <scottschreckengaust@users.noreply.github.com>

---------

Signed-off-by: Scott Schreckengaust <scottschreckengaust@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
scottschreckengaust and github-actions authored Nov 30, 2023
1 parent ab8b901 commit 5f9c7e6
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .github/workflows/commitlint.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
buildOrtToolkitWorkflow,
runSemGrepWorkflow,
runBanditWorkflow,
runCommitLintWorkflow,
} from './projenrc/github-workflows';

// Constants
Expand Down Expand Up @@ -97,6 +98,7 @@ buildAutoApproveWorkflow(project);
buildOrtToolkitWorkflow(project);
runSemGrepWorkflow(project);
runBanditWorkflow(project);
runCommitLintWorkflow(project);

// Add specific overrides https://projen.io/github.html#actions-versions
project.github?.actions.set('actions/checkout@v3', 'actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744');
Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']}
64 changes: 64 additions & 0 deletions projenrc/github-workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,67 @@ export function runBanditWorkflow(project: AwsCdkConstructLibrary) {
}
}
}

/**
* https://commitlint.js.org/#/guides-ci-setup
* Runs commitlint on the repository.
* @param project AwsCdkConstructLibrary
*/
export function runCommitLintWorkflow(project: AwsCdkConstructLibrary) {
const commitlint: Job = {
name: 'commitlint/ci',
runsOn: ['ubuntu-latest'],
permissions: {
contents: JobPermission.READ,
pullRequests: JobPermission.READ,
securityEvents: JobPermission.WRITE,
actions: JobPermission.READ,
},
if: "(github.actor != 'dependabot[bot]')",

steps: [
{
name: 'Checkout project',
uses: 'actions/checkout@v3',
with: {
'fetch-depth': '0',
},
},
{
name: 'Setup Node',
uses: 'actions/setup-node@v3',
with: {
'node-version': '20.x',
},
},
{
name: 'Install CommitLint',
run: 'npm install -g @commitlint/config-conventional commitlint',
},
{
name: 'Validate Current Commit',
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',
},
],
};

if (project.github) {
const workflow = project.github.addWorkflow('commitlint');
if (workflow) {
workflow.on({
pullRequest: {},
workflowDispatch: {},
push: {},
});
workflow.addJobs({
commitlint: commitlint,
});
}
}
}

0 comments on commit 5f9c7e6

Please sign in to comment.