Skip to content

Commit 96d3833

Browse files
Merge pull request #5 from sifive/automate-release
Create GitHub Actions release automation
2 parents 3d667f2 + 2e11d39 commit 96d3833

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
on:
2+
push:
3+
# Require one of the following patterns to match the tag
4+
tags:
5+
- 'v[0-9]+.[0-9]+.[0-9]+.[0-9]+' # ex. v20.00.00.00
6+
- 'v[0-9]+.[0-9]+.RC.[0-9]+' # ex. v20.00.RC.00
7+
8+
name: Create Release
9+
10+
env:
11+
PROJECT_NAME: cmsis-svd-generator
12+
# Release is a prerelease if the tag contains rc
13+
PRERELEASE: ${{ contains(github.ref, 'RC') }}
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: 'Checkout'
21+
uses: actions/checkout@v2
22+
23+
# In order to generate release notes, we need a deep clone of the
24+
# repository so that we can find the most recent tag and generate
25+
# statistics based on it.
26+
- name: 'Fetch History'
27+
run: git fetch --prune --unshallow
28+
29+
- name: 'Create Release Notes'
30+
id: create-release-notes
31+
run: |
32+
tag=$(echo ${{ github.ref }} | cut -d '/' -f 3)
33+
release_notes=$(./scripts/create-release-notes.sh ${{ env.PROJECT_NAME }} ${tag})
34+
# The string passed to Actions must urlencode newlines.
35+
release_notes="${release_notes//$'\n'/'%0A'}"
36+
# Use a magic "workflow command" to set the output for the step.
37+
echo "::set-output name=release-notes::${release_notes}"
38+
39+
- name: 'Create Release'
40+
uses: actions/create-release@v1
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
tag_name: ${{ github.ref }}
45+
release_name: ${{ env.PROJECT_NAME }} ${{ github.ref }}
46+
body: ${{ steps.create-release-notes.outputs.release-notes }}
47+
draft: false
48+
prerelease: ${{ env.PRERELEASE }}

scripts/create-release-notes.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Copyright (c) 2020 SiFive Inc.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -euo pipefail
6+
7+
if [ "$#" -lt 2 ] ; then
8+
>&2 echo "$0: please provide project name and release tag"
9+
exit 1
10+
fi
11+
12+
project=$1; shift 1;
13+
current_release=$1; shift 1;
14+
15+
# Get the most recent previous tag with git-describe. If this is
16+
# the first tag in the repository, then this will return a commit
17+
# hash (because of the --always flag).
18+
last_release=$(git describe --tags --always HEAD~)
19+
20+
echo "# Release notes for ${project} ${current_release}"
21+
echo "## Statistics since ${last_release}"
22+
echo "- $(git rev-list --count ${last_release}..HEAD) commits"
23+
echo "-$(git diff --shortstat ${last_release} HEAD)"
24+
echo ""
25+
echo "## Authors"
26+
git shortlog -s -n --no-merges ${last_release}..HEAD | cut -f 2
27+
echo ""
28+
echo "## Merge history"
29+
git log --merges --pretty=format:"%h %b" ${last_release}..HEAD

0 commit comments

Comments
 (0)