Code Freeze CLI: Add branch and milestone commands to Code Freeze action (#37948)

* Add milestone computation cli

* lock file update

* lock file update

* conflicts

* fixup
This commit is contained in:
Paul Sealock 2023-04-27 09:02:32 +12:00 committed by GitHub
parent 64c2526b98
commit 95dc211bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 137 deletions

View File

@ -23,11 +23,17 @@ env:
permissions: {}
jobs:
verify-code-freeze:
name: 'Verify that today is the day of the code freeze'
code-freeze-prep:
name: 'Verify that today is the day of the code freeze and prepare repository'
runs-on: ubuntu-20.04
permissions:
contents: write
issues: write
outputs:
freeze: ${{ steps.check-freeze.outputs.freeze }}
nextReleaseBranch: ${{ steps.branch.outputs.nextReleaseBranch }}
nextReleaseVersion: ${{ steps.milestone.outputs.nextReleaseVersion }}
nextDevelopmentVersion: ${{ steps.milestone.outputs.nextDevelopmentVersion }}
steps:
- name: Checkout code
uses: actions/checkout@v3
@ -43,39 +49,19 @@ jobs:
id: check-freeze
run: pnpm utils code-freeze verify-day -g -o $TIME_OVERRIDE
maybe-create-next-milestone-and-release-branch:
name: 'Maybe create next milestone and release branch'
runs-on: ubuntu-20.04
permissions:
contents: write
issues: write
needs: verify-code-freeze
if: needs.verify-code-freeze.outputs.freeze == 'true'
outputs:
branch: ${{ steps.freeze.outputs.branch }}
release_version: ${{ steps.freeze.outputs.release_version }}
next_version: ${{ steps.freeze.outputs.next_version }}
steps:
- name: 'Install PHP'
uses: shivammathur/setup-php@8e2ac35f639d3e794c1da1f28999385ab6fdf0fc
with:
php-version: '7.4'
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 100
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
build: false
- name: 'Run the script to enforce the code freeze'
id: freeze
run: php .github/workflows/scripts/release-code-freeze.php
- name: Create next milestone
id: milestone
if: steps.check-freeze.outputs.freeze == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_OUTPUTS: 1
run: pnpm run utils code-freeze milestone -g -o ${{ github.repository_owner }}
- name: Create next release branch
id: branch
if: steps.check-freeze.outputs.freeze == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pnpm run utils code-freeze branch -g -o ${{ github.repository_owner }}
prep-trunk:
name: Preps trunk for next development cycle
@ -83,7 +69,8 @@ jobs:
permissions:
contents: write
pull-requests: write
needs: maybe-create-next-milestone-and-release-branch
needs: code-freeze-prep
if: needs.code-freeze-prep.outputs.freeze == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v3
@ -100,41 +87,41 @@ jobs:
uses: ./.github/actions/setup-woocommerce-monorepo
- name: Create branch
run: git checkout -b prep/trunk-for-next-dev-cycle-${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }}
run: git checkout -b prep/trunk-for-next-dev-cycle-${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }}
- name: Bump versions
working-directory: ./tools/version-bump
run: pnpm run version bump woocommerce -v ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }}.0-dev
run: pnpm run version bump woocommerce -v ${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }}.0-dev
- name: Checkout pnpm-lock.yaml to prevent issues
run: git checkout pnpm-lock.yaml
- name: Commit changes
run: git commit -am "Prep trunk for ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }} cycle"
run: git commit -am "Prep trunk for ${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }} cycle"
- name: Push branch up
run: git push --no-verify origin prep/trunk-for-next-dev-cycle-${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }}
run: git push --no-verify origin prep/trunk-for-next-dev-cycle-${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }}
- name: Create the PR
uses: actions/github-script@v6
with:
script: |
const body = "This PR updates the versions in trunk to ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }} for next development cycle."
const body = "This PR updates the versions in trunk to ${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }} for next development cycle."
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Prep trunk for ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }} cycle",
head: "prep/trunk-for-next-dev-cycle-${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }}",
title: "Prep trunk for ${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }} cycle",
head: "prep/trunk-for-next-dev-cycle-${{ needs.code-freeze-prep.outputs.nextDevelopmentVersion }}",
base: "trunk",
body: body
})
notify-slack:
name: 'Sends code freeze notification to Slack'
if: ${{ inputs.skipSlackPing != true }}
runs-on: ubuntu-20.04
needs: maybe-create-next-milestone-and-release-branch
needs: prep-trunk
if: ${{ inputs.skipSlackPing != true }}
steps:
- name: Slack
uses: archive/github-actions-slack@v2.0.0
@ -143,16 +130,17 @@ jobs:
slack-bot-user-oauth-access-token: ${{ secrets.CODE_FREEZE_BOT_TOKEN }}
slack-channel: ${{ inputs.slackChannelOverride || secrets.WOO_RELEASE_SLACK_CHANNEL }}
slack-text: |
:warning-8c: ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.release_version }} Code Freeze :ice_cube:
:warning-8c: ${{ needs.code-freeze-prep.outputs.nextReleaseVersion }} Code Freeze :ice_cube:
The automation to cut the release branch for ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.release_version }} has run. Any PRs that were not already merged will be a part of ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.next_version }} by default. If you have something that needs to make ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.release_version }} that hasn't yet been merged, please see the <${{ secrets.FG_LINK }}/code-freeze-for-woocommerce-core-release/|fieldguide page for the code freeze>.
The automation to cut the release branch for ${{ needs.code-freeze-prep.outputs.nextReleaseVersion }} has run. Any PRs that were not already merged will be a part of ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.nextDevelopmentVersion }} by default. If you have something that needs to make ${{ needs.maybe-create-next-milestone-and-release-branch.outputs.nextReleaseVersion }} that hasn't yet been merged, please see the <${{ secrets.FG_LINK }}/code-freeze-for-woocommerce-core-release/|fieldguide page for the code freeze>.
trigger-changelog-action:
name: 'Trigger changelog action'
runs-on: ubuntu-20.04
permissions:
actions: write
needs: maybe-create-next-milestone-and-release-branch
needs: code-freeze-prep
if: needs.code-freeze-prep.outputs.freeze == 'true'
steps:
- name: 'Trigger changelog action'
uses: actions/github-script@v6
@ -164,7 +152,7 @@ jobs:
workflow_id: 'release-changelog.yml',
ref: 'trunk',
inputs: {
releaseVersion: "${{ needs.maybe-create-next-milestone-and-release-branch.outputs.release_version }}",
releaseBranch: "${{ needs.maybe-create-next-milestone-and-release-branch.outputs.branch }}"
releaseVersion: "${{ needs.code-freeze-prep.outputs.nextReleaseVersion }}",
releaseBranch: "${{ needs.code-freeze-prep.outputs.nextReleaseBranch }}"
}
})

