From eedf3ae89005752c97a53e920413a624fb103924 Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Wed, 16 Nov 2022 19:09:23 +0100 Subject: [PATCH 1/2] Meta: Add GitHub release action The action is executed on every tag and creates a GitHub release. The release contains a .tar.gz asset and a changelog consisting of all commit messages since the previous tag. Commits with a commit message starting with "Meta" are excluded from the changelog. --- .github/scripts/changelog.sh | 27 +++++++++++++++++++++++++++ .github/workflows/ci.yaml | 8 +++++++- .github/workflows/release.yaml | 29 +++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/changelog.sh create mode 100644 .github/workflows/release.yaml diff --git a/.github/scripts/changelog.sh b/.github/scripts/changelog.sh new file mode 100755 index 0000000..f8e80d6 --- /dev/null +++ b/.github/scripts/changelog.sh @@ -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 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 89e2795..d6914d8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..4c773ca --- /dev/null +++ b/.github/workflows/release.yaml @@ -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 From f0e9e4f7483dc34160753f4b1e195821d34912b7 Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Wed, 23 Nov 2022 18:13:28 +0100 Subject: [PATCH 2/2] Meta: Add GitHub tag action The action is executed on every first day of a month. It checks whether the current master is already tagged and, if not, creates a new release tag. --- .github/scripts/tag.sh | 18 ++++++++++++++++++ .github/workflows/tag.yaml | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 .github/scripts/tag.sh create mode 100644 .github/workflows/tag.yaml diff --git a/.github/scripts/tag.sh b/.github/scripts/tag.sh new file mode 100755 index 0000000..54ffdbc --- /dev/null +++ b/.github/scripts/tag.sh @@ -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 diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml new file mode 100644 index 0000000..6a5ba1b --- /dev/null +++ b/.github/workflows/tag.yaml @@ -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