Skip to content

Commit 4168ff1

Browse files
authored
Add username for draft process (#913)
Upgrade the release plugin
1 parent e0718de commit 4168ff1

File tree

2 files changed

+60
-49
lines changed

2 files changed

+60
-49
lines changed

.github/actions/gitlog/gitlog.sh

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,96 @@
55
output_file=""
66
crate=""
77
while true; do
8-
case $1 in
9-
"--output-file")
10-
shift
11-
output_file="$1"
12-
shift
13-
;;
14-
"--crate")
15-
shift
16-
crate="$1"
17-
shift
18-
;;
19-
*)
20-
break
21-
;;
22-
esac
8+
case $1 in
9+
"--output-file")
10+
shift
11+
output_file="$1"
12+
shift
13+
;;
14+
"--crate")
15+
shift
16+
crate="$1"
17+
shift
18+
;;
19+
*)
20+
break
21+
;;
22+
esac
2323
done
2424

2525
if [[ "$output_file" == "" ]]; then
26-
echo "Missing --output-file <file> option argument, define path to file or - for stdout" && exit 1
26+
echo "Missing --output-file <file> option argument, define path to file or - for stdout" && exit 1
2727
fi
2828
if [[ "$crate" == "" ]]; then
29-
echo "Missing --crate <crate> option argument, need an explisit crate to get git log for" && exit 1
29+
echo "Missing --crate <crate> option argument, need an explisit crate to get git log for" && exit 1
3030
fi
3131

3232
from_commit=HEAD
3333
last_release=$(git tag --sort=-committerdate | grep -E "$crate-[0-9]*\.[0-9]*\.[0-9]*" | head -1)
3434
echo "Found tag: $last_release"
3535
if [[ "$last_release" == "" ]]; then
36-
last_release=$(git tag --sort=-committerdate | head -1) # get last tag
37-
echo "Using latest tag: $last_release"
36+
last_release=$(git tag --sort=-committerdate | head -1) # get last tag
37+
echo "Using latest tag: $last_release"
3838
fi
3939

4040
commit_range=""
4141
if [[ $last_release != "" ]]; then
42-
commit_range="$from_commit...$last_release"
42+
commit_range="$from_commit...$last_release"
4343
else
44-
commit_range="$from_commit"
44+
commit_range="$from_commit"
4545
fi
4646

4747
ancestry_path=""
4848
if [[ "$last_release" != "" ]]; then
49-
ancestry_path="--ancestry-path"
49+
ancestry_path="--ancestry-path"
5050
fi
5151

52-
mapfile -t log_lines < <(git log --pretty=format:'(%h) %s' $ancestry_path $commit_range)
52+
mapfile -t log_lines < <(git log --pretty=format:'(%h) %s' $ancestry_path "$commit_range")
5353

5454
function is_crate_related {
55-
commit="$1"
56-
changes="$(git diff --name-only "$commit"~ "$commit" | awk -F / '{print $1}' | xargs)"
57-
58-
is_related=false
59-
if [[ "$changes" == *"$crate"* ]]; then
60-
is_related=true
61-
fi
62-
63-
echo $is_related
55+
commit="$1"
56+
changes="$(git diff --name-only "$commit"~ "$commit" | awk -F / '{print $1}' | xargs)"
57+
58+
is_related=false
59+
if [[ "$changes" == *"$crate"* ]]; then
60+
is_related=true
61+
fi
62+
63+
echo $is_related
64+
}
65+
66+
get_username() {
67+
commit=$1
68+
curl -sSL \
69+
-H "Accept: application/vnd.github+json" \
70+
-H "X-GitHub-Api-Version: 2022-11-28" \
71+
https://api.github.com/repos/juhaku/utoipa/commits/"$commit" | jq -r .author.login
6472
}
6573

6674
log=""
6775
for line in "${log_lines[@]}"; do
68-
commit=$(echo "$line" | awk -F ' ' '{print $1}')
69-
commit=${commit//[\(\)]/}
70-
71-
if [[ $(is_crate_related "$commit") == true ]]; then
72-
log=$log"* $line\n"
73-
fi
76+
commit=$(echo "$line" | awk -F ' ' '{print $1}')
77+
commit=${commit//[\(\)]/}
78+
79+
if [[ $(is_crate_related "$commit") == true ]]; then
80+
user=$(get_username "$commit")
81+
log=$log"* $line @$user\n"
82+
fi
7483
done
7584

7685
if [[ "$output_file" != "" ]]; then
77-
if [[ "$output_file" == "-" ]]; then
78-
echo -e "$log"
79-
else
80-
echo -e "$log" > "$output_file"
81-
fi
86+
if [[ "$output_file" == "-" ]]; then
87+
echo -e "$log"
88+
else
89+
echo -e "$log" >"$output_file"
90+
fi
8291
fi
8392

8493
if [[ "$last_release" == "" ]]; then
85-
last_release=$(git rev-list --reverse HEAD | head -1)
94+
last_release=$(git rev-list --reverse HEAD | head -1)
95+
fi
96+
97+
if [ -n "$GITHUB_OUTPUT" ]; then
98+
echo "last_release=$last_release" >>"$GITHUB_OUTPUT"
8699
fi
87-
echo "::set-output name=last_release::$last_release"
100+

.github/workflows/draft.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ jobs:
7474
- name: Create release
7575
id: create_release
7676
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
77-
uses: actions/create-release@v1
78-
env:
79-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
uses: softprops/[email protected]
8078
with:
8179
tag_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
82-
release_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
80+
name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
8381
body_path: ./draft-changes.md
8482
draft: true
8583
prerelease: ${{ steps.release_info.outputs.is_prerelease }}

0 commit comments

Comments
 (0)