Skip to content

Commit 62fdae9

Browse files
ewelsjustinegeffen
andauthored
Make changelog (#254)
* Initial version of bash script for creating changelog entries * Make the script beautiful using 'gum' * Increase limit to avoid pagination * Cleanup * MD not MDX, MultiQC not Multiqc --------- Co-authored-by: Justine Geffen <justinegeffen@users.noreply.github.com>
1 parent 6b7e0f3 commit 62fdae9

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

make_changelog.sh

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
3+
# Check if gum is installed
4+
if ! command -v gum &> /dev/null
5+
then
6+
echo "Error: 'gum' command not found. Please install it using 'brew install gum'."
7+
exit 1
8+
fi
9+
10+
# Prompt for repository if not supplied as an argument
11+
if [ -z "$1" ]; then
12+
REPO=$(gum choose \
13+
"nextflow-io/nextflow" \
14+
"MultiQC/MultiQC" \
15+
"seqeralabs/fusion" \
16+
"seqeralabs/wave" \
17+
"seqeralabs/platform" \
18+
"[ other ]")
19+
20+
# Set the corresponding product name and colour based on the repository selected
21+
case "$REPO" in
22+
"nextflow-io/nextflow")
23+
product="nextflow"
24+
COLOR="32" # Green
25+
;;
26+
"MultiQC/MultiQC")
27+
product="multiqc"
28+
COLOR="214" # Orange
29+
;;
30+
"seqeralabs/fusion")
31+
product="fusion"
32+
COLOR="196" # Red
33+
;;
34+
"seqeralabs/wave")
35+
product="wave"
36+
COLOR="33" # Blue
37+
;;
38+
"seqeralabs/platform")
39+
# We will handle the conditional product in the loop for this case
40+
COLOR="93" # Purple
41+
;;
42+
"[ other ]")
43+
# If "other" is selected, prompt for both repository and product name
44+
REPO=$(gum input --placeholder "Enter repository name (e.g., org/repo)")
45+
product=$(gum input --placeholder "Enter name for filenames and tags array (e.g., custom-name)")
46+
COLOR="240" # Default grey
47+
;;
48+
esac
49+
else
50+
REPO=$1
51+
if [ -z "$2" ]; then
52+
product=$(gum input --placeholder "Enter name for filenames and tags array (e.g., fusion)")
53+
COLOR="240" # Default grey
54+
else
55+
product=$2
56+
COLOR="240" # Default grey
57+
fi
58+
fi
59+
60+
# Prompt for whether to fetch all releases or stop at the first existing file
61+
FETCH_ALL=$(gum choose "Just new until an existing entry found" "All releases")
62+
63+
# Fetch the releases, sort them by publishedAt in descending order
64+
gh -R "$REPO" release list --json tagName,publishedAt --limit 1000 | jq -r 'sort_by(.publishedAt) | reverse | .[] | "\(.tagName) \(.publishedAt)"' | while read tag publishedAt; do
65+
# Skip any release with "nightly" in the tagName
66+
if [[ "$tag" == *"nightly"* ]]; then
67+
gum style --foreground "240" "Skipping nightly release: $tag"
68+
continue
69+
fi
70+
71+
# Format the date to yyyy-mm-dd
72+
date=$(echo $publishedAt | cut -d'T' -f1)
73+
74+
# Set the appropriate product based on conditions
75+
if [[ "$REPO" == "seqeralabs/platform" ]]; then
76+
if [[ "$tag" == *"enterprise"* ]]; then
77+
product="seqera-enterprise"
78+
else
79+
product="seqera-cloud"
80+
fi
81+
fi
82+
83+
# Capitalize the first letter of the product
84+
capitalized_product=$(echo "$product" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
85+
if [[ "$capitalized_product" == "Multiqc" ]]; then
86+
capitalized_product="MultiQC"
87+
fi
88+
89+
# Create a file in changelog/{product} directory with the name {tagName}.md
90+
filename="changelog/${product}/${tag}.md"
91+
92+
# Check if the file already exists
93+
if [ -f "$filename" ]; then
94+
# If the option is to stop at the first existing file, break the loop
95+
if [ "$FETCH_ALL" == "Just new until an existing entry found" ]; then
96+
gum style --foreground "240" "Stopping: Found existing file: $filename"
97+
break
98+
fi
99+
else
100+
# Fetch the body (release notes) for the current tag
101+
body=$(gh -R "$REPO" release view "$tag" --json body -q '.body')
102+
103+
# Write the content to the file
104+
cat <<EOF > "$filename"
105+
---
106+
title: ${capitalized_product} ${tag}
107+
date: ${date}
108+
tags: [${product}]
109+
---
110+
111+
${body}
112+
EOF
113+
114+
# Output nice feedback with gum, using single-line style and colour coding
115+
gum style --foreground "$COLOR" "Created file: $filename"
116+
fi
117+
done

0 commit comments

Comments
 (0)