Skip to content

Commit 6aedc43

Browse files
committed
update workflow
1 parent 3a9cffb commit 6aedc43

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

.github/workflows/release.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,21 @@ jobs:
5858
run: |
5959
echo "RELEASE_NAME=$(node -p -e "require('./package.json').name")" >> $GITHUB_ENV
6060
61+
62+
# This step runs the script and captures its output
63+
- name: Get Changelog
64+
id: changelog
65+
run: |
66+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
67+
npm run changelog >> $GITHUB_OUTPUT
68+
echo "EOF" >> $GITHUB_OUTPUT
69+
6170
- name: "Upload Release"
6271
uses: softprops/action-gh-release@v2
6372
with:
6473
files: ./${{ env.RELEASE_NAME }}.zip
6574
make_latest: true
6675
name: Release - v${{ env.RELEASE_TAG }}
76+
body: ${{ steps.changelog.outputs.changelog }}
6777
env:
6878
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"wpml-config.xml"
4949
],
5050
"bin": {
51-
"package": "./tools/package.js"
51+
"package": "./tools/package.js",
52+
"changelog": "./tools/changelog.js"
5253
},
5354
"dependencies": {
5455
"@storepress/components": "^0.0.3",
@@ -103,6 +104,7 @@
103104
"packages-update": "wp-scripts packages-update",
104105
"prepackage": "rm -rf ./languages && rm -rf ./${npm_package_name}.zip && npm run clean-composer && composer install --no-dev --optimize-autoloader",
105106
"package": "./tools/package.js",
107+
"changelog": "./tools/changelog.js",
106108
"postpackage": "npm run clean-composer && composer install",
107109
"plugin-zip": "npm run package -- --zip",
108110
"start": "rm -rf ./build && wp-scripts start --webpack-copy-php --experimental-modules",

tools/changelog.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
/**
4+
* External dependencies
5+
*/
6+
const fs = require('fs-extra')
7+
const { stdout } = require('process')
8+
9+
/**
10+
* Internal dependencies
11+
*/
12+
13+
const {
14+
hasPackageProp,
15+
getPackageProp,
16+
hasArgInCLI,
17+
} = require('@wordpress/scripts/utils')
18+
19+
const {
20+
getChangelogFile,
21+
} = require('./webpack-helpers')
22+
23+
24+
25+
const version = getPackageProp('version')
26+
27+
const changelogFile = getChangelogFile()
28+
29+
// 2. Read and find the changelog entry for the current version.
30+
const changelog = fs.readFileSync(changelogFile, 'utf8')
31+
const lines = changelog.split('\n')
32+
const changelogEntry = []
33+
let inSection = false
34+
const versionString = `version ${version}`
35+
const dateRegex = /^\d{4}-\d{2}-\d{2}/
36+
37+
for (const line of lines) {
38+
if (inSection) {
39+
if (dateRegex.test(line) && !line.includes(versionString)) {
40+
break
41+
}
42+
changelogEntry.push(line)
43+
} else if (line.includes(versionString)) {
44+
inSection = true
45+
// continue
46+
// changelogEntry.push(line)
47+
}
48+
}
49+
50+
if (changelogEntry.length === 0) {
51+
changelogEntry.push(`- No changelog entry for version ${version}.\n\n`)
52+
}
53+
54+
// 3. Prepare the final output string
55+
const finalOutput = changelogEntry.join('\n').trim()
56+
57+
// 4. Check if running in GitHub Actions environment
58+
/*if (process.env.GITHUB_OUTPUT) {
59+
// If yes, write to the GITHUB_OUTPUT file to set an output variable
60+
// The format `key<<DELIMITER` is used for multiline strings
61+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `changelog_body<<EOF\n${finalOutput}\nEOF\n`)
62+
} else {
63+
stdout.write(`${finalOutput}\n`)
64+
}*/
65+
66+
stdout.write(`## What's Changed\n\n`)
67+
stdout.write(`${finalOutput}\n`)
68+
69+

tools/webpack-helpers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ function getFile( fileName ) {
8585
return fromProjectRoot( getProjectSourcePath() + sep + fileName );
8686
}
8787

88+
function getChangelogFile() {
89+
return fromProjectRoot( 'changelog.txt' );
90+
}
91+
8892
function getWebPackAlias() {
8993
return {
9094
//'@storepress/icons': getFile('packages/icons'),
@@ -94,6 +98,7 @@ function getWebPackAlias() {
9498
}
9599

96100
module.exports = {
101+
getChangelogFile,
97102
getFile,
98103
getWebPackAlias,
99104
requestToExternal,

0 commit comments

Comments
 (0)