View File

@ -1,87 +0,0 @@
<?php
// phpcs:ignoreFile
/**
* Script to automatically enforce the release code freeze.
*
* @package WooCommerce/GithubActions
*/
require_once __DIR__ . '/post-request-shared.php';
$now = time();
if ( getenv( 'TIME_OVERRIDE' ) ) {
$now = strtotime( getenv( 'TIME_OVERRIDE' ) );
}
/**
* Set an output for the GitHub action.
*
* @param string $name The name of the output.
* @param string $value The value of the output.
*/
function set_output( $name, $value ) {
file_put_contents( getenv( 'GITHUB_OUTPUT' ), "{$name}={$value}" . PHP_EOL, FILE_APPEND );
}
// Code freeze comes 22 days prior to release day.
$release_time = strtotime( '+22 days', $now );
$release_day_of_week = date( 'l', $release_time );
$release_day_of_month = (int) date( 'j', $release_time );
// If 22 days from now isn't the second Tuesday, then it's not code freeze day.
if ( 'Tuesday' !== $release_day_of_week || $release_day_of_month < 8 || $release_day_of_month > 14 ) {
echo 'Info: Today is not the Monday of the code freeze.' . PHP_EOL;
exit( 1 );
}
$latest_version_with_release = get_latest_version_with_release();
if ( empty( $latest_version_with_release ) ) {
echo '*** Error: Unable to get latest version with release' . PHP_EOL;
exit( 1 );
}
// Because we go from 5.9 to 6.0, we can get the next major_minor by adding 0.1 and formatting appropriately.
$latest_float = (float) $latest_version_with_release;
$branch_major_minor = number_format( $latest_float + 0.1, 1 );
$milestone_major_minor = number_format( $latest_float + 0.2, 1 );
// We use those values to get the release branch and next milestones that we need to create.
$release_branch_to_create = "release/{$branch_major_minor}";
$milestone_to_create = "{$milestone_major_minor}.0";
if ( getenv( 'GITHUB_OUTPUTS' ) ) {
echo 'Including GitHub Outputs...' . PHP_EOL;
set_output( 'next_version', $milestone_major_minor );
set_output( 'release_version', $branch_major_minor );
set_output( 'branch', $release_branch_to_create );
set_output( 'milestone', $milestone_to_create );
}
if ( getenv( 'DRY_RUN' ) ) {
echo 'DRY RUN: Skipping actual creation of release branch and milestone...' . PHP_EOL;
echo "Release Branch: {$release_branch_to_create}" . PHP_EOL;
echo "Milestone: {$milestone_to_create}" . PHP_EOL;
return;
}
if ( create_github_milestone( $milestone_to_create ) ) {
echo "Created milestone {$milestone_to_create}" . PHP_EOL;
} elseif ( '422' === $github_api_response_code ) {
// The milestone already existed when GitHub returns a 422 status.
echo "Notice: Unable to create {$milestone_to_create} milestone. Maybe it already exists? Skipping..." . PHP_EOL;
} else {
echo "*** Error: Unable to create {$milestone_to_create} milestone" . PHP_EOL;
}
if ( create_github_branch_from_branch( 'trunk', $release_branch_to_create ) ) {
echo "Created branch {$release_branch_to_create}" . PHP_EOL;
} elseif ( '422' === $github_api_response_code ) {
// The release branch already existed when GitHub returns a 422 status.
echo "Notice: Unable to create {$release_branch_to_create} branch. Maybe it already exists? Skipping..." . PHP_EOL;
exit( 1 );
} else {
echo "*** Error: Unable to create {$release_branch_to_create}" . PHP_EOL;
exit( 1 );
}

View File

@ -15,6 +15,11 @@ export const WPIncrement = ( version: string ): string => {
return inc( parsedVersion, parsedVersion.minor === 9 ? 'major' : 'minor' );
};
const getMajorMinor = ( version: string ) => {
const parsedVersion = parse( version );
return `${ parsedVersion.major }.${ parsedVersion.minor }`;
};
/**
* Set Github outputs.
*
@ -25,6 +30,6 @@ export const setGithubMilestoneOutputs = (
nextReleaseVersion: string,
nextMilestone: string
): void => {
setOutput( 'nextReleaseVersion', nextReleaseVersion );
setOutput( 'nextDevelopmentVersion', nextMilestone );
setOutput( 'nextReleaseVersion', getMajorMinor( nextReleaseVersion ) );
setOutput( 'nextDevelopmentVersion', getMajorMinor( nextMilestone ) );
};