Skip to content

Commit

Permalink
Port over the build-tag-release action (#1)
Browse files Browse the repository at this point in the history
* Port over the build-tag-release action

* Use ESM

* Use cwd instead of __dirname

* Implement CR changes:

- Rename token to gh_token
- Make git username and email configurable
  • Loading branch information
CobyPear authored Dec 20, 2023
1 parent 28df330 commit 6797126
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# plugin-release-actions
GitHub actions for standardized releases for WP plugins and Drupal modules

## Build Tag and Release
This action will build a tag and draft a release for a plugin or module.
83 changes: 83 additions & 0 deletions build-tag-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build, Tag, and Release
description: Build the assets and push them to a new tag. Create a release based on the tag.

inputs:
draft:
description: "Create a draft release instead of a regular release."
required: false
default: "true"
build_node_assets:
description: "Build the node assets."
required: false
default: "false"
build_composer_assets:
description: "Build the composer assets."
required: false
default: "false"
gh_token:
description: "The GitHub token to use for authentication."
required: true
git_username:
description: "The username to use for git commits."
required: false
default: "Pantheon Automation"
git_email:
description: "The email to use for git commits."
required: false
default: "[email protected]"

runs:
using: "composite"
steps:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "lts"
cache: "npm"
- name: Build Node Assets
if: ${{ inputs.build_node_assets == 'true' }}
shell: bash
run: |
npm ci
npm run build
- name: Build Composer Assets
if: ${{ inputs.build_composer_assets == 'true' }}
shell: bash
run: |
composer install --no-dev -o
- name: Setup
shell: bash
run: |
VERSION=$(cat README.MD| grep 'Stable tag:' | awk '{print $3}')
[[ "$VERSION" != "" ]] || exit 1
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Commit Assets
shell: bash
if: ${{ inputs.build_node_assets == 'true' || inputs.build_composer_assets == 'true' }}
run: |
[[ "$VERSION" != "" ]] || exit 1
git config user.name "${{ inputs.git_username }}"
git config user.email "${{ inputs.git_email }}"
git checkout -b "robot-release-$VERSION"
[[ ${{ inputs.build_node_assets }} == "true" ]] && git add -f assets/*
[[ ${{ inputs.build_composer_assets }} == "true" ]] && git add -f vendor/*
git commit -m "Release $VERSION"
- name: Tag
shell: bash
run: |
echo "Releasing version $VERSION ..."
[[ "$VERSION" != "" ]] || exit 1
git tag "$VERSION"
git push --tags
- name: Release
shell: bash
run: |
node ../scripts/get_release_notes.js ./README.MD >> ./release_notes.md
gh release create $VERSION --title "$VERSION" -F ./release_notes.md $([[ ${{ inputs.draft }} == "true" ]] && echo "--draft")
env:
GH_TOKEN: ${{ inputs.gh_token }}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "plugin-release-actions",
"version": "0.1.0",
"private": true,
"description": "GitHub actions for standardized releases for WP plugins and Drupal modules",
"scripts": {
"test": "node --test"
},
"keywords": [],
"type": "module",
"author": "@pantheon-systems",
"license": "LGPL-3.0-or-later"
}
24 changes: 24 additions & 0 deletions scripts/get_release_notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
import { readFileSync } from "fs";
import { resolve } from "path";


export default (() => {
// get the args
const [path] = process.argv.slice(2);
// throw if necessary args are missing
if (!path) {
throw new Error("Please provide a path to the file to parse");
}
const filePath = resolve(process.cwd(), path);
const fileContent = readFileSync(filePath, "utf8");
/**
* @see {@link https://regex101.com/r/TmzSYI/1} for the regex explanation
*/
const regex =
/(^#{3}\s[\s\d\.-\w]+(\([\w\d\s]+\))?$\n(?<notes>^[\w\d\W][^#]{3,}$\n))/gm;
const matches = fileContent.matchAll(regex);
const [releaseNotes] = [...matches].map((match) => match.groups.notes.trim());
console.log(releaseNotes);
return releaseNotes;
})();
24 changes: 24 additions & 0 deletions scripts/tests/fixtures/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rossums Universal Robots
Contributors: [getpantheon](https://profiles.wordpress.org/getpantheon)
Donate link: https://example.com/
Tags: comments, spam
Requires at least: 4.5
Tested up to: 6.2.1
Requires PHP: 5.6
Stable tag: 0.1.2-dev
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

See the robots hard at work.

## Changelog

### 0.1.2-dev
* Set Counter to 1 [[34](https://github.com/pantheon-systems/plugin-pipeline-example/pull/34)]
* Set Counter to 2 [[36](https://github.com/pantheon-systems/plugin-pipeline-example/pull/36)]

### 0.1.1 (18 December 2023)
* Set Counter to 0 [[19](https://github.com/pantheon-systems/plugin-pipeline-example/pull/19)]

### 0.1.0 (6 June 2023)
* Initial Release [[1](https://github.com/pantheon-systems/plugin-pipeline-example/pull/1)]
24 changes: 24 additions & 0 deletions scripts/tests/fixtures/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rossums Universal Robots
Contributors: [getpantheon](https://profiles.wordpress.org/getpantheon)
Donate link: https://example.com/
Tags: comments, spam
Requires at least: 4.5
Tested up to: 6.2.1
Requires PHP: 5.6
Stable tag: 0.1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

See the robots hard at work.

## Changelog

### 0.1.2 (19 December 2023)
* Set Counter to 1 [[34](https://github.com/pantheon-systems/plugin-pipeline-example/pull/34)]
* Set Counter to 2 [[36](https://github.com/pantheon-systems/plugin-pipeline-example/pull/36)]

### 0.1.1 (18 December 2023)
* Set Counter to 0 [[19](https://github.com/pantheon-systems/plugin-pipeline-example/pull/19)]

### 0.1.0 (6 June 2023)
* Initial Release [[1](https://github.com/pantheon-systems/plugin-pipeline-example/pull/1)]
27 changes: 27 additions & 0 deletions scripts/tests/get_release_notes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
import assert from "node:assert";
import test from "node:test";

const expected = `* Set Counter to 1 [[34](https://github.com/pantheon-systems/plugin-pipeline-example/pull/34)]
* Set Counter to 2 [[36](https://github.com/pantheon-systems/plugin-pipeline-example/pull/36)]`;

const cases = [
{
name: "dev changelog",
path: "./scripts/tests/fixtures/dev.md",
expected,
},
{
name: "release changelog",
path: "./scripts/tests/fixtures/release.md",
expected,
},
];

for (const { name, path, expected } of cases) {
test(name, async () => {
process.argv[2] = path;
const actual = (await import("../get_release_notes.js")).default;
assert.equal(actual, expected);
});
}

0 comments on commit 6797126

Please sign in to comment.