Skip to content

Commit

Permalink
Init auto gen changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
chen08209 committed Oct 12, 2024
1 parent 89bbbc6 commit fcca017
Show file tree
Hide file tree
Showing 3 changed files with 712 additions and 58 deletions.
85 changes: 44 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ jobs:
overwrite: true


upload-release:
if: ${{ !contains(github.ref, '+') }}
upload:
permissions: write-all
needs: [ build ]
runs-on: ubuntu-latest
Expand All @@ -123,32 +122,63 @@ jobs:
pattern: artifact-*
merge-multiple: true

- name: Pre Release
- name: Generate release.md
run: |
pip install gitchangelog pystache mustache markdown
pre=$(curl --silent "https://api.github.com/repos/chen08209/FlClash/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' || echo "")
if [ -z "pre" ]; then
echo "init" > release.md
else
current="${{ github.ref_name }}"
echo -e "\n\n<details markdown=1><summary>All changes from $current to the latest commit:</summary>\n\n" >> release.md
gitchangelog "${pre}.." >> release.md 2>&1 || echo "Error in gitchangelog"
echo -e "\n\n</details>" >> release.md
fi
tags=($(git tag --merged $(git rev-parse HEAD) --sort=-creatordate))
preTag=$(curl --silent "https://api.github.com/repos/chen08209/FlClash/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' || echo "")
currentTag=""
for ((i = 0; i <= ${#tags[@]}; i++)); do
if (( i < ${#tags[@]} )); then
tag=${tags[$i]}
else
tag=""
fi
if [ -n "$currentTag" ]; then
if [ "$(echo -e "$currentTag\n$preTag" | sort -V | head -n 1)" == "$currentTag" ]; then
break
fi
fi
if [ -n "$currentTag" ]; then
echo "## $currentTag" >> release.md
echo "" >> release.md
if [ -n "$tag" ]; then
git log --pretty=format:"%B" "$tag..$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> release.md
else
git log --pretty=format:"%B" "$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> release.md
fi
echo "" >> release.md
fi
currentTag=$tag
done
- name: Get Branch
run: echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV

- name: Upload
if: env.BRANCH_NAME != 'main'
uses: actions/upload-artifact@v4
with:
name: artifact
path: ./dist
retention-days: 7
overwrite: true

- name: Release
if: env.BRANCH_NAME == 'main'
uses: softprops/action-gh-release@v2
with:
files: ./dist/*
body_path: './release.md'

- name: Create Fdroid Source Dir
if: env.BRANCH_NAME == 'main'
run: |
mkdir -p ./tmp
cp ./dist/*android-arm64-v8a* ./tmp/ || true
echo "Files copied successfully"
- name: Push to fdroid repo
if: env.BRANCH_NAME == 'main'
uses: cpina/[email protected]
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
Expand All @@ -160,31 +190,4 @@ jobs:
user-email: 'github-actions[bot]@users.noreply.github.com'
target-branch: action-pr
commit-message: Update from ${{ github.ref_name }}
target-directory: /tmp/


upload-test:
if: ${{ contains(github.ref, '+') }}
permissions: write-all
needs: [ build ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download
uses: actions/download-artifact@v4
with:
path: ./dist/
pattern: artifact-*
merge-multiple: true

- name: Upload
uses: actions/upload-artifact@v4
with:
name: artifact
path: ./dist
retention-days: 7
overwrite: true
target-directory: /tmp/
55 changes: 38 additions & 17 deletions .github/workflows/change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'main'

jobs:
changelog:
change:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -16,30 +16,51 @@ jobs:

- name: Generate
run: |
tags=$(git tag --sort=creatordate)
previous=""
if [ ! -f CHANGELOG.md ]; then
echo "" > CHANGELOG.md
else
previous=$(grep -oP '^## \K.*' CHANGELOG.md | tail -n 1)
tags=($(git tag --merged $(git rev-parse HEAD) --sort=-creatordate))
preTag=""
currentTag=""
if [ -f CHANGELOG.md ]; then
preTag=$(grep -oP '^## \K.*' CHANGELOG.md | head -n 1)
fi
for tag in $tags; do
if [ -n "$previous" ]; then
echo "## $tag" >> CHANGELOG.md
git log --pretty=format:"* %s (%h)" "$previous..$tag" >> CHANGELOG.md
echo -e "\n" >> CHANGELOG.md
for ((i = 0; i <= ${#tags[@]}; i++)); do
if (( i < ${#tags[@]} )); then
tag=${tags[$i]}
else
tag=""
fi
if [ -n "$currentTag" ]; then
if [ "$(echo -e "$currentTag\n$preTag" | sort -V | head -n 1)" == "$currentTag" ]; then
break
fi
fi
if [ -n "$currentTag" ]; then
echo "## $currentTag" >> NEW_CHANGELOG.md
echo "" >> NEW_CHANGELOG.md
if [ -n "$tag" ]; then
git log --pretty=format:"%B" "$tag..$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md
else
git log --pretty=format:"%B" "$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md
fi
echo "" >> NEW_CHANGELOG.md
fi
previous=$tag
currentTag=$tag
done
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> NEW_CHANGELOG.md
fi
mv NEW_CHANGELOG.md CHANGELOG.md
- name: Commit
run: |
if !git diff --cached --quiet; then
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git config --local user.email "[email protected]"
git config --local user.name "chen08209"
git add CHANGELOG.md
if ! git diff --cached --quiet; then
git commit -m "Update Changelog"
git push
else
echo "CHANGELOG.md not changed"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit fcca017

Please sign in to comment.