diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml index c87ccf495..186009f76 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release.yml @@ -1,4 +1,4 @@ -name: Prepare release +name: Prepare Release on: workflow_dispatch: inputs: @@ -9,6 +9,7 @@ on: jobs: crowdin_download_translations: + needs: pr_stable_bump runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -42,11 +43,12 @@ jobs: commit-message: Automated Crowdin downstream title: "[i18n] Automated Crowdin downstream" body: | - This is an automated PR. + This is an automated PR that is part of Prepare Release automated workflow (2 out of 2). Please ensure that there are no errors or invalid files are in the PR. labels: "Automated PR, Category: i18n, Changelog Entry: Skipped" branch: "automated/i18n" author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + milestone: ${{ needs.pr_stable_bump.outputs.milestone_number }} - name: Close and reopen the PR with different token to trigger CI uses: actions/github-script@v3 @@ -63,6 +65,8 @@ jobs: pr_stable_bump: runs-on: ubuntu-latest + outputs: + milestone_number: ${{ steps.get_milestone_number.outputs.result }} steps: # Checkout repository and install Python - uses: actions/checkout@v2 @@ -80,6 +84,19 @@ jobs: PYTHONPATH: ${{ github.workspace }}:${{ env.PYTHONPATH }} NEW_STABLE_VERSION: ${{ github.event.inputs.new_stable_version }} + # Get milestone number of the milestone for the new stable version + - name: Get milestone number + id: get_milestone_number + uses: actions/github-script@v3 + env: + MILESTONE_TITLE: ${{ steps.bump_version_stable.outputs.new_version }} + with: + script: | + const script = require( + `${process.env.GITHUB_WORKSPACE}/.github/workflows/scripts/get_milestone_number_by_exact_title.js` + ); + return await script({github, context}); + - name: Create Pull Request id: cpr_bump_stable uses: peter-evans/create-pull-request@v3 @@ -88,11 +105,12 @@ jobs: commit-message: Version bump to ${{ steps.bump_version_stable.outputs.new_version }} title: Version bump to ${{ steps.bump_version_stable.outputs.new_version }} body: | - This is an automated PR. + This is an automated PR that is part of Prepare Release automated workflow (1 out of 2). Please ensure that there are no errors or invalid files are in the PR. labels: "Automated PR, Changelog Entry: Skipped" branch: "automated/pr_bumps/${{ steps.bump_version_stable.outputs.new_version }}" author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + milestone: ${{ steps.get_milestone_number.outputs.result }} - name: Close and reopen the PR with different token to trigger CI uses: actions/github-script@v3 diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index 76d0a6010..306a6f9f8 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -1,4 +1,4 @@ -name: Publish the release +name: Publish Release on: push: tags: @@ -45,6 +45,19 @@ jobs: PYTHONPATH: ${{ github.workspace }}:${{ env.PYTHONPATH }} DEV_BUMP: '1' + # Get milestone number of the milestone for the old version + - name: Get milestone number + id: get_milestone_number + uses: actions/github-script@v3 + env: + MILESTONE_TITLE: ${{ steps.bump_version_dev.outputs.old_version }} + with: + script: | + const script = require( + `${process.env.GITHUB_WORKSPACE}/.github/workflows/scripts/get_milestone_number_by_exact_title.js` + ); + return await script({github, context}); + - name: Create Pull Request id: cpr_bump_dev uses: peter-evans/create-pull-request@v3 @@ -58,6 +71,7 @@ jobs: labels: "Automated PR, Changelog Entry: Skipped" branch: "automated/pr_bumps/${{ steps.bump_version_dev.outputs.new_version }}" author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + milestone: ${{ steps.get_milestone_number.outputs.result }} - name: Close and reopen the PR with different token to trigger CI uses: actions/github-script@v3 diff --git a/.github/workflows/scripts/bump_version.py b/.github/workflows/scripts/bump_version.py index b6d1d98d0..fdb2bb2a1 100644 --- a/.github/workflows/scripts/bump_version.py +++ b/.github/workflows/scripts/bump_version.py @@ -12,6 +12,8 @@ version_info = None def repl(match: Match[str]) -> str: global version_info + print(f"::set-output name=old_version::{match.group('version')}") + new_stable_version = os.environ.get("NEW_STABLE_VERSION", "auto") if new_stable_version == "auto": version_info = redbot.VersionInfo.from_str(match.group("version")) diff --git a/.github/workflows/scripts/get_milestone_number_by_exact_title.js b/.github/workflows/scripts/get_milestone_number_by_exact_title.js new file mode 100644 index 000000000..b7d734b5d --- /dev/null +++ b/.github/workflows/scripts/get_milestone_number_by_exact_title.js @@ -0,0 +1,49 @@ +module.exports = (async function ({github, context}) { + const milestone_title = process.env.MILESTONE_TITLE; + const [repo_owner, repo_name] = process.env.GITHUB_REPOSITORY.split('/'); + + const { + repository: { + milestones: { + nodes: milestones, + pageInfo: {hasNextPage} + } + } + } = await github.graphql({ + query: ` + query getMilestoneNumberByTitle( + $repo_owner: String! + $repo_name: String! + $milestone_title: String! + ) { + repository(owner:$repo_owner name:$repo_name) { + milestones(query:$milestone_title states:OPEN first:100) { + nodes { + number + title + } + pageInfo { + hasNextPage + } + } + } + }`, + repo_owner: repo_owner, + repo_name: repo_name, + milestone_title: milestone_title, + }); + + if (hasNextPage) { + // this should realistically never happen so let's just error + core.setFailed('Impossible happened! :)'); + return; + } + + for (const milestone of milestones) + if (milestone.title === milestone_title) + return milestone.number; + + // if no exact match is found, assume the milestone doesn't exist + console.log('The milestone was not found. API returned the array: %o', milestones); + return null; +})