From 9ee40022342ea9cb0e489e5f7bd11423aaf3f0e5 Mon Sep 17 00:00:00 2001 From: Alex Guretzki Date: Fri, 31 Jan 2025 13:47:34 +0100 Subject: [PATCH] Release note workflow escaping (#1999) # Summary - Using escaping for release notes instead of a token - Improving output COIOS-000 --- .github/workflows/get_release_notes.yml | 39 +++++++++++++------------ .github/workflows/prepare_release.yml | 10 +++---- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/get_release_notes.yml b/.github/workflows/get_release_notes.yml index 57c5a4db52..ab0cd6348c 100644 --- a/.github/workflows/get_release_notes.yml +++ b/.github/workflows/get_release_notes.yml @@ -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> & + 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 }} diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml index 63fe5e0e45..f7084f3c02 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release.yml @@ -45,11 +45,11 @@ 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 @@ -57,7 +57,7 @@ jobs: 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 }}