Skip to content

Commit

Permalink
Add workflow and utilities for creating releases in GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
laurivan committed Apr 12, 2024
1 parent 59ea2cb commit a54f4a7
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/create-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

echo "GITHUB variables:"
for github_var in "${!GITHUB_@}"
do
[ "${github_var}" = "GITHUB_TOKEN" ] && continue
printf "%30s: '%s\n" "${github_var}" "${!github_var}"
done

if ! [ -f "lint-commit-msg" ]
then
echo "No such file: lint-commit-msg"
echo "Are you running the script in the repository root?"
exit 1
fi

version="${1:-${GITHUB_REF_NAME}}"
hash="${2:-${GITHUB_SHA}}"
hash="${hash:0:7}"

echo "Making release"
echo "version: '${version}'"
echo " hash: '${hash}'"

version_regex='^v[0-9]+[.][0-9]+[.][0-9]+$'
if ! [[ "${version}" =~ ${version_regex} ]]
then
echo "Invalid version: '${version}'"
exit 1
fi

hash_regex='^[a-f0-9]{7}$'
if ! [[ "${hash}" =~ ${hash_regex} ]]
then
echo "Invalid hash: '${hash}'"
exit 1
fi

mkdir -p build || exit 1
sed -E "s/^# lint-commit-msg @\{version information\} .*$/# lint-commit-msg ${version} (${hash})/" \
lint-commit-msg > build/lint-commit-msg


echo "Running 'gh release create'"
gh release create "${version}" \
--repo="${GITHUB_REPOSITORY}" \
--title="${GITHUB_REPOSITORY#*/} ${version#v}" \
--generate-notes \
build/lint-commit-msg
19 changes: 19 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: create-release

on:
push:
tags:
- v*

permissions:
contents: write

jobs:
release:
name: Create release upon tag creation
runs-on: ubuntu-22.04
steps:
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: .github/workflows/create-release.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
test/out
.DS_Store
build
2 changes: 2 additions & 0 deletions lint-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
# SOFTWARE.
#
#
# lint-commit-msg @{version information} (placeholder for making releases)
#
# TODO: allow the user to edit the message if it contains errors
# - note that this doesn't work if the input comes from stdin
# - text editor preference: GIT_EDITOR, VISUAL, EDITOR, vi (or nano)
# TODO: check for leading whitespace in the subject line

EXIT_CODE_LINTING_ERROR=1
EXIT_CODE_USER_ERROR=2
Expand Down

0 comments on commit a54f4a7

Please sign in to comment.