diff --git a/.github/workflows/merge-milestone-PR.yml b/.github/workflows/merge-milestone-PR.yml new file mode 100644 index 0000000..a9dc0e8 --- /dev/null +++ b/.github/workflows/merge-milestone-PR.yml @@ -0,0 +1,92 @@ +name: Single PR for Closed Milestone PRs + +on: + workflow_dispatch: # Manual trigger + inputs: + milestone: + description: 'Milestone name to collect closed PRs from' + required: true + default: 'v3.8.2' # Default milestone set to v3.8.2 + target_branch: + description: 'Target branch to merge the consolidated PR' + required: true + default: 'pre-release-v3.8.2' # Default target branch with pre-release-v*.* format + schedule: + - cron: '0 0 * * 0' # Scheduled to run every Sunday at 00:00 UTC + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + cherry_pick_closed_milestone_prs: + runs-on: ubuntu-latest + steps: + # Step 1: Checkout the repository code + - name: Checkout repository + uses: actions/checkout@v2 + + # Step 2: Set up Git user details for making commits + - name: Setup Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + # Step 3: Install GitHub CLI to interact with milestones and PRs + - name: Install GitHub CLI + run: sudo apt install gh + + # Step 4: Authenticate GitHub CLI using GITHUB_TOKEN + - name: Authenticate GitHub CLI + run: echo "${{ env.GITHUB_TOKEN }}" | gh auth login --with-token + + # Step 5: Fetch closed PRs from the specified milestone + - name: Fetch Closed PRs from Milestone + id: fetch_prs + run: | + milestone="${{ github.event.inputs.milestone }}" + prs=$(gh pr list --search "milestone:$milestone is:closed" --json number,headRefName,mergeCommit) + echo "::set-output name=prs::$prs" + + # Step 6: Create a new branch from main, cherry-pick PRs, and push to remote + - name: Create and Cherry-pick Branch + if: ${{ steps.fetch_prs.outputs.prs != '[]' }} + run: | + target_branch="${{ github.event.inputs.target_branch }}" + cherry_pick_branch="milestone-cherry-pick-$(date +%Y%m%d%H%M%S)" + + # Switch to main branch, pull latest changes, then create a new cherry-pick branch + git checkout main + git pull origin main + git checkout -b $cherry_pick_branch + + # Iterate over closed PRs in the milestone and cherry-pick each merge commit + echo "${{ steps.fetch_prs.outputs.prs }}" | jq -c '.[]' | while read -r pr; do + pr_number=$(echo "$pr" | jq '.number') + merge_commit=$(echo "$pr" | jq -r '.mergeCommit') + + if [ "$merge_commit" != "null" ]; then + # Check if the merge commit is already in the target branch + if git merge-base --is-ancestor $merge_commit $target_branch; then + echo "Skipping PR #$pr_number - Commit $merge_commit already in $target_branch" + else + echo "Cherry-picking PR #$pr_number with commit $merge_commit" + git cherry-pick $merge_commit || git cherry-pick --abort + fi + else + echo "Skipping PR #$pr_number as it does not have a merge commit." + fi + done + + # Push the cherry-pick branch to the remote repository + git push origin $cherry_pick_branch + + # Step 7: Create a single pull request to merge the cherry-pick branch into the target branch + - name: Create Pull Request to Target Branch + if: steps.fetch_prs.outputs.prs != "[]" + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: $cherry_pick_branch + base: ${{ github.event.inputs.target_branch }} + title: "Consolidated Closed Milestone PRs for ${{ github.event.inputs.target_branch }}" + body: "This PR includes all cherry-picked changes from closed PRs in milestone '${{ github.event.inputs.milestone }}' to ${{ github.event.inputs.target_branch }}." diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml new file mode 100644 index 0000000..df86248 --- /dev/null +++ b/.github/workflows/milestone.yml @@ -0,0 +1,52 @@ +name: Assign Milestone to PR + +on: + pull_request: + types: [opened, edited, reopened] + +jobs: + assign-milestone: + runs-on: ubuntu-latest + + env: + STABLE_VERSION_MILESTONE: v3.8 + FEATURE_VERSION_MILESTONE: v3.8.2 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set milestone based on PR title + id: set-milestone + run: | + if [[ "${{ github.event.pull_request.title }}" == fix:* ]]; then + echo "::set-output name=milestone::${{ env.STABLE_VERSION_MILESTONE }}" + else + echo "::set-output name=milestone::${{ env.FEATURE_VERSION_MILESTONE }}" + fi + shell: bash + + - name: Assign milestone to PR + uses: actions/github-script@v6 + with: + script: | + const pr = context.payload.pull_request; + const milestoneTitle = '${{ steps.set-milestone.outputs.milestone }}'; + + const { data: milestones } = await github.rest.issues.listMilestones({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const milestone = milestones.find(m => m.title === milestoneTitle); + + if (milestone) { + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + milestone: milestone.number + }); + console.log(`Assigned milestone "${milestone.title}" to PR #${pr.number}`); + } else { + console.log(`Milestone "${milestoneTitle}" not found.`); \ No newline at end of file diff --git a/.github/workflows/del-bot-gen-branch.yml b/.github/workflows/unused/del-bot-gen-branch.yml similarity index 100% rename from .github/workflows/del-bot-gen-branch.yml rename to .github/workflows/unused/del-bot-gen-branch.yml diff --git a/.github/workflows/update-release-file.ymlbak b/.github/workflows/unused/update-release-file.ymlbak similarity index 100% rename from .github/workflows/update-release-file.ymlbak rename to .github/workflows/unused/update-release-file.ymlbak diff --git a/.github/workflows/unused/upgrade-version-by-tag.yml b/.github/workflows/unused/upgrade-version-by-tag.yml new file mode 100644 index 0000000..4b1f6f9 --- /dev/null +++ b/.github/workflows/unused/upgrade-version-by-tag.yml @@ -0,0 +1,56 @@ +# name: Upgrade version by tag + +# permissions: +# contents: write +# pull-requests: write + +# on: +# push: +# tags: +# - 'v[0-9]+.[0-9]+.[0-9]+' + +# jobs: +# upgrade_version: +# runs-on: ubuntu-latest +# env: +# TAG_VERSION: ${{ github.ref_name }} +# BRANCH_NAME: update-tag-version-${{ github.ref_name }} +# steps: +# # Step 1: Checkout the original repository's code +# - name: Checkout code +# uses: actions/checkout@v4 +# with: +# # repository: openimsdk/actions-test +# fetch-depth: 0 + +# # Step 2: Set up Git with official account +# - name: Set up Git +# run: | +# git config user.name "github-actions[bot]" +# git config user.email "github-actions[bot]@users.noreply.github.com" + +# # # Step 3: Create a new branch for version update +# # - name: Create new branch for version update +# # run: | +# # git checkout -b ${{ env.BRANCH_NAME }} + +# # Step 4: Update version file +# - name: Update version file +# run: | +# echo "${{ env.TAG_VERSION }}" > version/version + + +# # Step 5: Create a Pull Request from the new branch to the original repository +# - name: Create Pull Request +# id: create_pr +# uses: peter-evans/create-pull-request@v7.0.1 +# with: +# branch-token: ${{ secrets.GITHUB_TOKEN }} +# token: ${{ secrets.GITHUB_TOKEN }} +# # token: ${{ secrets.BOT_TOKEN }} +# commit-message: "Update version to ${{ env.TAG_VERSION }}" +# branch: ${{ env.BRANCH_NAME }} +# delete-branch: true +# base: main +# title: "Update version to ${{ env.TAG_VERSION }}" +# body: "This PR updates the version file to the new tag version ${{ env.TAG_VERSION }}." diff --git a/.github/workflows/change-release.yml b/.github/workflows/update-version-file-on-release.yml similarity index 70% rename from .github/workflows/change-release.yml rename to .github/workflows/update-version-file-on-release.yml index 63efc2a..f582edf 100644 --- a/.github/workflows/change-release.yml +++ b/.github/workflows/update-version-file-on-release.yml @@ -1,4 +1,4 @@ -name: Update Version and Tag +name: Update Version File on Release on: release: @@ -9,7 +9,6 @@ jobs: runs-on: ubuntu-latest env: TAG_VERSION: ${{ github.event.release.tag_name }} - BRANCH_NAME: update-tag-version-${{ github.event.release.tag_name }} steps: # Step 1: Checkout the original repository's code - name: Checkout code @@ -53,30 +52,33 @@ jobs: git tag ${{ env.TAG_VERSION }} git push origin ${{ env.TAG_VERSION }} - # Step 7: Wait for changes to propagate - - name: Wait for changes - run: sleep 30 - - # Step 8: Publish Release if Draft - - name: Publish Release if Draft + # Step 8: Find and Publish Draft Release + - name: Find and Publish Draft Release uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const { data: release } = await github.rest.repos.getReleaseByTag({ + // Get the list of releases + const releases = await github.rest.repos.listReleases({ owner: context.repo.owner, - repo: context.repo.repo, - tag: context.payload.release.tag_name + repo: context.repo.repo }); - - if (release.draft) { + + // Find the draft release where the title and tag_name are the same + const draftRelease = releases.data.find(release => + release.draft && release.name === release.tag_name + ); + + if (draftRelease) { + // Publish the draft release using the release_id await github.rest.repos.updateRelease({ owner: context.repo.owner, repo: context.repo.repo, - release_id: release.id, + release_id: draftRelease.id, // Use release_id draft: false }); - core.info(`Release ${release.tag_name} published successfully.`); + + core.info(`Draft Release ${draftRelease.tag_name} published successfully.`); } else { - core.info(`Release ${release.tag_name} is already published.`); + core.info("No matching draft release found."); } \ No newline at end of file diff --git a/.github/workflows/upgrade-version-by-tag.yml b/.github/workflows/upgrade-version-by-tag.yml deleted file mode 100644 index b2248e2..0000000 --- a/.github/workflows/upgrade-version-by-tag.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Upgrade version by tag - -permissions: - contents: write - pull-requests: write - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - -jobs: - upgrade_version: - runs-on: ubuntu-latest - env: - TAG_VERSION: ${{ github.ref_name }} - BRANCH_NAME: update-tag-version-${{ github.ref_name }} - steps: - # Step 1: Checkout the original repository's code - - name: Checkout code - uses: actions/checkout@v4 - with: - # repository: openimsdk/actions-test - fetch-depth: 0 - - # Step 2: Set up Git with official account - - name: Set up Git - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - # # Step 3: Create a new branch for version update - # - name: Create new branch for version update - # run: | - # git checkout -b ${{ env.BRANCH_NAME }} - - # Step 4: Update version file - - name: Update version file - run: | - echo "${{ env.TAG_VERSION }}" > version/version - - - # Step 5: Create a Pull Request from the new branch to the original repository - - name: Create Pull Request - id: create_pr - uses: peter-evans/create-pull-request@v7.0.1 - with: - branch-token: ${{ secrets.GITHUB_TOKEN }} - token: ${{ secrets.GITHUB_TOKEN }} - # token: ${{ secrets.BOT_TOKEN }} - commit-message: "Update version to ${{ env.TAG_VERSION }}" - branch: ${{ env.BRANCH_NAME }} - delete-branch: true - base: main - title: "Update version to ${{ env.TAG_VERSION }}" - body: "This PR updates the version file to the new tag version ${{ env.TAG_VERSION }}."