-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Git log | ||
description: Mangles git log for change log | ||
inputs: | ||
output-file: | ||
description: File path where to place the content of the changed commits | ||
required: true | ||
crate: | ||
description: Name of the crate to get git log for | ||
required: true | ||
outputs: | ||
last_release: | ||
description: Last release commit or first commit of history | ||
value: ${{ steps.gitlog.outputs.last_release }} | ||
runs: | ||
using: composite | ||
steps: | ||
- shell: bash | ||
id: gitlog | ||
run: | | ||
${{ github.action_path }}/gitlog.sh --output-file ${{ inputs.output-file }} --crate ${{ inputs.crate }} |
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,87 @@ | ||
#!/bin/bash | ||
|
||
# This mangles git log entries for change lop purposes | ||
|
||
output_file="" | ||
crate="" | ||
while true; do | ||
case $1 in | ||
"--output-file") | ||
shift | ||
output_file="$1" | ||
shift | ||
;; | ||
"--crate") | ||
shift | ||
crate="$1" | ||
shift | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
if [[ "$output_file" == "" ]]; then | ||
echo "Missing --output-file <file> option argument, define path to file or - for stdout" && exit 1 | ||
fi | ||
if [[ "$crate" == "" ]]; then | ||
echo "Missing --crate <crate> option argument, need an explisit crate to get git log for" && exit 1 | ||
fi | ||
|
||
from_commit=HEAD | ||
last_release=$(git tag --sort=-committerdate | grep -E "$crate-[0-9]*\.[0-9]*\.[0-9]*" | head -1) | ||
echo "Found tag: $last_release" | ||
if [[ "$last_release" == "" ]]; then | ||
last_release=$(git tag --sort=-committerdate | head -1) # get last tag | ||
echo "Using latest tag: $last_release" | ||
fi | ||
|
||
commit_range="" | ||
if [[ $last_release != "" ]]; then | ||
commit_range="$from_commit...$last_release" | ||
else | ||
commit_range="$from_commit" | ||
fi | ||
|
||
ancestry_path="" | ||
if [[ "$last_release" != "" ]]; then | ||
ancestry_path="--ancestry-path" | ||
fi | ||
|
||
mapfile -t log_lines < <(git log --pretty=format:'(%h) %s' $ancestry_path $commit_range) | ||
|
||
function is_crate_related { | ||
commit="$1" | ||
changes="$(git diff --name-only "$commit"~ "$commit" | awk -F / '{print $1}' | xargs)" | ||
|
||
is_related=false | ||
if [[ "$changes" == *"$crate"* ]]; then | ||
is_related=true | ||
fi | ||
|
||
echo $is_related | ||
} | ||
|
||
log="" | ||
for line in "${log_lines[@]}"; do | ||
commit=$(echo "$line" | awk -F ' ' '{print $1}') | ||
commit=${commit//[\(\)]/} | ||
|
||
if [[ $(is_crate_related "$commit") == true ]]; then | ||
log=$log"* $line\n" | ||
fi | ||
done | ||
|
||
if [[ "$output_file" != "" ]]; then | ||
if [[ "$output_file" == "-" ]]; then | ||
echo -e "$log" | ||
else | ||
echo -e "$log" > "$output_file" | ||
fi | ||
fi | ||
|
||
if [[ "$last_release" == "" ]]; then | ||
last_release=$(git rev-list --reverse HEAD | head -1) | ||
fi | ||
echo "::set-output name=last_release::$last_release" |