Skip to content

Commit

Permalink
build: implement changelog generate. (#748)
Browse files Browse the repository at this point in the history
* fix: improve release generate file.

* refactor: improve changelog structure.

* update goreleaser

* feat: implement changelog generate.

* remove README.md
use generate.
  • Loading branch information
mo3et authored and OpenIM-Robot committed Oct 25, 2024
1 parent 414adeb commit 31fbb84
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 589 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Release Changelog

on:
release:
types: [released]

permissions:
contents: write
pull-requests: write

jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Go Changelog Generator
run: |
# Run the Go changelog generator, passing the release tag if available
if [ "${{ github.event.release.tag_name }}" = "latest" ]; then
go run tools/changelog/changelog.go > "${{ github.event.release.tag_name }}-changelog.md"
else
go run tools/changelog/changelog.go "${{ github.event.release.tag_name }}" > "${{ github.event.release.tag_name }}-changelog.md"
fi
- name: Handle changelog files
run: |
# Ensure that the CHANGELOG directory exists
mkdir -p CHANGELOG
# Extract Major.Minor version by removing the 'v' prefix from the tag name
TAG_NAME=${{ github.event.release.tag_name }}
CHANGELOG_VERSION_NUMBER=$(echo "$TAG_NAME" | sed 's/^v//' | grep -oP '^\d+\.\d+')
# Define the new changelog file path
CHANGELOG_FILENAME="CHANGELOG-$CHANGELOG_VERSION_NUMBER.md"
CHANGELOG_PATH="CHANGELOG/$CHANGELOG_FILENAME"
# Check if the changelog file for the current release already exists
if [ -f "$CHANGELOG_PATH" ]; then
# If the file exists, append the new changelog to the existing one
cat "$CHANGELOG_PATH" >> "${TAG_NAME}-changelog.md"
# Overwrite the existing changelog with the updated content
mv "${TAG_NAME}-changelog.md" "$CHANGELOG_PATH"
else
# If the changelog file doesn't exist, rename the temp changelog file to the new changelog file
mv "${TAG_NAME}-changelog.md" "$CHANGELOG_PATH"
# Ensure that README.md exists
if [ ! -f "CHANGELOG/README.md" ]; then
echo -e "# CHANGELOGs\n\n" > CHANGELOG/README.md
fi
# Add the new changelog entry at the top of the README.md
if ! grep -q "\[$CHANGELOG_FILENAME\]" CHANGELOG/README.md; then
sed -i "3i- [$CHANGELOG_FILENAME](./$CHANGELOG_FILENAME)" CHANGELOG/README.md
# Remove the extra newline character added by sed
# sed -i '4d' CHANGELOG/README.md
fi
fi
- name: Clean up
run: |
# Remove any temporary files that were created during the process
rm -f "${{ github.event.release.tag_name }}-changelog.md"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7.0.5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update CHANGELOG for release ${{ github.event.release.tag_name }}"
title: "Update CHANGELOG for release ${{ github.event.release.tag_name }}"
body: "This PR updates the CHANGELOG files for release ${{ github.event.release.tag_name }}"
branch: changelog-${{ github.event.release.tag_name }}
base: main
delete-branch: true
labels: changelog
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ deploy/Open-IM-SDK-Core
# Dependency directories (remove the comment below to include it)
vendor/
bin/
tools/
tmp/


Expand Down
86 changes: 34 additions & 52 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ before:
- go generate ./...



git:
# What should be used to sort tags when gathering the current and previous
# tags if there are more than one tag in the same commit.
Expand Down Expand Up @@ -37,7 +36,7 @@ report_sizes: true
builds:
- id: openIM.wasm
main: wasm/cmd/main.go # Specify the path to the main WASM file
binary: openIM.wasm
binary: openIM
ldflags: "-s -w"
goos:
- js
Expand Down Expand Up @@ -88,39 +87,39 @@ archives:
- goos: windows
format: zip

changelog:
sort: asc
use: github
filters:
exclude:
- "^test:"
- "^chore"
- "merge conflict"
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 300
- title: "New Features"
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: "Security updates"
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
order: 150
- title: "Bug fixes"
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: "Documentation updates"
regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$
order: 400
- title: "Build process updates"
regexp: ^.*?build(\([[:word:]]+\))??!?:.+$
order: 400
- title: Other work
order: 9999
# changelog:
# sort: asc
# use: github
# filters:
# exclude:
# - "^test:"
# - "^chore"
# - "merge conflict"
# - Merge pull request
# - Merge remote-tracking branch
# - Merge branch
# - go mod tidy
# groups:
# - title: Dependency updates
# regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
# order: 300
# - title: "New Features"
# regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
# order: 100
# - title: "Security updates"
# regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
# order: 150
# - title: "Bug fixes"
# regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
# order: 200
# - title: "Documentation updates"
# regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$
# order: 400
# - title: "Build process updates"
# regexp: ^.*?build(\([[:word:]]+\))??!?:.+$
# order: 400
# - title: Other work
# order: 9999


# nfpms:
Expand Down Expand Up @@ -167,22 +166,5 @@ dist: ./_output/dist
# # Default: '{{ .Tag }}'
# name_template: "Current Release"

# publishers:
# - name: "fury.io"
# ids:
# - packages
# dir: "{{ dir .ArtifactPath }}"
# cmd: |
# bash -c '
# if [[ "{{ .Tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# curl -F package=@{{ .ArtifactName }} https://{{ .Env.FURY_TOKEN }}@push.fury.io/{{ .Env.USERNAME }}/
# else
# echo "Skipping deployment: Non-production release detected"
# fi'

checksum:
name_template: "{{ .ProjectName }}_checksums.txt"
algorithm: sha256

release:
prerelease: auto
62 changes: 0 additions & 62 deletions CHANGELOG/.chglog/CHANGELOG.tpl.md

This file was deleted.

81 changes: 0 additions & 81 deletions CHANGELOG/.chglog/config.yml

This file was deleted.

42 changes: 0 additions & 42 deletions CHANGELOG/CHANGELOG-1.0.md

This file was deleted.

Empty file removed CHANGELOG/CHANGELOG-1.1.md
Empty file.
Loading

0 comments on commit 31fbb84

Please sign in to comment.