Implement refund processing for expired orders #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Release | |
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- stable | |
workflow_dispatch: | |
# Add permissions block | |
permissions: | |
contents: write # Required for creating releases | |
packages: write # Required if you're also publishing packages | |
pull-requests: read # Added to read PR information | |
jobs: | |
create-release: | |
# Only run if PR is merged (not just closed) OR if manually triggered | |
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
# Try to get the latest tag, if none exists, start with v0.0.0 | |
if ! latest_tag=$(git describe --tags --abbrev=0 2>/dev/null); then | |
echo "No existing tags found. Starting with v0.0.0" | |
latest_tag="v0.0.0" | |
fi | |
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT | |
- name: Get PRs and commits since last release | |
id: get_changes | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}" | |
# Get all PRs since last tag | |
if [ "$latest_tag" = "v0.0.0" ]; then | |
# For first release, get all PRs | |
gh pr list --state merged --json number,title,body,labels --jq '.[] | "\(.number)|\(.title)|\(.body)|\(.labels[].name)"' > prs.txt | |
# Get all commits for first release - only first line (subject) for pattern matching | |
git log --pretty=format:"%s" > commits.txt | |
else | |
# Get the date of the latest tag | |
tag_date=$(git log -1 --format=%at $latest_tag) | |
# Get PRs merged since last tag - FIXED: filter by merge date | |
gh pr list --state merged --json number,title,body,labels,mergedAt --jq ".[] | select(.mergedAt != null and (.mergedAt | fromdateiso8601) > $tag_date) | \"\(.number)|\(.title)|\(.body)|\(.labels[].name)\"" > prs.txt | |
# Get commits since last tag - only first line (subject) for pattern matching | |
git log $latest_tag..HEAD --pretty=format:"%s" > commits.txt | |
fi | |
# Count PRs with different labels | |
major_count=$(grep -c "major\|breaking" prs.txt || echo "0") | |
minor_count=$(grep -c "minor\|feature" prs.txt || echo "0") | |
# Count commits with different types | |
# Breaking changes (major) - handle BREAKING CHANGE separately due to space | |
commit_major_count=$(grep -E "^feat\\!" commits.txt | wc -l || echo "0") | |
commit_breaking_count=$(grep -E "BREAKING CHANGE" commits.txt | wc -l || echo "0") | |
commit_major_count=$((commit_major_count + commit_breaking_count)) | |
# Features (minor) | |
commit_minor_count=$(grep -E "^(feat|\[minor\])" commits.txt | wc -l || echo "0") | |
# Fixes (patch) | |
commit_fix_count=$(grep -E "^(fix)" commits.txt | wc -l || echo "0") | |
# Other conventional commits (patch) | |
commit_other_count=$(grep -E "^(chore|docs|style|refactor|perf|test|ci|build|revert)" commits.txt | wc -l || echo "0") | |
# Use the higher count between PR labels and commit messages | |
if [ "$major_count" -gt 0 ] || [ "$commit_major_count" -gt 0 ]; then | |
echo "version_type=major" >> $GITHUB_OUTPUT | |
elif [ "$minor_count" -gt 0 ] || [ "$commit_minor_count" -gt 0 ]; then | |
echo "version_type=minor" >> $GITHUB_OUTPUT | |
else | |
# If we have any commits (fixes or other), it's a patch | |
if [ "$commit_fix_count" -gt 0 ] || [ "$commit_other_count" -gt 0 ]; then | |
echo "version_type=patch" >> $GITHUB_OUTPUT | |
else | |
echo "version_type=patch" >> $GITHUB_OUTPUT | |
fi | |
fi | |
# Format PRs for release notes | |
echo "formatted_prs<<EOF" >> $GITHUB_OUTPUT | |
while IFS='|' read -r number title body labels; do | |
echo "### PR #$number: $title" | |
echo "Labels: $labels" | |
echo "" | |
echo "$body" | |
echo "" | |
done < prs.txt | |
echo "EOF" >> $GITHUB_OUTPUT | |
# Format commits by type - use full commit messages for display | |
echo "formatted_commits<<EOF" >> $GITHUB_OUTPUT | |
echo "### Breaking Changes" | |
if [ "$latest_tag" = "v0.0.0" ]; then | |
git log --pretty=format:"%B" | grep -E "^(feat!|BREAKING CHANGE)" || echo "None" | |
else | |
git log $latest_tag..HEAD --pretty=format:"%B" | grep -E "^(feat!|BREAKING CHANGE)" || echo "None" | |
fi | |
echo "" | |
echo "### Features" | |
if [ "$latest_tag" = "v0.0.0" ]; then | |
git log --pretty=format:"%B" | grep -E "^(feat|\[minor\])" || echo "None" | |
else | |
git log $latest_tag..HEAD --pretty=format:"%B" | grep -E "^(feat|\[minor\])" || echo "None" | |
fi | |
echo "" | |
echo "### Fixes" | |
if [ "$latest_tag" = "v0.0.0" ]; then | |
git log --pretty=format:"%B" | grep -E "^(fix)" || echo "None" | |
else | |
git log $latest_tag..HEAD --pretty=format:"%B" | grep -E "^(fix)" || echo "None" | |
fi | |
echo "" | |
echo "### Other Changes" | |
if [ "$latest_tag" = "v0.0.0" ]; then | |
git log --pretty=format:"%B" | grep -E "^(chore|docs|style|refactor|perf|test|ci|build|revert)" || echo "None" | |
else | |
git log $latest_tag..HEAD --pretty=format:"%B" | grep -E "^(chore|docs|style|refactor|perf|test|ci|build|revert)" || echo "None" | |
fi | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Generate new version | |
id: new_version | |
run: | | |
latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}" | |
# For first release, start with v1.0.0 | |
if [ "$latest_tag" = "v0.0.0" ]; then | |
new_version="v1.0.0" | |
echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
echo "version_type=major" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
# Remove 'v' prefix and split into major.minor.patch | |
version=${latest_tag#v} | |
IFS='.' read -r major minor patch <<< "$version" | |
# Get version type from previous step | |
version_type="${{ steps.get_changes.outputs.version_type }}" | |
if [ "$version_type" = "major" ]; then | |
major=$((major + 1)) | |
minor=0 | |
patch=0 | |
elif [ "$version_type" = "minor" ]; then | |
minor=$((minor + 1)) | |
patch=0 | |
else | |
patch=$((patch + 1)) | |
fi | |
new_version="v$major.$minor.$patch" | |
echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.new_version.outputs.new_version }} | |
name: aggregator ${{ steps.new_version.outputs.new_version }} | |
body: | | |
# Release ${{ steps.new_version.outputs.new_version }} | |
## Version Information | |
- **Type**: ${{ steps.get_changes.outputs.version_type }} version bump | |
- **Branch**: ${{ github.ref_name }} | |
- **Previous Version**: ${{ steps.get_latest_tag.outputs.latest_tag }} | |
## Pull Requests | |
${{ steps.get_changes.outputs.formatted_prs }} | |
## Changes | |
${{ steps.get_changes.outputs.formatted_commits }} | |
draft: false | |
prerelease: false | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |