-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
41 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,13 @@ | |
|
||
> Automate "Tested up to" version updates in your WordPress projects. | ||
[GitHub Action](https://github.com/features/actions) that fetches the latest | ||
This [GitHub Action](https://github.com/features/actions) fetches the latest | ||
WordPress version then updates the "Tested up to" version of your WordPress | ||
plugin or theme if it's out of date. | ||
|
||
Run it based on a cron or trigger it manually. Have the action create a pull | ||
request, or allow it to commit directly to the default branch. | ||
|
||
Never forget to update the "Tested up to" version of your WordPress plugin or | ||
theme again! | ||
The action can create a pull request for the change, or commit directly to the | ||
default branch. Never forget to update the "Tested up to" version of your | ||
WordPress plugin or theme again! | ||
|
||
## Example | ||
|
||
|
@@ -25,7 +23,7 @@ Here's a minimal example of running the action based on a cron schedule. | |
```yaml | ||
on: | ||
schedule: | ||
- cron: '0 0 * * 0' # Every Sunday at midnight | ||
- cron: '0 0 * * 0' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
|
@@ -49,30 +47,21 @@ jobs: | |
create and approve pull requests" repository option are required for the action | ||
to create pull requests. | ||
|
||
Optionally specify paths to update which will override the default `readme.txt` | ||
file: | ||
## Usage | ||
|
||
See [action.yml](action.yml) for detailed information on the action's inputs. | ||
|
||
```yaml | ||
- name: Update "Tested up to" version | ||
uses: AlecRust/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: AlecRust/[email protected] | ||
with: | ||
# Paths to update (optional, default: readme.txt) | ||
file-paths: | | ||
readme.txt | ||
my-other-file.php | ||
``` | ||
|
||
Optionally the action can commit directly to your default branch by setting | ||
`create-pr` to `false`: | ||
|
||
```yaml | ||
- name: Update "Tested up to" version | ||
uses: AlecRust/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
create-pr: false | ||
src/other-file.php | ||
# Create a pull request, or commit directly if disabled (optional, default: true) | ||
create-pr: true | ||
# Git author (optional, default: github-actions <[email protected]>) | ||
git-author: 'Joe Bloggs <[email protected]>' | ||
``` | ||
|
||
Please remember to thoroughly test your plugin/theme with the new version of | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ describe('action', () => { | |
it('completes after updating files and creates PR when create-pr is true', async () => { | ||
mocked(core.getInput).mockReturnValueOnce('true') // create-pr is true | ||
mocked(core.getInput).mockReturnValueOnce('readme.txt\nanother-file.txt') | ||
mocked(core.getInput).mockReturnValueOnce('Test Name <[email protected]>') | ||
mocked(getLatestWpVersion).mockResolvedValueOnce('5.9') | ||
mocked(updateFiles).mockResolvedValueOnce(true) | ||
|
||
|
@@ -60,6 +61,7 @@ describe('action', () => { | |
it('completes after updating files and pushes to main branch when create-pr is false', async () => { | ||
mocked(core.getInput).mockReturnValueOnce('false') // create-pr is false | ||
mocked(core.getInput).mockReturnValueOnce('readme.txt\nanother-file.txt') | ||
mocked(core.getInput).mockReturnValueOnce('Test Name <[email protected]>') | ||
mocked(getLatestWpVersion).mockResolvedValueOnce('5.9') | ||
mocked(updateFiles).mockResolvedValueOnce(true) | ||
|
||
|
@@ -81,6 +83,7 @@ describe('action', () => { | |
it('completes with no updates needed', async () => { | ||
mocked(core.getInput).mockReturnValueOnce('true') | ||
mocked(core.getInput).mockReturnValueOnce('readme.txt\nanother-file.txt') | ||
mocked(core.getInput).mockReturnValueOnce('Test Name <[email protected]>') | ||
mocked(getLatestWpVersion).mockResolvedValueOnce('5.9') | ||
mocked(updateFiles).mockResolvedValueOnce(false) | ||
|
||
|
@@ -96,6 +99,7 @@ describe('action', () => { | |
const error = new Error('An unexpected error') | ||
mocked(core.getInput).mockReturnValueOnce('true') | ||
mocked(core.getInput).mockReturnValueOnce('readme.txt') | ||
mocked(core.getInput).mockReturnValueOnce('Test Name <[email protected]>') | ||
mocked(getLatestWpVersion).mockRejectedValueOnce(error) | ||
|
||
await run() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ inputs: | |
description: | ||
'Flag setting if a pull request should be created for the changes.' | ||
default: 'true' | ||
git-author: | ||
description: | ||
'The name and email of the Git commit author in the format "name <email>".' | ||
default: 'github-actions <[email protected]>' | ||
|
||
outputs: | ||
updated: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,14 @@ export async function run(): Promise<void> { | |
.split(/\r?\n/) | ||
.filter(path => path.trim() !== '') | ||
|
||
const authorInput = core.getInput('git-author') | ||
const [authorName, authorEmail] = authorInput.match(/^(.+) <(.+)>$/) || [] | ||
if (!authorName || !authorEmail) { | ||
throw new Error( | ||
'Invalid git-author input format. Expected format: "name <email>".' | ||
) | ||
} | ||
|
||
const wpVersion = await getLatestWpVersion() | ||
const filesUpdated = await updateFiles(workspace, filePaths, wpVersion) | ||
if (!filesUpdated) { | ||
|
@@ -27,8 +35,8 @@ export async function run(): Promise<void> { | |
|
||
console.log(`Updated to WordPress ${wpVersion}, committing changes...`) | ||
const commitMessage = `Update WordPress 'Tested up to' version to ${wpVersion}` | ||
await git.addConfig('user.email', '[email protected]') | ||
await git.addConfig('user.name', 'GitHub Action') | ||
await git.addConfig('user.email', authorEmail) | ||
await git.addConfig('user.name', authorName) | ||
if (createPR) { | ||
const branchName = `tested-up-to-${wpVersion.replace(/\./g, '-')}` | ||
await git.checkoutLocalBranch(branchName) | ||
|