diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml new file mode 100644 index 00000000..7236c5d9 --- /dev/null +++ b/.github/workflows/changelog.yaml @@ -0,0 +1,54 @@ +name: Changelog + +on: + push: + tags: + - "v*" + workflow_dispatch: + inputs: + version: + description: "Version tag to generate changelog for (e.g. v1.0.0)" + required: true + type: string + +permissions: + contents: write + +jobs: + changelog: + name: Generate Changelog + runs-on: ubuntu-latest + env: + VERSION_TAG: ${{ inputs.version || github.ref_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate changelog + uses: orhun/git-cliff-action@v4 + id: git-cliff + with: + config: cliff.toml + args: --verbose --tag ${{ env.VERSION_TAG }} + env: + OUTPUT: CHANGELOG.md + GITHUB_REPO: ${{ github.repository }} + + - name: Commit changelog + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add CHANGELOG.md + git commit -m "chore: update changelog for ${{ env.VERSION_TAG }}" || true + git push origin HEAD:main + + - name: Create/update GitHub release body + uses: orhun/git-cliff-action@v4 + with: + config: cliff.toml + args: --verbose --latest --strip header + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPO: ${{ github.repository }} diff --git a/.github/workflows/commitlint.yaml b/.github/workflows/commitlint.yaml new file mode 100644 index 00000000..27aeee72 --- /dev/null +++ b/.github/workflows/commitlint.yaml @@ -0,0 +1,30 @@ +name: Commit Lint + +on: + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + commitlint: + name: Lint Commit Messages + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install commitlint + run: npm install --save-dev @commitlint/{cli,config-conventional} + + - name: Lint commits + run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 00000000..e0e71e9f --- /dev/null +++ b/cliff.toml @@ -0,0 +1,71 @@ +[changelog] +header = """ +# Changelog + +All notable changes to this project will be documented in this file. + +This changelog is automatically generated based on [Conventional Commits](https://www.conventionalcommits.org/).\n +""" +body = """ +{%- macro remote_url() -%} + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }} +{%- endmacro -%} + +{% if version -%} +## [{{ version | trim_start_matches(pat="v") }}]\ + {% if commit_id %}({{ self::remote_url() }}/tree/{{ version }}){% endif %}\ + {% if timestamp %} - {{ timestamp | date(format="%Y-%m-%d") }}{% endif %} +{% else -%} +## [Unreleased] +{% endif -%} + +{% for group, commits in commits | group_by(attribute="group") %} +### {{ group | striptags | trim | upper_first }} +{% for commit in commits +| filter(attribute="scope") +| sort(attribute="scope") %} + - *({{ commit.scope }})* {{ commit.message | upper_first }}\ + {% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%} + {% if commit.github.pr_number %} in \ + [#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }})\ + {%- endif %} +{%- endfor -%} +{% for commit in commits %} +{%- if not commit.scope %} + - {{ commit.message | upper_first }}\ + {% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%} + {% if commit.github.pr_number %} in \ + [#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }})\ + {%- endif %} +{%- endif -%} +{%- endfor -%} +{% endfor %} +""" +footer = "" +trim = true + +[git] +conventional_commits = true +filter_unconventional = false +split_commits = false +commit_parsers = [ + { message = "^feat", group = "๐Ÿš€ Features" }, + { message = "^fix", group = "๐Ÿ› Bug Fixes" }, + { message = "^perf", group = "โšก Performance" }, + { message = "^doc", group = "๐Ÿ“š Documentation" }, + { message = "^example", group = "๐Ÿ“ฆ Examples" }, + { message = "^refactor", group = "๐Ÿ”ง Refactoring" }, + { message = "^chore\\(deps\\)", group = "๐Ÿ“ฆ Dependencies" }, + { message = "^chore|^ci", group = "๐Ÿ—๏ธ Maintenance" }, + { message = "^test", group = "๐Ÿงช Testing" }, + { message = "^Bump ", group = "๐Ÿ“ฆ Dependencies" }, + { message = "^.*", group = "๐Ÿ”€ Other" }, +] +protect_breaking_commits = true +filter_commits = false +tag_pattern = "v[0-9].*" +sort_commits = "newest" + +[remote.github] +owner = "awslabs" +repo = "aws-lambda-web-adapter" diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000..47c5349b --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,26 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'type-enum': [ + 2, + 'always', + [ + 'feat', + 'fix', + 'docs', + 'example', + 'examples', + 'chore', + 'refactor', + 'perf', + 'test', + 'ci', + 'revert', + ], + ], + 'subject-case': [0], + 'body-max-line-length': [0], + 'footer-max-line-length': [0], + 'header-max-length': [2, 'always', 120], + }, +};