Create Release Notes after CI #87
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: Create Release Notes after CI | |
# Controls when the workflow will run | |
on: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
microservice: | |
required: true | |
type: string | |
description: Name of Microservice | |
default: apple | |
env: | |
RELEASE_NOTES_FILE: RELEASELOG.md | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v3 | |
- name: Set version tag | |
id: set-version | |
run: | | |
BUILD_VERSION=v$(date '+%Y%m%d%H%M') | |
MICROSERVICE=${MICROSERVICE:=apple} | |
echo "microservice=$MICROSERVICE" >> $GITHUB_OUTPUT | |
echo "curr-release-tag=$MICROSERVICE/$BUILD_VERSION" >> $GITHUB_OUTPUT | |
echo "curr-release-title=$MICROSERVICE: $BUILD_VERSION" >> $GITHUB_OUTPUT | |
PREV_RELEASE_TAG=$(gh release list | grep -m1 "$MICROSERVICE/*" | cut -f3) | |
if [ -z "$PREV_RELEASE_TAG" ]; then | |
PREV_RELEASE_TAG=$(gh release list | head -n 1 | cut -f3) | |
fi | |
echo "prev-release-tag=$PREV_RELEASE_TAG" >> $GITHUB_OUTPUT | |
env: | |
GH_TOKEN: ${{ github.token }} | |
MICROSERVICE: ${{ inputs.microservice }} | |
- name: Write a release log | |
uses: cuchi/jinja2-action@v1.2.0 | |
with: | |
template: ${{ env.RELEASE_NOTES_FILE }} | |
output_file: ${{ env.RELEASE_NOTES_FILE }} | |
env: | |
# GITHUB_REPOSITORY: ${GITHUB_REPOSITORY} | |
PREV_RELEASE_TAG: ${{ steps.set-version.outputs.prev-release-tag }} | |
CURR_RELEASE_TAG: ${{ steps.set-version.outputs.curr-release-tag }} | |
- name: Get commit history | |
run: | | |
json_data=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${GITHUB_REPOSITORY}/compare/${{ env.BASEHEAD }}) | |
# Print the Markdown table header | |
echo "| Author | Date | Commit Message |" >> ${{ env.RELEASE_NOTES_FILE }} | |
echo "|--------|------|----------------|" >> ${{ env.RELEASE_NOTES_FILE }} | |
# Use jq to extract the commits as raw JSON lines | |
jq -c '.commits[]' <<< "$json_data" | while read -r commit; do | |
# Extract the author's login, commit date, and commit message | |
author_login=$(echo "$commit" | jq -r '.author.login') | |
commit_date=$(echo "$commit" | jq -r '.commit.author.date') | |
commit_message=$(echo "$commit" | jq -r '.commit.message' | head -n 1) | |
# Print the values as a Markdown table row | |
echo "| @$author_login | $commit_date | $commit_message |" >> ${{ env.RELEASE_NOTES_FILE }} | |
done | |
env: | |
GH_TOKEN: ${{ github.token }} | |
BASEHEAD: ${{ steps.set-version.outputs.prev-release-tag }}...${{ github.sha }} | |
- name: Publish a release note | |
run: | | |
gh release create "${{ env.CURR_RELEASE_TAG }}" \ | |
--title "${{ env.CURR_RELEASE_TITLE }}" \ | |
--target ${{ env.COMMIT_SHA }} \ | |
--notes-start-tag "${{ env.PREV_RELEASE_TAG }}" \ | |
--generate-notes \ | |
--notes-file ${{ env.RELEASE_NOTES_FILE }} | |
env: | |
GH_TOKEN: ${{ github.token }} | |
MICROSERVICE: ${{ steps.set-version.outputs.microservice }} | |
PREV_RELEASE_TAG: ${{ steps.set-version.outputs.prev-release-tag }} | |
CURR_RELEASE_TAG: ${{ steps.set-version.outputs.curr-release-tag }} | |
CURR_RELEASE_TITLE: ${{ steps.set-version.outputs.curr-release-title }} | |
COMMIT_SHA: ${{ github.sha }} |