Revise logic to update changelog.txt entries (#35086)
* Add logic to update the Stable version after a release * Revise post release automation to only update changelog
This commit is contained in:
parent
bb42e7892a
commit
53cb2ada67
|
@ -10,52 +10,112 @@ env:
|
|||
GIT_AUTHOR_EMAIL: 'no-reply@woocommerce.com'
|
||||
|
||||
jobs:
|
||||
update-changelog-in-trunk:
|
||||
name: Update changelog in trunk
|
||||
changelog-version-update:
|
||||
name: Update changelog and version
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Get tag name
|
||||
id: tag
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const tag = ${{ toJSON( github.event.release.tag_name ) }}
|
||||
|
||||
console.log( `::set-output name=tag::release/${ tag.substring( 0, 3 ) }` )
|
||||
|
||||
- name: Git fetch trunk branch
|
||||
run: git fetch origin trunk
|
||||
|
||||
- name: Copy changelog.txt to vm root
|
||||
run: cp changelog.txt ../../changelog.txt
|
||||
- name: Copy readme.txt to vm root
|
||||
run: cp ./plugins/woocommerce/readme.txt ../../readme.txt
|
||||
|
||||
- name: Switch to trunk branch
|
||||
run: git checkout trunk
|
||||
|
||||
- name: Create a new branch based on trunk
|
||||
run: git checkout -b update/changelog-from-release-${{ github.event.release.tag_name }}
|
||||
run: git checkout -b prep/post-release-tasks-${{ github.event.release.tag_name }}
|
||||
|
||||
- name: Copy saved changelog.txt to monorepo
|
||||
run: cp ../../changelog.txt ./changelog.txt
|
||||
- name: Check if we need to continue processing
|
||||
uses: actions/github-script@v6
|
||||
id: check
|
||||
with:
|
||||
script: |
|
||||
const fs = require( 'node:fs' );
|
||||
const version = ${{ toJSON( github.event.release.tag_name ) }}
|
||||
|
||||
fs.readFile( './plugins/woocommerce/readme.txt', 'utf-8', function( err, data ) {
|
||||
if ( err ) {
|
||||
console.error( err );
|
||||
}
|
||||
|
||||
const regex = /Stable\stag:\s(\d+\.\d+\.\d+)/;
|
||||
|
||||
const stableVersion = data.match( regex )[1];
|
||||
|
||||
// If the release version is less than stable version we can bail.
|
||||
if ( version.localeCompare( stableVersion, undefined, { numeric: true, sensitivity: 'base' } ) == -1 ) {
|
||||
console.log( 'Release version is less than stable version. No automated action taken. A manual process is required.' );
|
||||
console.log( `::set-output name=continue::false` )
|
||||
return;
|
||||
} else {
|
||||
console.log( `::set-output name=continue::true` )
|
||||
}
|
||||
} )
|
||||
|
||||
- name: Update changelog.txt entries
|
||||
uses: actions/github-script@v6
|
||||
id: update-entries
|
||||
if: steps.check.outputs.continue == 'true'
|
||||
with:
|
||||
script: |
|
||||
const fs = require( 'node:fs' );
|
||||
const version = ${{ toJSON( github.event.release.tag_name ) }}
|
||||
|
||||
// Read the saved readme.txt file from earlier.
|
||||
fs.readFile( '../../readme.txt', 'utf-8', function( err, readme ) {
|
||||
if ( err ) {
|
||||
console.log( `::set-output name=continue::false` )
|
||||
console.error( err );
|
||||
}
|
||||
|
||||
const regex = /(== Changelog ==[\s\S]+)\s{2}\[See changelog for all versions\]\(https:\/\/raw\.githubusercontent\.com\/woocommerce\/woocommerce\/trunk\/changelog\.txt\)\./;
|
||||
|
||||
const entries = readme.match( regex )[1];
|
||||
|
||||
fs.readFile( './changelog.txt', 'utf-8', function( err, changelog ) {
|
||||
if ( err ) {
|
||||
console.log( `::set-output name=continue::false` )
|
||||
console.error( err );
|
||||
}
|
||||
|
||||
const regex = /== Changelog ==/;
|
||||
|
||||
const updatedChangelog = changelog.replace( regex, entries );
|
||||
|
||||
fs.writeFile( './changelog.txt', updatedChangelog, err => {
|
||||
if ( err ) {
|
||||
console.log( `::set-output name=continue::false` )
|
||||
console.error( 'Unable to update changelog entries in changelog.txt' );
|
||||
}
|
||||
|
||||
console.log( `::set-output name=continue::true` )
|
||||
} )
|
||||
} )
|
||||
} )
|
||||
|
||||
- name: Commit changes
|
||||
run: git commit -am "Update changelog.txt from release ${{ github.event.release.tag_name }}"
|
||||
if: steps.update-entries.outputs.continue == 'true'
|
||||
run: git commit -am "Prep trunk post release ${{ github.event.release.tag_name }}"
|
||||
|
||||
- name: Push branch up
|
||||
run: git push origin update/changelog-from-release-${{ github.event.release.tag_name }}
|
||||
if: steps.update-entries.outputs.continue == 'true'
|
||||
run: git push origin prep/post-release-tasks-${{ github.event.release.tag_name }}
|
||||
|
||||
- name: Create the PR
|
||||
if: steps.update-entries.outputs.continue == 'true'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const body = "This PR updates the changelog.txt based on the latest release: ${{ github.event.release.tag_name }}"
|
||||
const body = "This PR updates the changelog.txt entries based on the latest release: ${{ github.event.release.tag_name }}"
|
||||
|
||||
const pr = await github.rest.pulls.create({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
title: "Update changelog.txt from release ${{ github.event.release.tag_name }}",
|
||||
head: "update/changelog-from-release-${{ github.event.release.tag_name }}",
|
||||
head: "prep/post-release-tasks-${{ github.event.release.tag_name }}",
|
||||
base: "trunk",
|
||||
body: body
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue