Skip to content

Commit

Permalink
Add CHANGELOG check before release
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-jozwikowski committed Jan 23, 2024
1 parent ad1f6fa commit 19ca748
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,34 @@ jobs:
Build-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check Changelog
run: |
TAG=$(git tag --points-at $GITHUB_SHA | sed 's/^v//')
CHANGELOG_ENTRY="## [$TAG] -"
if ! grep -Fq "$CHANGELOG_ENTRY" CHANGELOG.md; then
echo "Error: Changelog entry not found for tag $TAG in CHANGELOG.md"
exit 1
fi
# A fallback
cat CHANGELOG.md > release_body
# Fetch lines from CHANGELOG between the previous and current tag
PREVIOUS_TAG=$(git tag -l | sort -V | tail -n 2 | head -n 1 | sed 's/^v//')
if [ -n "$PREVIOUS_TAG" ]; then
PREVIOUS_TAG_ENTRY="## [$PREVIOUS_TAG] -"
PREVIOUS_TAG_LINE=$(grep -nF "$PREVIOUS_TAG_ENTRY" CHANGELOG.md | cut -d: -f1)
if [ -n "$PREVIOUS_TAG_LINE" ]; then
PREVIOUS_TAG_LINE=$((PREVIOUS_TAG_LINE - 1))
CURRENT_TAG_LINE=$(grep -nF "$CHANGELOG_ENTRY" CHANGELOG.md | tail -n 1 | cut -d: -f1)
sed -n "${CURRENT_TAG_LINE},${PREVIOUS_TAG_LINE}p" CHANGELOG.md > release_body
fi
fi
- name: Set up Go
uses: actions/setup-go@v2
Expand Down Expand Up @@ -49,7 +76,7 @@ jobs:
prerelease: false
release_name: ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
body_path: CHANGELOG.md
body_path: release_body
env:
GITHUB_TOKEN: ${{ github.token }}

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.10.1] - 2024-01-23

### Added

- Check for CHANGELOG in the workflow before new release

## [0.10.0] - 2024-01-23

### Added

- `-f` flag to display the file change lines coming from `tail`
- `-n` flag to remove empty lines between log entries

## [0.9.0] - 2023-12-05

### Added
Expand Down

0 comments on commit 19ca748

Please sign in to comment.