From 24f204d4ed52523742b55c6527175783a21ea953 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 9 Jan 2024 17:17:19 -0800 Subject: [PATCH] Extract changelog. --- CHANGELOG.md | 1 + action.yml | 7 +++++++ index.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++--- package.json | 4 +++- pnpm-lock.yaml | 27 ++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2bffe..f1aa806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.2.0 - Will attempt to extract a changelog. +- Added `built`, `changelog-entry`, and `tag-version` outputs. # 0.1.0 diff --git a/action.yml b/action.yml index d039748..30ee25c 100644 --- a/action.yml +++ b/action.yml @@ -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.' diff --git a/index.ts b/index.ts index 48b1084..84baaf4 100644 --- a/index.ts +++ b/index.ts @@ -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'; @@ -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'); @@ -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); diff --git a/package.json b/package.json index 89669fa..d717ba3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ed3ae7..cfafb94 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,8 +17,14 @@ dependencies: '@ltd/j-toml': specifier: ^1.38.0 version: 1.38.0 + changelog-parser: + specifier: ^3.0.1 + version: 3.0.1 devDependencies: + '@types/changelog-parser': + specifier: ^2.8.4 + version: 2.8.4 '@types/node': specifier: ^20.10.8 version: 20.10.8 @@ -257,6 +263,10 @@ packages: resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} dev: true + /@types/changelog-parser@2.8.4: + resolution: {integrity: sha512-lCjy5pdZr+PmGMUSnn/z1BPWb3ADiGXjwbKdLa6EnvZ+dY6815Ak65VWstOIq/x3mqEwdvmv+/2ExRElEEcXMw==} + dev: true + /@types/json-schema@7.0.15: resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} dev: true @@ -726,6 +736,15 @@ packages: supports-color: 7.2.0 dev: true + /changelog-parser@3.0.1: + resolution: {integrity: sha512-1AEVJgnFEO4v5ukfEH/j9cr2Z39Y/GCieNi605azhufAolXF4vQAwZBY8BrUVRkvlI3gwe3i621/PIAW0zmmEQ==} + engines: {node: '>=14'} + hasBin: true + dependencies: + line-reader: 0.2.4 + remove-markdown: 0.5.0 + dev: false + /ci-info@3.9.0: resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==} engines: {node: '>=8'} @@ -2004,6 +2023,10 @@ packages: type-check: 0.4.0 dev: true + /line-reader@0.2.4: + resolution: {integrity: sha512-342xzyZZS9uTiKwHJcMacopVl/WjrMMCZS1Qg4Uhl/WBknWRrGFdKOIS1Kec6SaiTcZMtmuxWvvIbPXj/+FMjA==} + dev: false + /lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} dev: true @@ -2401,6 +2424,10 @@ packages: jsesc: 0.5.0 dev: true + /remove-markdown@0.5.0: + resolution: {integrity: sha512-x917M80K97K5IN1L8lUvFehsfhR8cYjGQ/yAMRI9E7JIKivtl5Emo5iD13DhMr+VojzMCiYk8V2byNPwT/oapg==} + dev: false + /resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'}