Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandie committed Apr 13, 2023
0 parents commit a470f5a
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]

{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}

{{- if .RevertCommits -}}
### Reverts
{{ range .RevertCommits -}}
- {{ .Revert.Header }}
{{ end }}
{{ end -}}

{{- if .MergeCommits -}}
### Pull Requests
{{ range .MergeCommits -}}
- {{ .Header }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{- if .Versions }}
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
{{ range .Versions -}}
{{ if .Tag.Previous -}}
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
{{ end -}}
{{ end -}}
{{ end -}}
50 changes: 50 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/pfandie/gha-generate-changelog
options:
tag_filter_pattern: '^v'
sort: "date"

commits:
filters:
Type:
- feat
sort_by: Scope

commit_groups:
group_by: Type
sort_by: Title
title_order:
- feat
title_maps:
feat: Features

header:
pattern: "<regexp>"
pattern_maps:
- PropName

issues:
prefix:
- #

refs:
actions:
- Closes
- Fixes

merges:
pattern: "^Merge branch '(\\w+)'$"
pattern_maps:
- Source

reverts:
pattern: "^Revert \"([\\s\\S]*)\"$"
pattern_maps:
- Header

notes:
keywords:
- BREAKING CHANGE
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and Release

on:
push:
tags:
- 'v*'

jobs:
custom_test:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: read

name: Generate Release
steps:
- name: checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3

- name: Generate Changelog
uses: ./
id: changelog

- name: Create Release
uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e # v1.12.0
with:
makeLatest: true
token: ${{ github.token }}
body: ${{ steps.changelog.outputs.changelog }}
name: "Release ${{ github.ref_name }}"

- name: Create additional Major/Minor tags
uses: vweevers/additional-tags-action@3bab55b44e81186dcfef7db9f2cbca01a78eb710 # v2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_STORE
.idea
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM alpine:3.17.3@sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126

ENV CHGLOG_VERSION=0.15.4
COPY entrypoint.sh /entrypoint.sh
COPY .chglog /.chglog

RUN apk add --no-cache \
bash \
git \
jq

RUN wget -q https://github.com/git-chglog/git-chglog/releases/download/v${CHGLOG_VERSION}/git-chglog_${CHGLOG_VERSION}_linux_amd64.tar.gz -P /tmp/ && \
tar -xzf /tmp/git-chglog_${CHGLOG_VERSION}_linux_amd64.tar.gz -C /usr/local/bin/ && \
chmod 755 /entrypoint.sh /usr/local/bin/git-chglog

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 Hans Mayer and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Generate changelog with git-chglog

This GitHub Action creates a CHANGELOG output based on git-chglog tool. \
For configuration options see the [git-chglog](https://github.com/git-chglog/git-chglog) repository.

## Features

- Generates the CHANGELOG changes in Markdown format based on git-chglog.
- Exports changelog to a variable that can used in a subsequent step to create a release changelog.
- Use your exiting git-chglog configuration and template.
- Create a new CHANGELOG.md file or append to an existing one.

## Example workflows

### Generate CHANGELOG on every `push` to `main`

```yaml
name: Build and release
on:
push:
branches:
- main

jobs:
package:
runs-on: ubuntu-latest
steps:
- uses: pfandie/generate-changelog-action@v1
with:
next_version: "${{ github.ref_name }}"
```
### Generate CHANGELOG on `push` to `release` branches

```yaml
name: Build and Release
on:
push:
branches:
- 'release/*'
jobs:
custom_test:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
name: Generate Release
steps:
- name: checkout
uses: actions/checkout@v3
- name: Generate Changelog
uses: pfandie/generate-changelog-action@v1
id: changelog
with:
config_path:
next_tag: "${{ github.ref_name }}"
output_file: "MyChangelog.md"
write_file: true
```

### Generate CHANGELOG and Release on tag push

```yaml
name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
custom_test:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
name: Generate Release
steps:
- name: checkout
uses: actions/checkout@v3
- name: Generate Changelog
uses: pfandie/generate-changelog-action@v1
id: changelog
- name: Create Release
uses: ncipollo/release-action@v1.12.0
with:
makeLatest: true
token: ${{ github.token }}
body: ${{ steps.changelog.outputs.changelog }}
name: "Release ${{ github.ref_name }}"
```

## Input Parameters

| Parameter | Description | Required | Default |
|---------------|------------------------------------------------------------------|--------------------|----------------|
| `config_path` | Path to config directory. Defaults to: `.chglog` | :x: | `null` |
| `next_tag` | The next tag for version number, e.g. `"${{ github.ref_name }}"` | :white_check_mark: | `null` |
| `output_file` | Name of the output file, requires `write_file` == true | :x: | `CHANGELOG.md` |
| `write_file` | Write output to file | :x: | `false` |

### Outputs
- `changelog`: Changelog content if `outputFile` is not set

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/pfandie/generate-changelog-action/tags).

## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)

## Credits

- [github-changelog-action](https://github.com/nuuday/github-changelog-action) for inspiring to extend the actions
- [git-chglog](https://github.com/git-chglog/git-chglog) for a great tool on creating (and customizing) CHANGELOG
- [jacobtomlinson](https://github.com/jacobtomlinson) for the post of [Creating GitHub Actions in Go](https://jacobtomlinson.dev/posts/2019/creating-github-actions-in-go/)
38 changes: 38 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Generate CHANGELOG based on git-chglog"
description: "Generates a changelog using git-chlog tool. Use output changelog to create a release."
author: "Hans Mayer"
branding:
icon: "shopping-cart"
color: "blue"

inputs:
config_path:
description: "Configuration directory for git-chglog"
default: "/.chglog"
required: false

next_tag:
description: "Tag of next version"
required: true

output_file:
description: "The file, where the output should be written"
default: "CHANGELOG.md"
required: false

write_file:
description: "Output file should be written"
required: false

outputs:
changelog:
description: "The CHANGELOG content"

runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.config_path }}
- ${{ inputs.next_tag }}
- ${{ inputs.output_file }}
- ${{ inputs.write_file }}
35 changes: 35 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

# Check if required NEXT_TAG input is set
if [[ -n "$INPUT_NEXT_TAG" ]]; then
echo "ℹ️ Set next Tag to $INPUT_NEXT_TAG"
next_tag="--next-tag '$INPUT_NEXT_TAG'"
fi

# Set Output file
if [[ "$INPUT_WRITE_FILE" == 'true' && -n "$INPUT_OUTPUT_FILE" ]]; then
echo "ℹ️ Set file output to: $INPUT_OUTPUT_FILE"
output_file="--output '$INPUT_OUTPUT_FILE'"
fi

# Add Workspace to safe.directory to allow fetching git tags
git config --global --add safe.directory "${GITHUB_WORKSPACE}"

# Generate CHANGELOG based on settings
echo "🔖 Generating CHANGELOG"
changelog=$(/usr/local/bin/git-chglog -c "${INPUT_CONFIG_PATH}/config.yml" "$next_tag" "$output_file")

# Print CHANGELOG to stdout
echo "----------------------------------------------------------"
echo "${changelog}"
echo "----------------------------------------------------------"

# Set output for followup GitHub steps
echo "ℹ️ Return CHANGELOG to Output for use in followup Steps"
{
echo "changelog<<EOF"
echo "$changelog"
echo "EOF"
} >> "$GITHUB_OUTPUT"
Loading

0 comments on commit a470f5a

Please sign in to comment.