2022-09-07 19:30:10 +00:00
name : Run post release processes
2022-12-15 22:41:03 +00:00
on :
release :
types : [ released]
2022-09-07 19:30:10 +00:00
env :
GIT_COMMITTER_NAME : 'WooCommerce Bot'
2023-11-06 13:06:54 +00:00
GIT_COMMITTER_EMAIL : 'no-reply@woo.com'
2022-09-07 19:30:10 +00:00
GIT_AUTHOR_NAME : 'WooCommerce Bot'
2023-11-06 13:06:54 +00:00
GIT_AUTHOR_EMAIL : 'no-reply@woo.com'
2022-09-07 19:30:10 +00:00
2023-01-02 17:28:11 +00:00
permissions : {}
2022-09-07 19:30:10 +00:00
jobs :
2022-12-15 22:41:03 +00:00
changelog-version-update :
name : Update changelog and version
runs-on : ubuntu-20.04
2023-01-02 17:28:11 +00:00
permissions :
contents : write
pull-requests : write
2022-12-15 22:41:03 +00:00
steps :
- uses : actions/checkout@v3
- name : Git fetch trunk branch
run : git fetch origin trunk
- 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 prep/post-release-tasks-${{ github.event.release.tag_name }}
- 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.' );
core.setOutput( 'continue', 'false' )
return;
} else {
core.setOutput( '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 ) {
core.setOutput( '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 ) {
core.setOutput( 'continue', 'false' );
console.error( err );
}
const regex = /== Changelog ==/;
const updatedChangelog = changelog.replace( regex, entries );
fs.writeFile( './changelog.txt', updatedChangelog, err => {
if ( err ) {
core.setOutput( 'continue', 'false' );
console.error( 'Unable to update changelog entries in changelog.txt' );
}
core.setOutput( 'continue', 'true' );
} )
} )
} )
- name : Commit changes
if : steps.update-entries.outputs.continue == 'true'
run : git commit -am "Prep trunk post release ${{ github.event.release.tag_name }}"
- name : Push branch up
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 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 : "prep/post-release-tasks-${{ github.event.release.tag_name }}" ,
base : "trunk" ,
body : body
})
const prCreated = await github.rest.pulls.requestReviewers({
owner : context.repo.owner,
repo : context.repo.repo,
pull_number : pr.data.number,
reviewers : [ "${{ github.event.release.author.login }}" ]
})