From 6fb9493672d60612f5122d7f70796a4d20fda472 Mon Sep 17 00:00:00 2001 From: Scott Schreckengaust Date: Wed, 29 Nov 2023 19:51:55 +0000 Subject: [PATCH 1/7] feat: add commitlint github workflow Signed-off-by: Scott Schreckengaust --- .gitattributes | 1 + .github/workflows/commitlint.yml | 32 +++++++++++++++++ .gitignore | 1 + .projen/files.json | 1 + .projenrc.ts | 2 ++ projenrc/github-workflows.ts | 61 ++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 .github/workflows/commitlint.yml diff --git a/.gitattributes b/.gitattributes index f4fcbaa5..2c867fb6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,6 +7,7 @@ /.github/workflows/auto-approve.yml linguist-generated /.github/workflows/bandit.yml linguist-generated /.github/workflows/build.yml linguist-generated +/.github/workflows/commitlint.yml linguist-generated /.github/workflows/github-merit-badger.yml linguist-generated /.github/workflows/monthly-repo-metrics.yml linguist-generated /.github/workflows/ort-toolkit.yml linguist-generated diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 00000000..90e9af3f --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,32 @@ +# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". + +name: commitlint +on: + pull_request: {} + workflow_dispatch: {} + push: {} +jobs: + commitlint: + name: commitlint/ci + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + security-events: write + actions: read + if: (github.actor != 'dependabot[bot]') + steps: + - name: Checkout project + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + - name: Setup Node + uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 + 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 diff --git a/.gitignore b/.gitignore index f0218b86..cb7e6abb 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ tsconfig.json !/.github/workflows/ort-toolkit.yml !/.github/workflows/semgrep.yml !/.github/workflows/bandit.yml +!/.github/workflows/commitlint.yml diff --git a/.projen/files.json b/.projen/files.json index 2a2005fc..6846115a 100644 --- a/.projen/files.json +++ b/.projen/files.json @@ -6,6 +6,7 @@ ".github/workflows/auto-approve.yml", ".github/workflows/bandit.yml", ".github/workflows/build.yml", + ".github/workflows/commitlint.yml", ".github/workflows/github-merit-badger.yml", ".github/workflows/monthly-repo-metrics.yml", ".github/workflows/ort-toolkit.yml", diff --git a/.projenrc.ts b/.projenrc.ts index 84d473bd..e3d2cd44 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -20,6 +20,7 @@ import { buildOrtToolkitWorkflow, runSemGrepWorkflow, runBanditWorkflow, + runCommitLintWorkflow, } from './projenrc/github-workflows'; // Constants @@ -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'); diff --git a/projenrc/github-workflows.ts b/projenrc/github-workflows.ts index 1682816a..ce946878 100644 --- a/projenrc/github-workflows.ts +++ b/projenrc/github-workflows.ts @@ -429,3 +429,64 @@ 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', + }, + { + 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, + }); + } + } +} From 79cf17d9f27ab8d1849087eb14e873a494a8e654 Mon Sep 17 00:00:00 2001 From: Scott Schreckengaust Date: Wed, 29 Nov 2023 23:14:02 +0000 Subject: [PATCH 2/7] fix: checkout depth for review Signed-off-by: Scott Schreckengaust --- .github/workflows/commitlint.yml | 2 ++ projenrc/github-workflows.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 90e9af3f..48d75e75 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -18,6 +18,8 @@ jobs: steps: - name: Checkout project uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 + with: + fetch-depth: "2" - name: Setup Node uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 with: diff --git a/projenrc/github-workflows.ts b/projenrc/github-workflows.ts index ce946878..4a1ff1a1 100644 --- a/projenrc/github-workflows.ts +++ b/projenrc/github-workflows.ts @@ -451,6 +451,9 @@ export function runCommitLintWorkflow(project: AwsCdkConstructLibrary) { { name: 'Checkout project', uses: 'actions/checkout@v3', + with: { + "fetch-depth": "2", + } }, { name: 'Setup Node', From 2761530000bfde92b63656305a7b23f45ade4636 Mon Sep 17 00:00:00 2001 From: Scott Schreckengaust Date: Wed, 29 Nov 2023 23:15:18 +0000 Subject: [PATCH 3/7] fix: add commitlint configuration Signed-off-by: Scott Schreckengaust --- commitlint.config.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 commitlint.config.js diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000..28fe5c5b --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1 @@ +module.exports = {extends: ['@commitlint/config-conventional']} From d53be0ba9c7d1293c2469de734ac0011dc2cebeb Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 29 Nov 2023 23:21:13 +0000 Subject: [PATCH 4/7] chore: self mutation Signed-off-by: github-actions --- projenrc/github-workflows.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projenrc/github-workflows.ts b/projenrc/github-workflows.ts index 4a1ff1a1..d1256711 100644 --- a/projenrc/github-workflows.ts +++ b/projenrc/github-workflows.ts @@ -452,8 +452,8 @@ export function runCommitLintWorkflow(project: AwsCdkConstructLibrary) { name: 'Checkout project', uses: 'actions/checkout@v3', with: { - "fetch-depth": "2", - } + 'fetch-depth': '2', + }, }, { name: 'Setup Node', From fd920504216634cdbaba0e67988c556a14e7366e Mon Sep 17 00:00:00 2001 From: Scott Schreckengaust Date: Wed, 29 Nov 2023 23:40:47 +0000 Subject: [PATCH 5/7] fix: merge conflict Signed-off-by: Scott Schreckengaust --- .github/workflows/commitlint.yml | 2 +- projenrc/github-workflows.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 48d75e75..3a1a3af8 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout project uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 with: - fetch-depth: "2" + fetch-depth: "0" - name: Setup Node uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 with: diff --git a/projenrc/github-workflows.ts b/projenrc/github-workflows.ts index d1256711..480ce69b 100644 --- a/projenrc/github-workflows.ts +++ b/projenrc/github-workflows.ts @@ -452,7 +452,7 @@ export function runCommitLintWorkflow(project: AwsCdkConstructLibrary) { name: 'Checkout project', uses: 'actions/checkout@v3', with: { - 'fetch-depth': '2', + "fetch-depth": "0", }, }, { From 07814883946b28fbbf235b679ffe7ad31e2168ba Mon Sep 17 00:00:00 2001 From: Scott Schreckengaust Date: Thu, 30 Nov 2023 00:41:39 +0000 Subject: [PATCH 6/7] fix: run ort manually Signed-off-by: Scott Schreckengaust --- .github/workflows/ort-toolkit.yml | 3 --- projenrc/github-workflows.ts | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ort-toolkit.yml b/.github/workflows/ort-toolkit.yml index d58a3c8d..472ccadc 100644 --- a/.github/workflows/ort-toolkit.yml +++ b/.github/workflows/ort-toolkit.yml @@ -2,9 +2,6 @@ name: ort-toolkit on: - push: - branches: - - main workflow_dispatch: {} jobs: ort: diff --git a/projenrc/github-workflows.ts b/projenrc/github-workflows.ts index 480ce69b..17f05366 100644 --- a/projenrc/github-workflows.ts +++ b/projenrc/github-workflows.ts @@ -267,11 +267,11 @@ export function buildOrtToolkitWorkflow(project: AwsCdkConstructLibrary) { const workflow = project.github.addWorkflow('ort-toolkit'); if (workflow) { workflow.on({ - push: { - branches: [ - 'main', - ], - }, + // push: { + // branches: [ + // 'main', + // ], + // }, workflowDispatch: {}, }); workflow.addJobs({ ort: orttoolkit }); From a086c24d455181408fe99cab8cbf70e1c143abac Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 30 Nov 2023 00:45:26 +0000 Subject: [PATCH 7/7] chore: self mutation Signed-off-by: github-actions --- projenrc/github-workflows.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projenrc/github-workflows.ts b/projenrc/github-workflows.ts index 17f05366..013f9935 100644 --- a/projenrc/github-workflows.ts +++ b/projenrc/github-workflows.ts @@ -452,7 +452,7 @@ export function runCommitLintWorkflow(project: AwsCdkConstructLibrary) { name: 'Checkout project', uses: 'actions/checkout@v3', with: { - "fetch-depth": "0", + 'fetch-depth': '0', }, }, {