-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move (Laerdal.Build.targets): move the file under Leardal.Scripts
- Loading branch information
1 parent
c8581b2
commit c1dbbde
Showing
7 changed files
with
442 additions
and
28 deletions.
There are no files selected for viewing
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/bin/bash | ||
|
||
usage(){ | ||
echo "usage: ./Laerdal.Changelog.sh [-nv | --new-version X.Y.Z] [-o | --output version.txt] [-h | --help]" | ||
echo "parameters:" | ||
echo " -nv | --new-version [version] New major.minor.patch version (default is 0.0.0)" | ||
echo " -o | --output [filename] Name of the output file" | ||
echo " -h | --help Prints this message" | ||
echo " -v | --verbose Verbose mode" | ||
} | ||
|
||
function log () { | ||
if [[ $verbose -eq 1 ]]; then | ||
echo "$@" | ||
fi | ||
} | ||
|
||
filename="CHANGELOG.md" | ||
|
||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-nv | --new-version ) shift | ||
newversion="$1" | ||
;; | ||
-o | --output ) shift | ||
filename="$1" | ||
;; | ||
-h | --help ) usage | ||
exit | ||
;; | ||
-v | --verbose ) verbose=1 | ||
;; | ||
* ) echo | ||
echo "### Wrong parameter: $1 ###" | ||
echo | ||
usage | ||
exit 1 | ||
esac | ||
shift | ||
done | ||
|
||
|
||
if [ ! -z "$newversion" ]; then | ||
if [[ "$newversion" =~ .*"-".* ]]; then | ||
log "New version contains a dash, skipping changelog generation" | ||
else | ||
currenthash=$(git show --format=%h --no-patch) | ||
echo "$currenthash $newversion" > tags.txt | ||
log "New version: $newversion" | ||
fi | ||
else | ||
echo "" > tags.txt | ||
fi | ||
|
||
# Get all tags on develop and Filter out tags that are not in the format "HASH 1.2.3" | ||
git tag --format='%(objectname:short) %(refname:short)' --sort=-version:refname --merged | grep -o '[a-z0-9]* [a-z0-9]*[.][a-z0-9]*[.][a-z0-9]*$' >> tags.txt | ||
|
||
# Create changelog file | ||
echo "# CHANGELOG" > "$filename" | ||
echo "" >> "$filename" | ||
log "Created changelog file: $filename" | ||
|
||
|
||
# Loop through all tags and create changelog | ||
lastline='' | ||
while read line; do | ||
if [ -z "$lastline" ]; then | ||
lastline=$line | ||
else | ||
# Split the line into hash and version | ||
lasthash=`echo $lastline | cut -d' ' -f1` | ||
lastversion=`echo $lastline | cut -d' ' -f2` | ||
hash=`echo $line | cut -d' ' -f1` | ||
|
||
echo "## **$lastversion**" >> "$filename" | ||
log "Added version: $lastversion" | ||
# Get the commit message and author of the tag | ||
git log -n 1 --pretty=tformat:"%b" $lasthash >> "$filename" | ||
|
||
echo "" >> "$filename" | ||
|
||
# Get all commits between the current tag and the previous tag | ||
git log $hash..$lasthash --pretty=format:"- %s [%cn]" --no-merges >> "$filename" | ||
|
||
echo "" >> "$filename" | ||
echo "" >> "$filename" | ||
|
||
# Get the commit message and author of the tag | ||
git log -n 1 --pretty=tformat:"> by _%cn_ on _%cd_" --date=format:'%Y-%m-%d %H:%M:%S' $lasthash >> "$filename" | ||
|
||
echo "" >> "$filename" | ||
echo "---" >> "$filename" | ||
echo "" >> "$filename" | ||
lastline=$line | ||
fi | ||
done < tags.txt | ||
|
||
rm -r -f tags.txt | ||
|
||
log "Done" | ||
|
||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
#!/bin/bash | ||
|
||
declare VERBOSE=0 | ||
declare TAG_VERSION="" | ||
|
||
declare GIT_BRANCH="" | ||
declare GITHUB_ACCESS_TOKEN="" | ||
declare GITHUB_REPOSITORY_PATH="" | ||
|
||
function parse_arguments() { | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
|
||
-v | --log) | ||
VERBOSE=1 | ||
shift | ||
;; | ||
|
||
-r | --repository-path) | ||
GITHUB_REPOSITORY_PATH="$2" | ||
shift | ||
;; | ||
|
||
-t | --tag-version) | ||
TAG_VERSION="$2" | ||
shift | ||
;; | ||
|
||
-b | --git-branch) | ||
GIT_BRANCH="$2" | ||
shift | ||
;; | ||
|
||
-a | --access-token) | ||
GITHUB_ACCESS_TOKEN="$2" | ||
shift | ||
;; | ||
|
||
*) | ||
echo "Unknown option: $1" | ||
usage | ||
exit 1 | ||
;; | ||
|
||
esac | ||
shift | ||
done | ||
|
||
if [[ -z $GIT_BRANCH ]]; then | ||
echo "Missing git-branch." | ||
usage | ||
exit 1 | ||
fi | ||
|
||
if [[ -z $GITHUB_REPOSITORY_PATH ]]; then | ||
echo "Missing github-repository." | ||
usage | ||
exit 1 | ||
fi | ||
|
||
if [[ -z $GITHUB_ACCESS_TOKEN ]]; then | ||
echo "Missing github-access-token." | ||
usage | ||
exit 1 | ||
fi | ||
|
||
validate_tag_format "$TAG_VERSION" | ||
} | ||
|
||
function validate_tag_format() { | ||
local -r tag="$1" | ||
local -r pattern='^[0-9]+\.[0-9]+(\.[0-9]+)?$' | ||
|
||
if ! [[ $tag =~ $pattern ]]; then | ||
exit_with_error "Tag format is invalid: '$tag'" | ||
fi | ||
} | ||
|
||
function usage() { | ||
local -r script_name=$(basename "$0") | ||
|
||
echo "Usage: $script_name [--verbose|-v] [--repository-path|-r]=<repository_path> [--git-branch|-b]=<branch> [--access-token|-a]=<token> [--tag-version|-t]=<version>" | ||
} | ||
|
||
function create_release_on_github() { | ||
# https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release | ||
|
||
local eventual_tag_name="" | ||
local eventual_singleline_summary="" | ||
if [[ $GIT_BRANCH == "refs/heads/main" || $GIT_BRANCH == "refs/heads/master" ]]; then | ||
eventual_tag_name="v$TAG_VERSION" # builds targeting main have this simple and straightforward tag name | ||
eventual_singleline_summary="Release $eventual_tag_name" | ||
|
||
elif [[ $GIT_BRANCH == "refs/heads/develop" ]]; then # all builds that target develop are beta builds | ||
eventual_tag_name="v$TAG_VERSION-beta" | ||
eventual_singleline_summary="Beta $eventual_tag_name" | ||
|
||
else # all other builds that dont target main are alpha builds should rarely happen in practice but just in case | ||
eventual_tag_name="v$TAG_VERSION-alpha" | ||
eventual_singleline_summary="Alpha $eventual_tag_name" | ||
fi | ||
|
||
local -r payload=$( | ||
cat <<EOF | ||
{ | ||
"tag_name": "$eventual_tag_name", | ||
"target_commitish": "$GIT_BRANCH", | ||
"name": "$eventual_singleline_summary", | ||
"generate_release_notes": true, | ||
"draft": false, | ||
"prerelease": false | ||
} | ||
EOF | ||
) | ||
|
||
local -r api_url="https://api.github.com/repos/$GITHUB_REPOSITORY_PATH/releases" | ||
|
||
echo "** Creating release on GitHub ..." | ||
|
||
local -r response=$( | ||
curl \ | ||
-i \ | ||
-sS \ | ||
-X "POST" \ | ||
-o /dev/null \ | ||
-d "$payload" \ | ||
-w "%{http_code}" \ | ||
-H "Content-Type:application/json" \ | ||
-H "Accept:application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \ | ||
"$api_url" | ||
) | ||
local -r curl_exit_code=$? | ||
|
||
log "** api_url=$api_url" | ||
log "** payload=$payload" | ||
log "** response=$response" | ||
log "** curl_exit_code=$curl_exit_code" | ||
if [[ $curl_exit_code -ne 0 ]]; then | ||
exit_with_error "curl failed with exit code $?" | ||
fi | ||
|
||
local -r http_status_code="${response}" | ||
if [[ $http_status_code -ge 300 ]]; then | ||
exit_with_error "API returned HTTP status $http_status_code" | ||
fi | ||
} | ||
|
||
function log() { | ||
if [[ $VERBOSE -ne 0 ]]; then | ||
echo "$@" | ||
fi | ||
} | ||
|
||
function exit_with_error() { | ||
echo "Error: $1" | ||
exit 1 | ||
} | ||
|
||
function main() { | ||
parse_arguments "$@" | ||
create_release_on_github | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.