Skip to content

Commit

Permalink
Release note workflow escaping (#1999)
Browse files Browse the repository at this point in the history
# Summary
- Using escaping for release notes instead of a token
- Improving output

<ticket>COIOS-000</ticket>
  • Loading branch information
goergisn authored Jan 31, 2025
1 parent 034e498 commit 9ee4002
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
39 changes: 20 additions & 19 deletions .github/workflows/get_release_notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,38 @@ jobs:
- name: Generate release notes
id: generate-release-notes
run: |
# Get the latest tag
LATEST_TAG=$(git describe --tags --abbrev=0)
NUMBER_OF_COMMITS_SINCE_LAST_RELEASE=$(git log --oneline $LATEST_TAG..HEAD | wc -l | sed 's/^ *//g' | sed 's/ *$//g')
# Get the commit messages since the latest tag
COMMITS=$(git log "$LATEST_TAG"..HEAD)
# Convert the labels string to an array
IFS=',' read -r -a ALLOWED_LABELS_ARRAY <<< "$ALLOWED_LABELS"
OUTPUT=""
# Loop through each label and find matching commits
for LABEL in "${ALLOWED_LABELS_ARRAY[@]}"; do
LABEL=$(echo "$LABEL" | sed 's/^ *//g' | sed 's/ *$//g')
GIT_LOG_CMD="git log -$NUMBER_OF_COMMITS_SINCE_LAST_RELEASE"
FIND_CMD="awk '/<$LABEL>/,/<\/$LABEL>/'"
LABEL_OUTPUT="$(eval "$GIT_LOG_CMD | $FIND_CMD")"
if [ ! -z "$LABEL_OUTPUT" ]; then
LABEL_CONTENT="
LABEL=$(echo "$LABEL" | xargs) # Trim spaces
# Finding content inside of <$LABEL> & </$LABEL> + trimming leading/trailling spaces/newlines
LABEL_OUTPUT=$(echo "$COMMITS" | awk "/<$LABEL>/,/<\/$LABEL>/" | sed "s/<$LABEL>//g; s/<\/$LABEL>//g" | xargs)
if [ -n "$LABEL_OUTPUT" ]; then
OUTPUT="$OUTPUT
## $LABEL
$LABEL_OUTPUT"
REMOVE_TAG_CMD="sed 's/<$LABEL>//g' | sed 's/<\/$LABEL>//g'"
OUTPUT=$(echo "$OUTPUT
$LABEL_CONTENT" | eval $REMOVE_TAG_CMD)
fi
fi
done
if [ ! -z "$OUTPUT" ]; then
IFS="" echo "$OUTPUT"
IFS="" echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY
SANITIZED_OUTPUT=$(echo "$OUTPUT" | sed 'H;1h;$!d;x;s/\n/NEW_LINE_TOKEN/g' )
echo "Sanitized Output: $SANITIZED_OUTPUT"
IFS="" echo "RELEASE_NOTES=$SANITIZED_OUTPUT" >> $GITHUB_OUTPUT
# Converting the output to Base64 to get a single line required by the GITHUB_OUTPUT
BASE64_RELEASE_NOTES=$(echo "$OUTPUT" | base64)
echo "Base64 Release Notes: $BASE64_RELEASE_NOTES"
IFS="" echo "RELEASE_NOTES=$BASE64_RELEASE_NOTES" >> $GITHUB_OUTPUT
fi
env:
ALLOWED_LABELS: ${{ steps.get-allowed_labels.outputs.LABELS }}
10 changes: 5 additions & 5 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ jobs:
# Sanitizing the Release Notes from the get-release-notes job
- name: Prepare Release Notes
run: |
SANITIZED_RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed 'H;1h;$!d;x;s/NEW_LINE_TOKEN/\n/g' )
echo "# Changes since last release
$SANITIZED_RELEASE_NOTES" >> "${{ github.workspace }}/release_notes.md"
RELEASE_NOTES=$(echo "$BASE_64_RELEASE_NOTES" | base64 --decode)
rm -rf "${{ github.workspace }}/release_notes.md" # Making sure we start a fresh document
echo "$RELEASE_NOTES" >> "${{ github.workspace }}/release_notes.md"
env:
RELEASE_NOTES: ${{ needs.get-release-notes.outputs.RELEASE_NOTES }}
BASE_64_RELEASE_NOTES: ${{ needs.get-release-notes.outputs.RELEASE_NOTES }}

# Creates a release/[sdk-version] branch with a PR to develop
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
delete-branch: true
branch: "release/${{ github.event.inputs.sdk-version }}"
commit-message: "chore: updating documentation"
commit-message: "chore: prepare '${{ github.event.inputs.sdk-version }}' release"
title: "[Release] ${{ github.event.inputs.sdk-version }}"
body-path: "${{ github.workspace }}/release_notes.md"
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 9ee4002

Please sign in to comment.