Skip to content

Commit

Permalink
ci: squash pr commits
Browse files Browse the repository at this point in the history
  • Loading branch information
dianjuar committed Oct 29, 2024
1 parent a7a96e1 commit 8823cf2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
11 changes: 11 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
74 changes: 49 additions & 25 deletions .github/workflows/enforce-semantic-commits.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#? should we comment in the PR?
name: Enforce Semantic Commits

on:
Expand All @@ -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}}
6 changes: 0 additions & 6 deletions .github/workflows/publishment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8823cf2

Please sign in to comment.