Skip to content

Test generating release notes #1

Test generating release notes

Test generating release notes #1

name: Generate release notes
# Start this workflow when a release branch is created
on:
workflow_call:
jobs:
get_allowed_labels:
runs-on: ubuntu-latest
outputs:
allowed_labels: ${{ steps.get_allowed_labels.outputs.ALLOWED_LABELS }}
steps:
- uses: actions/checkout@v4
- name: Get the list of allowed pull request labels
id: get_allowed_labels
run: |
RED='\033[0;31m'
FILE_NAME=.release_notes_allowed_labels_list
GITHUB_DIR=.github
FILE_PATH=$PROJECT_ROOT/$GITHUB_DIR/$FILE_NAME
if [[ ! -f "$FILE_PATH" ]]; then
echo -e "${RED}$FILE_NAME file doesn't exits in $GITHUB_DIR/"
exit 1
fi
ALLOWED_LABELS=$(cat $FILE_PATH)
echo "allowed_labels=$ALLOWED_LABELS" >> $GITHUB_OUTPUT
echo "Allowed labels are: $ALLOWED_LABELS"
env:
PROJECT_ROOT: ${{ github.workspace }}
generate_release_notes:
runs-on: ubuntu-latest
needs: get_allowed_labels
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

Check failure on line 42 in .github/workflows/generate_release_notes.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/generate_release_notes.yml

Invalid workflow file

You have an error in your yaml syntax on line 42
- name: Generate release notes
env:
ALLOWED_LABELS: ${{ needs.get_allowed_labels.outputs.allowed_labels }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_OWNER: "Adyen"
GITHUB_REPO: "adyen-android"
run: |
#
# Fetch recent commits since the last release tag
LATEST_TAG=$(git describe --tags --abbrev=0)
COMMITS=$(git log --oneline "$LATEST_TAG"..HEAD)
# Define allowed labels
IFS=',' read -r -a ALLOWED_LABELS_ARRAY <<< "$ALLOWED_LABELS"
# Initialize the output variable
OUTPUT=""
# Iterate over each commit to find PR numbers
while IFS= read -r COMMIT; do
# Check for "Merge pull request #xxxx" format in commit messages
if [[ $COMMIT =~ Merge\ pull\ request\ \#([0-9]+) ]]; then
PR_NUMBER="${BASH_REMATCH[1]}"
echo "Processing PR #$PR_NUMBER"
# Fetch PR details using the GitHub API
PR_RESPONSE=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/pulls/$PR_NUMBER")
# Extract the PR body
PR_BODY=$(echo "$PR_RESPONSE" | jq -r '.body')
# Loop over allowed labels to check for headers in the PR body
for LABEL in "${ALLOWED_LABELS_ARRAY[@]}"; do
HEADER="### $LABEL"
# Extract the content under each label header, if present
LABEL_CONTENT=$(echo "$PR_BODY" | awk "/^$HEADER/,/^### /" | grep -v "^### ")
# If there's content under this label, format and add it to OUTPUT
if [ ! -z "$LABEL_CONTENT" ]; then
OUTPUT="${OUTPUT}\n$HEADER\n$LABEL_CONTENT\n"
fi
done
fi
done <<< "$COMMITS"
# Print and save the output if it's not empty
if [ ! -z "$OUTPUT" ]; then
IFS="" echo "$OUTPUT"
IFS="" echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY
fi