Skip to content

Commit

Permalink
feat(changelog.sh): update to new changelog flags, update workflow an…
Browse files Browse the repository at this point in the history
…d ci.sh
  • Loading branch information
tcodes0 committed Aug 22, 2024
1 parent 6da622c commit d168888
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ run-name: release PR ${{ github.ref }}@${{ github.sha }}
on:
workflow_dispatch:
inputs:
module:
description: Module to release
url:
description: Github repository URL to point commit links at
required: true
type: string
title:
description: Release title; new version and date will be added
type: string
tag_prefix:
description: Prefix to be concatenated to semver tag, i.e ${PREFIX}v1.0.0
type: string

jobs:
release-pr:
Expand Down Expand Up @@ -35,15 +41,15 @@ jobs:
shell: bash
env:
CHANGELOG_FILE: CHANGELOG.md
run: ./workflows/release/changelog.sh ${{ inputs.module }}
run: ./workflows/release/changelog.sh ${{ inputs.url }} ${{ inputs.title }} ${{ inputs.tag_prefix }}

- name: Open PR
uses: peter-evans/[email protected]
with:
commit-message: "chore: release ${{ inputs.module }}"
title: "chore: release ${{ inputs.module }}"
commit-message: "chore: release ${{ inputs.title }}"
title: "chore: release ${{ inputs.title }}"
add-paths: .
body: ""
committer: release-workflow <41898282+github-actions[bot]@users.noreply.github.com>
branch: release-${{ inputs.module }}
branch: release-${{ inputs.title }}
branch-suffix: random
12 changes: 7 additions & 5 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Usage:
Wrapper around act that runs ci workflows and presents output in a friendly way
$0
run with github actions [event] and repo module [module]
run with github actions pull-request event
$0 push
send a push event
$0 dispatch pizza
run release-pr workflow with module=pizza
run release-pr workflow with tagprefix=pizza
EOF
}

Expand Down Expand Up @@ -94,14 +94,14 @@ validate() {
}

# Description: Initializes ci log and event json file
# Args : 1=github actions event, 2=module
# Args : 1=github actions event, 2=tagprefix
# STDOUT : event_type, log_file, event_json_file
# Returns : event_type, log_file, event_json_file
# Sideeffects: Makes 2 temporary log files
# Example : prepare_logs push pizza
prepare_logs() {
local gitLocalBranch prJson eventJson pushJson releasePrJson
local event="${1-}" module="${2-}" event_json_file ciLog eventType
local event="${1-}" tag_prefix="${2-}" event_json_file ciLog eventType

gitLocalBranch=$(git branch --show-current)
prJson="
Expand Down Expand Up @@ -129,7 +129,9 @@ prepare_logs() {
releasePrJson="
{
\"inputs\": {
\"module\": \"$module\"
\"tag_prefix\": \"$tag_prefix\",
\"title\": \"CI Release\",
\"url\": \"https://github.com/tcodes0/sh\"
},
\"local\": true
}
Expand Down
14 changes: 7 additions & 7 deletions workflows/release/changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# at https://opensource.org/license/BSD-3-clause.
#
# wrapper around changelog tool.
# Args: 1=module being released
# Args: 1=url 2=title 3=prefix

set -euo pipefail
shopt -s globstar
Expand All @@ -30,16 +30,18 @@ validate() {

# Description: Calls changelog tool and updates CHANGELOG_FILE
# Globals : CHANGELOG_FILE (github workflow or .env)
# Args : 1=module being released
# Args : 1=url 2=title 3=prefix
# STDERR : Might print errors
# Returns : 1 if fail
# Sideeffects: Updates CHANGELOG_FILE
# Example : update_changelog pizza
update_changelog() {
local module=$1 changes changelog flags=()
local url=$1 title=${2:-} prefix=${3:-} changes changelog flags=()

changelog=$(cat "$CHANGELOG_FILE")
flags+=(-module "$module")
flags+=(-title "$title")
flags+=(-tagprefix "$prefix")
flags+=(-url "$url")

changes=$(changelog "${flags[@]}")
if [ ! "$changes" ]; then
Expand All @@ -55,12 +57,10 @@ update_changelog() {
### script ###
##############

module=$1

if [ ! "${CHANGELOG_FILE-}" ]; then
# shellcheck source=../../.env
source .env
fi

validate
update_changelog "$module"
update_changelog "$@"

0 comments on commit d168888

Please sign in to comment.