-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Release Changelog | ||
|
||
on: | ||
release: | ||
types: [released] | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
update-changelog: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run Go Changelog Generator | ||
run: | | ||
# Run the Go changelog generator, passing the release tag if available | ||
if [ "${{ github.event.release.tag_name }}" = "latest" ]; then | ||
go run tools/changelog/changelog.go > "${{ github.event.release.tag_name }}-changelog.md" | ||
else | ||
go run tools/changelog/changelog.go "${{ github.event.release.tag_name }}" > "${{ github.event.release.tag_name }}-changelog.md" | ||
fi | ||
- name: Handle changelog files | ||
run: | | ||
# Ensure that the CHANGELOG directory exists | ||
mkdir -p CHANGELOG | ||
# Extract Major.Minor version by removing the 'v' prefix from the tag name | ||
TAG_NAME=${{ github.event.release.tag_name }} | ||
CHANGELOG_VERSION_NUMBER=$(echo "$TAG_NAME" | sed 's/^v//' | grep -oP '^\d+\.\d+') | ||
# Define the new changelog file path | ||
CHANGELOG_FILENAME="CHANGELOG-$CHANGELOG_VERSION_NUMBER.md" | ||
CHANGELOG_PATH="CHANGELOG/$CHANGELOG_FILENAME" | ||
# Check if the changelog file for the current release already exists | ||
if [ -f "$CHANGELOG_PATH" ]; then | ||
# If the file exists, append the new changelog to the existing one | ||
cat "$CHANGELOG_PATH" >> "${TAG_NAME}-changelog.md" | ||
# Overwrite the existing changelog with the updated content | ||
mv "${TAG_NAME}-changelog.md" "$CHANGELOG_PATH" | ||
else | ||
# If the changelog file doesn't exist, rename the temp changelog file to the new changelog file | ||
mv "${TAG_NAME}-changelog.md" "$CHANGELOG_PATH" | ||
# Ensure that README.md exists | ||
if [ ! -f "CHANGELOG/README.md" ]; then | ||
echo -e "# CHANGELOGs\n\n" > CHANGELOG/README.md | ||
fi | ||
# Add the new changelog entry at the top of the README.md | ||
if ! grep -q "\[$CHANGELOG_FILENAME\]" CHANGELOG/README.md; then | ||
sed -i "3i- [$CHANGELOG_FILENAME](./$CHANGELOG_FILENAME)" CHANGELOG/README.md | ||
# Remove the extra newline character added by sed | ||
# sed -i '4d' CHANGELOG/README.md | ||
fi | ||
fi | ||
- name: Clean up | ||
run: | | ||
# Remove any temporary files that were created during the process | ||
rm -f "${{ github.event.release.tag_name }}-changelog.md" | ||
- name: Create Pull Request | ||
uses: peter-evans/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "Update CHANGELOG for release ${{ github.event.release.tag_name }}" | ||
title: "Update CHANGELOG for release ${{ github.event.release.tag_name }}" | ||
body: "This PR updates the CHANGELOG files for release ${{ github.event.release.tag_name }}" | ||
branch: changelog-${{ github.event.release.tag_name }} | ||
base: main | ||
delete-branch: true | ||
labels: changelog |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Create Pre-Release PR from Milestone | ||
name: Create Individual PRs from Milestone | ||
|
||
permissions: | ||
contents: write | ||
|
@@ -9,24 +9,24 @@ on: | |
workflow_dispatch: | ||
inputs: | ||
milestone_name: | ||
description: 'Milestone name to collect closed PRs from' | ||
description: "Milestone name to collect closed PRs from" | ||
required: true | ||
default: 'v1.8.3' | ||
default: "v3.8.4" | ||
target_branch: | ||
description: 'Target branch to merge the consolidated PR' | ||
description: "Target branch to merge the consolidated PR" | ||
required: true | ||
default: 'pre-release-v1.8.3' | ||
default: "pre-release-v3.8.4" | ||
|
||
env: | ||
MILESTONE_NAME: ${{ github.event.inputs.milestone_name || 'v1.8.3' }} | ||
TARGET_BRANCH: ${{ github.event.inputs.target_branch || 'pre-release-v1.8.3' }} | ||
MILESTONE_NAME: ${{ github.event.inputs.milestone_name || 'v3.8.4' }} | ||
TARGET_BRANCH: ${{ github.event.inputs.target_branch || 'pre-release-v3.8.4' }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | ||
LABEL_NAME: cherry-picked | ||
TEMP_DIR: /tmp # Using /tmp as the temporary directory | ||
TEMP_DIR: /tmp | ||
|
||
jobs: | ||
cherry_pick_milestone_prs: | ||
merge_milestone_prs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup temp directory | ||
|
@@ -47,7 +47,6 @@ jobs: | |
|
||
- name: Setup Git User for OpenIM-Robot | ||
run: | | ||
# Set up Git credentials for the bot | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "OpenIM-Robot" | ||
|
@@ -83,136 +82,66 @@ jobs: | |
if ! echo "$labels" | grep -q "${LABEL_NAME}"; then | ||
echo "PR #$pr_number does not have the 'cherry-picked' label. Adding to the list." | ||
echo "$pr_number" >> ${{ env.TEMP_DIR }}/pr_numbers.txt | ||
else | ||
echo "PR #$pr_number already has the 'cherry-picked' label. Skipping." | ||
fi | ||
done | ||
# Sort the filtered PR numbers | ||
sort -n ${{ env.TEMP_DIR }}/pr_numbers.txt -o ${{ env.TEMP_DIR }}/pr_numbers.txt | ||
echo "Filtered and sorted PR numbers:" | ||
cat ${{ env.TEMP_DIR }}/pr_numbers.txt || echo "No closed PR numbers found for milestone." | ||
- name: Fetch Merge Commits for PRs and Generate Title and Body | ||
- name: Create Individual PRs | ||
run: | | ||
# Ensure the files are initialized | ||
> ${{ env.TEMP_DIR }}/commit_hashes.txt | ||
> ${{ env.TEMP_DIR }}/pr_title.txt | ||
> ${{ env.TEMP_DIR }}/pr_body.txt | ||
# Write description to the PR body | ||
echo "### Description:" >> ${{ env.TEMP_DIR }}/pr_body.txt | ||
echo "Merging PRs from milestone \`$MILESTONE_NAME\` into target branch \`$TARGET_BRANCH\`." >> ${{ env.TEMP_DIR }}/pr_body.txt | ||
echo "" >> ${{ env.TEMP_DIR }}/pr_body.txt | ||
echo "### Need Merge PRs:" >> ${{ env.TEMP_DIR }}/pr_body.txt | ||
pr_numbers_in_title="" | ||
# Process sorted PR numbers and generate commit hashes | ||
for pr_number in $(cat ${{ env.TEMP_DIR }}/pr_numbers.txt); do | ||
echo "Processing PR #$pr_number" | ||
pr_details=$(curl -s -H "Authorization: token $BOT_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number") | ||
pr_title=$(echo "$pr_details" | jq -r '.title') | ||
pr_body=$(echo "$pr_details" | jq -r '.body') | ||
pr_creator=$(echo "$pr_details" | jq -r '.user.login') | ||
merge_commit=$(echo "$pr_details" | jq -r '.merge_commit_sha') | ||
short_commit_hash=$(echo "$merge_commit" | cut -c 1-7) | ||
# Append PR details to the body | ||
echo "- $pr_title: (#$pr_number) ($short_commit_hash)" >> ${{ env.TEMP_DIR }}/pr_body.txt | ||
if [ "$merge_commit" != "null" ];then | ||
echo "$merge_commit" >> ${{ env.TEMP_DIR }}/commit_hashes.txt | ||
echo "#$pr_number" >> ${{ env.TEMP_DIR }}/pr_title.txt | ||
pr_numbers_in_title="$pr_numbers_in_title #$pr_number" | ||
fi | ||
done | ||
git fetch origin | ||
echo "Checking out target branch: $TARGET_BRANCH" | ||
git checkout $TARGET_BRANCH | ||
echo "Pulling latest changes from target branch: $TARGET_BRANCH" | ||
git pull origin $TARGET_BRANCH | ||
cherry_pick_branch="cherry-pick-${short_commit_hash}" | ||
git checkout -b $cherry_pick_branch | ||
echo "Cherry-picking commit: $merge_commit" | ||
if ! git cherry-pick "$merge_commit" --strategy=recursive -X theirs; then | ||
echo "Cherry-pick encountered conflicts, attempting to continue..." | ||
git cherry-pick --continue || { echo "Cherry-pick failed"; exit 1; } | ||
fi | ||
git cherry-pick "$merge_commit" --strategy=recursive -X theirs || git cherry-pick --continue | ||
git remote set-url origin "https://${BOT_TOKEN}@github.com/${{ github.repository }}.git" | ||
echo "Pushing branch: $cherry_pick_branch" | ||
git push origin $cherry_pick_branch --force || { echo "Push failed"; exit 1; } | ||
new_pr_title="$pr_title [Created by @$pr_creator from #$pr_number]" | ||
new_pr_body="$pr_body | ||
> This PR cherry-picks commit from original PR #$pr_number." | ||
response=$(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
https://api.github.com/repos/${{ github.repository }}/pulls \ | ||
-d "$(jq -n --arg title "$new_pr_title" \ | ||
--arg head "$cherry_pick_branch" \ | ||
--arg base "$TARGET_BRANCH" \ | ||
--arg body "$new_pr_body" \ | ||
'{title: $title, head: $head, base: $base, body: $body}')") | ||
commit_hashes=$(cat ${{ env.TEMP_DIR }}/commit_hashes.txt | tr '\n' ' ') | ||
first_commit_hash=$(head -n 1 ${{ env.TEMP_DIR }}/commit_hashes.txt) | ||
cherry_pick_branch="cherry-pick-${first_commit_hash:0:7}" | ||
echo "COMMIT_HASHES=$commit_hashes" >> $GITHUB_ENV | ||
echo "CHERRY_PICK_BRANCH=$cherry_pick_branch" >> $GITHUB_ENV | ||
echo "pr_numbers_in_title=$pr_numbers_in_title" >> $GITHUB_ENV | ||
new_pr_number=$(echo "$response" | jq -r '.number') | ||
echo "Created PR #$new_pr_number" | ||
- name: Pull and Cherry-pick Commits, Then Push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | ||
run: | | ||
# Fetch and pull the latest changes from the target branch | ||
git fetch origin | ||
git checkout $TARGET_BRANCH | ||
git pull origin $TARGET_BRANCH | ||
# Create a new branch for cherry-picking | ||
git checkout -b $CHERRY_PICK_BRANCH | ||
# Cherry-pick the commits and handle conflicts | ||
for commit_hash in $COMMIT_HASHES; do | ||
echo "Attempting to cherry-pick commit $commit_hash" | ||
if ! git cherry-pick "$commit_hash" --strategy=recursive -X theirs; then | ||
echo "Conflict detected for $commit_hash. Resolving with incoming changes." | ||
conflict_files=$(git diff --name-only --diff-filter=U) | ||
echo "Conflicting files:" | ||
echo "$conflict_files" | ||
for file in $conflict_files; do | ||
if [ -f "$file" ]; then | ||
echo "Resolving conflict for $file" | ||
git add "$file" | ||
else | ||
echo "File $file has been deleted. Skipping." | ||
git rm "$file" | ||
fi | ||
done | ||
echo "Conflicts resolved. Continuing cherry-pick." | ||
git cherry-pick --continue | ||
else | ||
echo "Cherry-pick successful for commit $commit_hash." | ||
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-d '{"labels": ["milestone-merge"]}' \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues/$new_pr_number/labels" | ||
fi | ||
done | ||
# Push the cherry-pick branch to the repository | ||
git remote set-url origin "https://${BOT_TOKEN}@github.com/${{ github.repository }}.git" | ||
git push origin $CHERRY_PICK_BRANCH --force | ||
- name: Create Pull Request | ||
run: | | ||
# Prepare and create the PR | ||
pr_title="deps: Merge ${{ env.pr_numbers_in_title }} PRs into $TARGET_BRANCH" | ||
pr_body=$(cat ${{ env.TEMP_DIR }}/pr_body.txt) | ||
echo "Prepared PR title:" | ||
echo "$pr_title" | ||
echo "Prepared PR body:" | ||
echo "$pr_body" | ||
# Create the PR using the GitHub API | ||
response=$(curl -s -X POST -H "Authorization: token $BOT_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
https://api.github.com/repos/${{ github.repository }}/pulls \ | ||
-d "$(jq -n --arg title "$pr_title" \ | ||
--arg head "$CHERRY_PICK_BRANCH" \ | ||
--arg base "$TARGET_BRANCH" \ | ||
--arg body "$pr_body" \ | ||
'{title: $title, head: $head, base: $base, body: $body}')") | ||
pr_number=$(echo "$response" | jq -r '.number') | ||
echo "$pr_number" > ${{ env.TEMP_DIR }}/created_pr_number.txt | ||
echo "Created PR #$pr_number" | ||
- name: Add Label to Created Pull Request | ||
run: | | ||
# Add 'milestone-merge' label to the created PR | ||
pr_number=$(cat ${{ env.TEMP_DIR }}/created_pr_number.txt) | ||
echo "Adding label to PR #$pr_number" | ||
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-d '{"labels": ["milestone-merge"]}' \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues/$pr_number/labels" | ||
echo "Added 'milestone-merge' label to PR #$pr_number." |