Skip to content

Commit

Permalink
Test generating release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
araratthehero committed Nov 13, 2024
1 parent e5ef86d commit eb24cd4
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/.release_notes_allowed_labels_list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Breaking Changes,New,Fixed,Improved,Changed,Removed,Deprecated
95 changes: 95 additions & 0 deletions .github/workflows/generate_release_notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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

- 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
40 changes: 4 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
name: Release

# Every time we trigger the workflow on a branch.
on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: main

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: true

- name: Gradle build
run: ./gradlew build

- name: Set PROJECT_VERSION
run: |
chmod +x scripts/version_name.sh
PROJECT_VERSION=$(./scripts/version_name.sh)
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
echo "Variable PROJECT_VERSION set to: ${PROJECT_VERSION}"
- name: Create Github release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.PROJECT_VERSION }}
bodyFile: RELEASE_NOTES.md
draft: true
artifacts: "app/build/outputs/apk/release/app-release.apk"
generate_release_notes:
name: Generate release notes
uses: ./.github/workflows/generate_release_notes.yml

0 comments on commit eb24cd4

Please sign in to comment.