Skip to content

Commit

Permalink
Extract changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jan 10, 2024
1 parent f947447 commit 24f204d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.2.0

- Will attempt to extract a changelog.
- Added `built`, `changelog-entry`, and `tag-version` outputs.

# 0.1.0

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.'
52 changes: 49 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,19 +194,52 @@ 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}`);
}
}

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() {
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"@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/changelog-parser": "^2.8.4",
"@types/node": "^20.10.8",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24f204d

Please sign in to comment.