fix: CI-CD Optimisation #5499
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This action is centrally managed in https://github.com/asyncapi/.github/ | |
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | |
name: Lint PR title | |
on: | |
pull_request_target: | |
types: [opened, reopened, synchronize, edited, ready_for_review] | |
jobs: | |
lint-pr-title: | |
name: Lint PR title | |
runs-on: ubuntu-latest | |
steps: | |
# Check if this is a repeated title-only change to avoid unnecessary runs | |
- name: Check if title-only change | |
if: github.event.action == 'edited' | |
id: check_title_only | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GH_TOKEN }} | |
script: | | |
const { data: pr } = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}); | |
// Check if there are any file changes in the PR | |
const { data: files } = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}); | |
// Check if there are existing title lint comments (indicating previous title validation) | |
const { data: comments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number | |
}); | |
const hasExistingTitleLintComment = comments.some(comment => | |
comment.body.includes('Conventional Commits specification') || | |
comment.body.includes('pr-title-lint-error') | |
); | |
// Skip if this is an edit with no code changes and we've already validated title before | |
const shouldSkip = github.event.action === 'edited' && | |
files.length === 0 && | |
hasExistingTitleLintComment && | |
github.event.changes?.title; | |
console.log(`Should skip title validation: ${shouldSkip}`); | |
console.log(`Files changed: ${files.length}`); | |
console.log(`Has existing title lint comment: ${hasExistingTitleLintComment}`); | |
return shouldSkip; | |
# Since this workflow is REQUIRED for a PR to be mergable, we have to have this 'if' statement in step level instead of job level. | |
- if: ${{ !contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]", "allcontributors[bot]"]'), github.actor) && steps.check_title_only.outputs.result != 'true' }} | |
uses: amannn/action-semantic-pull-request@c3cd5d1ea3580753008872425915e343e351ab54 #version 5.2.0 https://github.com/amannn/action-semantic-pull-request/releases/tag/v5.2.0 | |
id: lint_pr_title | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} | |
with: | |
subjectPattern: ^(?![A-Z]).+$ | |
subjectPatternError: | | |
The subject "{subject}" found in the pull request title "{title}" should start with a lowercase character. | |
# Comments the error message from the above lint_pr_title action | |
- if: ${{ always() && steps.lint_pr_title.outputs.error_message != null && !contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]", "allcontributors[bot]"]'), github.actor)}} | |
name: Comment on PR | |
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd #use 2.5.0 https://github.com/marocchino/sticky-pull-request-comment/releases/tag/v2.5.0 | |
with: | |
header: pr-title-lint-error | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} | |
message: | | |
We require all PRs to follow [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). | |
More details 👇🏼 | |
``` | |
${{ steps.lint_pr_title.outputs.error_message}} | |
``` | |
# deletes the error comment if the title is correct | |
- if: ${{ steps.lint_pr_title.outputs.error_message == null }} | |
name: delete the comment | |
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd #use 2.5.0 https://github.com/marocchino/sticky-pull-request-comment/releases/tag/v2.5.0 | |
with: | |
header: pr-title-lint-error | |
delete: true | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} |