|
| 1 | +#!/bin/bash |
| 2 | +# To run: chmod +x fetch-versioned-release-notes.sh && ./fetch-versioned-release-notes.sh |
| 3 | +# Dokumentation https://wiki.gecko.hs-heilbronn.de/doc/dokumentation-release-notes-script-45Ex3hoxjB |
| 4 | + |
| 5 | +# GitHub repository details |
| 6 | +REPO_OWNER="datasharingframework" |
| 7 | +REPO_NAME="dsf" |
| 8 | + |
| 9 | +# Output base directory (this will hold the versioned folders) |
| 10 | +OUTPUT_BASE_DIR="../../operations" |
| 11 | + |
| 12 | +# Define the range of versions |
| 13 | +VERSIONS=("v1.0.0" "v1.1.0" "v1.2.0" "v1.3.0" "v1.3.1" "v1.3.2" "v1.4.0" "v1.5.0" "v1.5.1" "v1.5.2" "v1.6.0" "v1.7.0" "v1.7.1" "v1.8.0") |
| 14 | + |
| 15 | +# Fetch all release details |
| 16 | +echo "Fetching all releases..." |
| 17 | +RELEASES=$(curl -s https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases) |
| 18 | + |
| 19 | +# Loop through each version in the version list |
| 20 | +for VERSION in "${VERSIONS[@]}"; do |
| 21 | + VERSION_FOUND=$(echo "$RELEASES" | jq -r ".[] | select(.tag_name == \"$VERSION\")") |
| 22 | + |
| 23 | + if [ ! -z "$VERSION_FOUND" ]; then |
| 24 | + VERSION_DIR="$OUTPUT_BASE_DIR/$VERSION" |
| 25 | + |
| 26 | + if [ ! -d "$VERSION_DIR" ]; then |
| 27 | + echo "Directory $VERSION_DIR does not exist. Skipping $VERSION." |
| 28 | + continue |
| 29 | + fi |
| 30 | + |
| 31 | + OUTPUT_FILE="$VERSION_DIR/release-notes.md" |
| 32 | + |
| 33 | + |
| 34 | +# Write frontmatter at the top of the Markdown file |
| 35 | +cat <<EOF > "$OUTPUT_FILE" |
| 36 | +--- |
| 37 | +title: Release Notes ($VERSION) |
| 38 | +icon: note |
| 39 | +--- |
| 40 | +
|
| 41 | +## [Release Notes for $VERSION](https://github.com/$REPO_OWNER/$REPO_NAME/releases/tag/$VERSION) |
| 42 | +
|
| 43 | +::: tip Release Notes |
| 44 | +You can access all release notes on our [GitHub](https://github.com/datasharingframework/dsf/releases). |
| 45 | +::: |
| 46 | +
|
| 47 | +EOF |
| 48 | + |
| 49 | + echo "$RELEASES" | jq -r ".[] | select(.tag_name == \"$VERSION\") | @base64" | while read -r RELEASE; do |
| 50 | + RELEASE_JSON=$(echo "$RELEASE" | base64 --decode) |
| 51 | + RELEASE_BODY=$(echo "$RELEASE_JSON" | jq -r '.body') |
| 52 | + RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.name') |
| 53 | + |
| 54 | + # Convert #issue_number to GitHub issue link |
| 55 | + RELEASE_BODY=$(echo "$RELEASE_BODY" | sed -E 's/#([0-9]+)/[#\1](https:\/\/github.com\/datasharingframework\/dsf\/issues\/\1)/g') |
| 56 | + |
| 57 | + # Convert @username to GitHub user link |
| 58 | + RELEASE_BODY=$(echo "$RELEASE_BODY" | sed -E 's/@([a-zA-Z0-9_-]+)/[@\1](https:\/\/github.com\/\1)/g') |
| 59 | + |
| 60 | + |
| 61 | + echo "### $RELEASE_NAME" >> "$OUTPUT_FILE" |
| 62 | + echo "$RELEASE_BODY" >> "$OUTPUT_FILE" |
| 63 | + |
| 64 | + echo "" >> "$OUTPUT_FILE" |
| 65 | + done |
| 66 | + |
| 67 | + echo "Release notes for version $VERSION saved to $OUTPUT_FILE" |
| 68 | + else |
| 69 | + echo "No release found for version $VERSION" |
| 70 | + fi |
| 71 | +done |
| 72 | + |
| 73 | +echo "Process completed." |
0 commit comments