Merge pull request #246 from carlfriedrich/add-release-action

Automatic releases
This commit is contained in:
Wenxuan 2022-11-24 09:05:51 +08:00 committed by GitHub
commit a1d1d990ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 1 deletions

27
.github/scripts/changelog.sh vendored Executable file
View file

@ -0,0 +1,27 @@
#!/bin/bash
url=$(git remote get-url origin | sed -r 's/(.*)\.git/\1/')
previous_tag=$(git describe --tags --abbrev=0 HEAD~)
echo "Changes since $previous_tag:"
echo
# Loop through all commits since previous tag
for rev in $(git log $previous_tag..HEAD --format="%H" --reverse --no-merges)
do
summary=$(git log $rev~..$rev --format="%s")
# Exclude commits starting with "Meta"
if [[ $summary != Meta* ]]
then
# Print markdown list of commit headlines
echo "* [$summary]($url/commit/$rev)"
# Append commit body indented (blank lines and signoff trailer removed)
git log $rev~..$rev --format="%b" | sed '/^\s*$/d' | sed '/^Signed-off-by:/d' | \
while read -r line
do
# Escape markdown formatting symbols _ * `
echo " $line" | sed 's/_/\\_/g' | sed 's/`/\\`/g' | sed 's/\*/\\\*/g'
done
fi
done

18
.github/scripts/tag.sh vendored Executable file
View file

@ -0,0 +1,18 @@
#!/bin/bash
set -e
head_tag=$(git describe --exact-match 2>/dev/null | true)
if [[ ${head_tag} =~ [\d{2}.\d{2}.\d+] ]]
then
echo "Current master already has version tag ${head_tag}"
else
git config --local user.email "github-actions@users.noreply.github.com"
git config --local user.name "github-actions"
version=$(date +'%y.%m.0')
git tag -a ${version} -m "Release ${version}"
git push origin ${version}
echo "Pushed new tag:"
echo "${{github.server_url}}/${{github.repository}}/tag/${version}"
fi

View file

@ -4,7 +4,13 @@ name: ci
# Controls when the action will run. Triggers the workflow on push or pull request
# events, but only for the master branch
on: [push, pull_request]
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

29
.github/workflows/release.yaml vendored Normal file
View file

@ -0,0 +1,29 @@
name: Release
on:
push:
tags:
- '**'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Create Package
run: tar -czf forgit-${{github.ref_name}}.tar.gz --exclude LICENSE --exclude README.md *
- name: Generate Changelog
run: .github/scripts/changelog.sh > CHANGELOG.md
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: CHANGELOG.md
files: forgit-${{github.ref_name}}.tar.gz

20
.github/workflows/tag.yaml vendored Normal file
View file

@ -0,0 +1,20 @@
name: Tag
on:
schedule:
# Run on every first day of the month
- cron: '0 0 1 * *'
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Create Tag
run: .github/scripts/tag.sh