woocommerce/.github/workflows/post-release.yml

134 lines
5.5 KiB
YAML
Raw Normal View History

name: Run post release processes
on:
release:
types: [released]
env:
GIT_COMMITTER_NAME: 'WooCommerce Bot'
GIT_COMMITTER_EMAIL: 'no-reply@woocommerce.com'
GIT_AUTHOR_NAME: 'WooCommerce Bot'
GIT_AUTHOR_EMAIL: 'no-reply@woocommerce.com'
permissions: {}
jobs:
changelog-version-update:
name: Update changelog and version
runs-on: ubuntu-20.04
permissions:
contents: write
pull-requests: write
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 }}"]
})