Skip to content

Commit

Permalink
new: Support extracting a changelog. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Jan 10, 2024
1 parent cfd0bc6 commit 412fbb6
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 90 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.0.0
# 0.2.0

- Added `built`, `changelog-entry`, and `tag-version` outputs.
- Will attempt to extract a changelog.
- Refer to our readme for an updated GitHub workflow example.

# 0.1.0

- Initial release.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ for distribution. It achieves this by:
- Optimizes all `.wasm` files with `wasm-opt` and `wasm-strip`.
- Generates `.sha256` checksum files for all `.wasm` files.
- Moves built files to a `builds` directory.
- Extract changelog information for a release.

## Installation

Expand Down Expand Up @@ -36,12 +37,14 @@ jobs:
with:
cache: false
targets: wasm32-wasi
- uses: moonrepo/build-proto-plugin@v0
- id: build
uses: moonrepo/build-proto-plugin@v0
- if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: ncipollo/release-action@v1
with:
artifacts: builds/*
artifactErrorsFailBuild: true
body: ${{ steps.build.outputs.changelog-entry }}
prerelease:
${{ contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') ||
contains(github.ref_name, '-rc') }}
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ runs:
branding:
icon: 'layers'
color: 'red'
outputs:
built:
description: 'Whether the plugins have been built or not.'
changelog-entry:
description: 'The changelog entry, if it exists.'
tag-version:
description: 'The extracted version from a Git tag, if applicable.'
59 changes: 56 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import parseChangelog from 'changelog-parser';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
Expand All @@ -22,6 +23,18 @@ function getRoot(): string {
return process.env.GITHUB_WORKSPACE!;
}

let PLUGIN_VERSION: string | null = null;

function detectVersion() {
const ref = process.env.GITHUB_REF;

if (ref && ref.startsWith('refs/tags/')) {
PLUGIN_VERSION = ref.replace('refs/tags/', '');

core.setOutput('tag-version', PLUGIN_VERSION);
}
}

// https://github.com/WebAssembly/binaryen
async function installBinaryen() {
core.info('Installing WebAssembly binaryen');
Expand Down Expand Up @@ -181,20 +194,60 @@ async function buildPackages(builds: BuildInfo[]) {

await fs.promises.writeFile(checksumFile, checksumHash);

core.info(`${build.packageName} (${checksumHash})`);
core.info(`--> ${outputFile}`);
core.info(`--> ${checksumFile}`);
core.info(`Built ${build.packageName}`);
core.info(`\tPlugin file: ${checksumFile}`);
core.info(`\tChecksum file: ${outputFile}`);
core.info(`\tChecksum: ${checksumHash}`);
}

core.setOutput('built', 'true');
}

async function extractChangelog() {
let changelogPath = null;

for (const lookup of ['CHANGELOG.md', 'CHANGELOG', 'HISTORY.md', 'HISTORY']) {
const lookupPath = path.join(getRoot(), lookup);

if (fs.existsSync(lookupPath)) {
changelogPath = lookupPath;
break;
}
}

if (!changelogPath || !PLUGIN_VERSION) {
return;
}

const changelog = await parseChangelog({
filePath: changelogPath,
removeMarkdown: false,
});

for (const entry of changelog.versions) {
if (entry.version === PLUGIN_VERSION && entry.body) {
core.setOutput('changelog-entry', `## Changelog\n\n${entry.body.trim()}`);
break;
}
}
}

async function run() {
core.setOutput('built', 'false');
core.setOutput('changelog-entry', '');
core.setOutput('tag-version', '');

try {
detectVersion();

const builds = await findBuildablePackages();

if (builds.length > 0) {
await Promise.all([installWabt(), installBinaryen(), addRustupTarget()]);
await buildPackages(builds);
}

await extractChangelog();
} catch (error: unknown) {
core.setFailed(error as Error);
}
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonrepo/build-proto-plugin",
"version": "0.1.3",
"version": "0.2.0",
"description": "A GitHub action to build, optimize, and prepare proto WASM plugins for release.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -22,13 +22,15 @@
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/tool-cache": "^2.0.1",
"@ltd/j-toml": "^1.38.0"
"@ltd/j-toml": "^1.38.0",
"changelog-parser": "^3.0.1"
},
"devDependencies": {
"@types/node": "^20.10.5",
"@types/changelog-parser": "^2.8.4",
"@types/node": "^20.10.8",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
"eslint-config-moon": "^2.0.13",
"eslint-config-moon": "^2.0.14",
"prettier": "^3.1.1",
"prettier-config-moon": "^1.1.2",
"ts-node": "^10.9.2",
Expand Down
Loading

0 comments on commit 412fbb6

Please sign in to comment.