From 871c244302c4cf21e7de1e7a800ae8b9c38a3fe9 Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 16:01:38 -0500 Subject: [PATCH 1/7] ci: improve commit lint enforcement this is a test commit body --- .github/workflows/pr.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 1357fe0c..865db1b1 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -23,6 +23,21 @@ jobs: - name: Execute commitlint run: npx commitlint --from=origin/${{ github.base_ref }} + - name: Get PR Title + run: "echo 'PR Title: ${{ github.event.pull_request.title }}'" + + - name: Get PR Body + run: 'echo "PR Body: ${{ github.event.pull_request.body }}"' + + - name: Fetch commits + run: git fetch origin ${{ github.event.pull_request.head.ref }} + + - name: Get commit messages + run: | + git log --pretty=format:'%s' --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} > commits.txt + echo "Commit Messages:" + cat commits.txt + check-file-format: name: Check files changes follow guidelines runs-on: ubuntu-latest From fddc2bedc20f760d91f86ab9e7f6b1e6f7ae071e Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 16:05:45 -0500 Subject: [PATCH 2/7] docs: hello This is just another commit body --- .github/workflows/pr.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 865db1b1..f48465cd 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -26,12 +26,6 @@ jobs: - name: Get PR Title run: "echo 'PR Title: ${{ github.event.pull_request.title }}'" - - name: Get PR Body - run: 'echo "PR Body: ${{ github.event.pull_request.body }}"' - - - name: Fetch commits - run: git fetch origin ${{ github.event.pull_request.head.ref }} - - name: Get commit messages run: | git log --pretty=format:'%s' --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} > commits.txt From 3ff661126b51e926089263fd719102cdc5567b0b Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 17:10:49 -0500 Subject: [PATCH 3/7] fix: verify how it works --- .github/workflows/pr.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f48465cd..7305f9e1 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -28,9 +28,14 @@ jobs: - name: Get commit messages run: | - git log --pretty=format:'%s' --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} > commits.txt - echo "Commit Messages:" - cat commits.txt + BODY=$(git log \ + --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} \ + --pretty=format:'* %s%n%n%b') + TITLE='${{ github.event.pull_request.title }}' + + echo "${TITLE}\n${BODY}" > commit-message.txt + cat commit-message.txt + cat commit-message.txt | npx commitlint check-file-format: name: Check files changes follow guidelines From 95c5a504101a5958a92733a51d408a2a9a2a8dbc Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 17:14:32 -0500 Subject: [PATCH 4/7] fix: the thing --- .github/workflows/pr.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7305f9e1..48285c1f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -33,9 +33,18 @@ jobs: --pretty=format:'* %s%n%n%b') TITLE='${{ github.event.pull_request.title }}' + echo $TITLE + echo '---------' + echo $BODY + echo '---------' + echo "${TITLE}\n${BODY}" + echo '---------' + echo "${TITLE}\n${BODY}" > commit-message.txt cat commit-message.txt - cat commit-message.txt | npx commitlint + + - name: Check commit message + run: cat commit-message.txt | npx commitlint check-file-format: name: Check files changes follow guidelines From 08a8240c8f35b93b325c629d5c3fb703cf60cbc6 Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 19:55:06 -0500 Subject: [PATCH 5/7] ci: create a pr title and commit linter --- .github/workflows/{pr.yml => ci.yml} | 41 ++----------------- .../workflows/enforce-semantic-commits.yml | 36 ++++++++++++++++ 2 files changed, 40 insertions(+), 37 deletions(-) rename .github/workflows/{pr.yml => ci.yml} (54%) create mode 100644 .github/workflows/enforce-semantic-commits.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/ci.yml similarity index 54% rename from .github/workflows/pr.yml rename to .github/workflows/ci.yml index 48285c1f..0dadfaa1 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ -name: PR's -on: - pull_request: - types: [opened, synchronize, reopened] +name: CI +# on: +# pull_request: +# types: [opened, synchronize, reopened] env: PR_NUMBER: ${{ github.event.pull_request.number }} @@ -13,39 +13,6 @@ jobs: pr-e2e-test: uses: ./.github/workflows/e2e-test.yml - check-commit-lint: - name: Check commit message follows guidelines - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Execute commitlint - run: npx commitlint --from=origin/${{ github.base_ref }} - - - name: Get PR Title - run: "echo 'PR Title: ${{ github.event.pull_request.title }}'" - - - name: Get commit messages - run: | - BODY=$(git log \ - --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} \ - --pretty=format:'* %s%n%n%b') - TITLE='${{ github.event.pull_request.title }}' - - echo $TITLE - echo '---------' - echo $BODY - echo '---------' - echo "${TITLE}\n${BODY}" - echo '---------' - - echo "${TITLE}\n${BODY}" > commit-message.txt - cat commit-message.txt - - - name: Check commit message - run: cat commit-message.txt | npx commitlint - check-file-format: name: Check files changes follow guidelines runs-on: ubuntu-latest diff --git a/.github/workflows/enforce-semantic-commits.yml b/.github/workflows/enforce-semantic-commits.yml new file mode 100644 index 00000000..1f3b5c70 --- /dev/null +++ b/.github/workflows/enforce-semantic-commits.yml @@ -0,0 +1,36 @@ +name: Enforce Semantic Commits + +on: + pull_request: + types: [opened, edited, synchronize] #? reopened + +jobs: + check-semantic-commits: + name: Check Semantic Commits + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + + - name: Fetch all commits for the PR + run: git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge + + - name: Check commit messages + run: | + COMMIT_MESSAGES="$(git log --pretty=format:'%s' --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})" + echo "$COMMIT_MESSAGES" | npx commitlint + + # 'Check if the PR title is a valid semantic commit message' + check-pr-title: + name: Check PR Title + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + + - name: Check PR Title + run: | + PR_TITLE='${{ github.event.pull_request.title }}' + echo "PR TITLE": '$PR_TITLE' + echo "$PR_TITLE" | npx commitlint From a7a96e1e02a75a0a9549e2bbe59f7bb317f8df6e Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 20:36:28 -0500 Subject: [PATCH 6/7] feat: generate changelog on ci --- .github/workflows/enforce-semantic-commits.yml | 14 ++++++++++++++ packages/ngx-deploy-npm/project.json | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/enforce-semantic-commits.yml b/.github/workflows/enforce-semantic-commits.yml index 1f3b5c70..c4c474c6 100644 --- a/.github/workflows/enforce-semantic-commits.yml +++ b/.github/workflows/enforce-semantic-commits.yml @@ -34,3 +34,17 @@ jobs: PR_TITLE='${{ github.event.pull_request.title }}' echo "PR TITLE": '$PR_TITLE' echo "$PR_TITLE" | npx commitlint + + generate-changelog: + name: Generate Changelog #? should we comment in the PR? + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: ./.github/actions/setup + + - name: Generate Changelog + run: | + git checkout -b changelog + npx nx version ngx-deploy-npm --dry-run diff --git a/packages/ngx-deploy-npm/project.json b/packages/ngx-deploy-npm/project.json index c127c28c..c08f569e 100644 --- a/packages/ngx-deploy-npm/project.json +++ b/packages/ngx-deploy-npm/project.json @@ -65,7 +65,7 @@ ] } }, - "deploy": { + "publish": { "executor": "./dist/packages/ngx-deploy-npm:deploy", "options": { "distFolderPath": "dist/packages/ngx-deploy-npm", @@ -73,7 +73,7 @@ }, "dependsOn": ["build"] }, - "deploy:without-build": { + "publish:without-build": { "executor": "./dist/packages/ngx-deploy-npm:deploy", "options": { "distFolderPath": "dist/packages/ngx-deploy-npm", @@ -90,7 +90,6 @@ "version": { "executor": "@jscutlery/semver:version", "options": { - "postTargets": ["build", "deploy"], "versionTagPrefix": "v" } } From 8823cf2043cd5b689d7fd9c1c48a2d831dc5fac9 Mon Sep 17 00:00:00 2001 From: Diego Juliao Date: Mon, 28 Oct 2024 20:52:22 -0500 Subject: [PATCH 7/7] ci: squash pr commits --- .github/actions/setup/action.yml | 11 +++ .../workflows/enforce-semantic-commits.yml | 74 ++++++++++++------- .github/workflows/publishment.yml | 6 -- 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 0754b2a7..4dd8d746 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -4,10 +4,15 @@ inputs: node-version: description: 'The Node.js version to use. The default one is going to be the defined on the .nvmrc file.' required: false + full-checkout: + description: 'Whether to do a full checkout or not. A full checkout will fetch all commits from the repository.' + required: false + default: true runs: using: composite steps: - name: Checkout all commits + if: ${{ inputs.full-checkout == 'true' }} uses: actions/checkout@v4 with: fetch-depth: 0 @@ -24,6 +29,12 @@ runs: echo "NODE_VERSION=${{ inputs.node-version }}" >> $GITHUB_ENV fi + - name: git config + shell: bash + run: | + git config user.name "ngx-deploy-npm bot" + git config user.email "-" + - name: Use Node.js uses: actions/setup-node@v4 with: diff --git a/.github/workflows/enforce-semantic-commits.yml b/.github/workflows/enforce-semantic-commits.yml index c4c474c6..debba0f2 100644 --- a/.github/workflows/enforce-semantic-commits.yml +++ b/.github/workflows/enforce-semantic-commits.yml @@ -1,3 +1,4 @@ +#? should we comment in the PR? name: Enforce Semantic Commits on: @@ -10,41 +11,64 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Fetch all commits for the PR - run: git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge + - name: git clone + uses: actions/checkout@v4 + - name: Setup + uses: ./.github/actions/setup - name: Check commit messages - run: | - COMMIT_MESSAGES="$(git log --pretty=format:'%s' --abbrev-commit ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})" - echo "$COMMIT_MESSAGES" | npx commitlint + run: npx commitlint --from=origin/${{ github.base_ref }} - # 'Check if the PR title is a valid semantic commit message' - check-pr-title: - name: Check PR Title + # Based on PR name + generate-commit-message: + name: Generate Commit Message runs-on: ubuntu-latest + outputs: + commit_message: ${{ steps.generate-message.outputs.commit_message }} steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup + - name: git clone + uses: actions/checkout@v4 - - name: Check PR Title + - name: Generate Title + id: generate-message run: | - PR_TITLE='${{ github.event.pull_request.title }}' - echo "PR TITLE": '$PR_TITLE' - echo "$PR_TITLE" | npx commitlint + COMMIT_MESSAGE='${{ github.event.pull_request.title }}' + echo "Commit Message": '$COMMIT_MESSAGE' + echo "commit_message=$COMMIT_MESSAGE" >> $GITHUB_OUTPUT + echo "$COMMIT_MESSAGE" - generate-changelog: - name: Generate Changelog #? should we comment in the PR? + validate-commit-message: + needs: [generate-commit-message] + name: Validate Commit Message runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: git clone + uses: actions/checkout@v4 + - name: Setup + uses: ./.github/actions/setup with: - fetch-depth: 0 - - uses: ./.github/actions/setup + full-checkout: false + + - name: Validate Title + run: echo "${{needs.generate-commit-message.outputs.commit_message}}" | npx commitlint + + generate-changelog: + needs: [generate-commit-message, validate-commit-message] + name: Generate Changelog + runs-on: ubuntu-latest + steps: + - name: git clone + uses: actions/checkout@v4 + - name: Setup + uses: ./.github/actions/setup + + - name: Generate tmp branch + run: git checkout -b changelog - - name: Generate Changelog + - name: Squash commits run: | - git checkout -b changelog - npx nx version ngx-deploy-npm --dry-run + git reset --soft $(git merge-base origin/${{ github.base_ref }} HEAD) + git commit -m "$COMMIT_MESSAGE" + git log -n 3 + env: + COMMIT_MESSAGE: ${{needs.generate-commit-message.outputs.commit_message}} diff --git a/.github/workflows/publishment.yml b/.github/workflows/publishment.yml index b83feca0..2fe1f3cf 100644 --- a/.github/workflows/publishment.yml +++ b/.github/workflows/publishment.yml @@ -53,12 +53,6 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup - - name: git config - shell: bash - run: | - git config user.name "Github Actions" - git config user.email "-" - - uses: ./.github/actions/download-build - name: Check npm credentials