Skip to content

Commit

Permalink
Support globs in release filenames
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
Kas-tle committed Oct 14, 2024
1 parent 6136c13 commit e1194c6
Showing 14 changed files with 39,652 additions and 40,288 deletions.
78,790 changes: 39,360 additions & 39,430 deletions dist/index.js

Large diffs are not rendered by default.

1,018 changes: 211 additions & 807 deletions dist/licenses.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
16 changes: 8 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as core from '@actions/core'
import { getInputs } from './src/action/inputs';
import { writeRelease } from './src/action/release';
import { getRepoData } from './src/action/repo';
import { storeReleaseData } from './src/action/store';
import { uploadFiles } from './src/action/files';
import { authGithubApp } from './src/action/auth';
import { sendWebhook } from './src/action/hook';
import { setOutputs } from './src/action/output';
import { getInputs } from './src/action/inputs.js';
import { writeRelease } from './src/action/release.js';
import { getRepoData } from './src/action/repo.js';
import { storeReleaseData } from './src/action/store.js';
import { uploadFiles } from './src/action/files.js';
import { authGithubApp } from './src/action/auth.js';
import { sendWebhook } from './src/action/hook.js';
import { setOutputs } from './src/action/output.js';

async function run(): Promise<void> {
try {
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "base-release-action",
"version": "1.3.5",
"version": "1.4.0",
"description": "An action to create incremented releases in a similar style to Jenkins",
"repository": "https://github.com/Kas-tle/base-release-action.git",
"author": "Joshua Castle <packages@kastle.dev>",
@@ -17,18 +17,20 @@
},
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/auth-app": "^6.0.1",
"@octokit/core": "^5.0.1",
"@octokit/plugin-rest-endpoint-methods": "^10.0.0",
"@octokit/auth-app": "7.1.1",
"@octokit/core": "6.1.2",
"@octokit/plugin-rest-endpoint-methods": "13.2.6",
"@vermaysha/discord-webhook": "^1.4.0",
"glob": "^11.0.0",
"markdown-escape": "^2.0.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/markdown-escape": "^1.1.1",
"@types/node": "^20.7.1",
"@types/node": "22.7.5",
"@vercel/ncc": "^0.38.0",
"js-yaml": "^4.1.0",
"typescript": "^5.2.2"
}
},
"type": "module"
}
4 changes: 2 additions & 2 deletions src/action/auth.ts
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ import crypto from 'crypto';
import { createAppAuth } from '@octokit/auth-app';
import { Octokit } from '@octokit/core';
import { restEndpointMethods } from '@octokit/plugin-rest-endpoint-methods';
import { OctokitApi } from '../types/auth';
import { BaseRepo, Repo } from '../types/repo';
import { OctokitApi } from '../types/auth.js';
import { BaseRepo, Repo } from '../types/repo.js';
import { request } from "@octokit/request"

export async function authGithubApp(inp: {baseRepoData: BaseRepo}): Promise<{octokit: OctokitApi, repoData: Repo}> {
12 changes: 6 additions & 6 deletions src/action/files.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from "path";
import fs from "fs";
import * as parse from "../util/parse";
import { Inputs } from "../types/inputs";
import { ReleaseResponse } from "src/types/release";
import { Repo } from "src/types/repo";
import { FileInfo, UploadInfo } from "../types/files";
import * as parse from "../util/parse.js";
import { Inputs } from "../types/inputs.js";
import { ReleaseResponse } from "src/types/release.js";
import { Repo } from "src/types/repo.js";
import { FileInfo, UploadInfo } from "../types/files.js";
import { Readable } from "stream";
import { OctokitApi } from "../types/auth";
import { OctokitApi } from "../types/auth.js";

export async function uploadFiles(inp: {api: OctokitApi, inputs: Inputs, release: ReleaseResponse | null, repoData: Repo}) {
const { api, inputs, release, repoData } = inp;
8 changes: 4 additions & 4 deletions src/action/hook.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Embed, Webhook } from '@vermaysha/discord-webhook'
import { Inputs } from '../types/inputs';
import { ReleaseResponse } from '../types/release';
import { Repo } from '../types/repo';
import { OctokitApi } from '../types/auth';
import { Inputs } from '../types/inputs.js';
import { ReleaseResponse } from '../types/release.js';
import { Repo } from '../types/repo.js';
import { OctokitApi } from '../types/auth.js';

export async function sendWebhook(inp: {inputs: Inputs, api: OctokitApi, repoData: Repo, releaseResponse: ReleaseResponse | null}) {
const { inputs, api, repoData, releaseResponse } = inp;
51 changes: 38 additions & 13 deletions src/action/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as core from '@actions/core'
import fs from 'fs';
import { Inputs, PreviousRelease } from '../types/inputs';
import * as parse from '../util/parse';
import { Repo } from '../types/repo';
import { Inputs, PreviousRelease } from '../types/inputs.js';
import * as parse from '../util/parse.js';
import { Repo } from '../types/repo.js';
import os from 'os';
import path from 'path';
import { OctokitApi } from '../types/auth';
import { OctokitApi } from '../types/auth.js';
import markdownEscape from 'markdown-escape';
import { globSync } from 'glob';

export async function getInputs(inp: {api: OctokitApi, repoData: Repo}): Promise<Inputs> {
const { api, repoData } = inp;
@@ -47,18 +48,42 @@ async function getPrevRelease(inp: {api: OctokitApi, repoData: Repo}): Promise<P
}

function getFiles(): Inputs.File[] {
const files = core.getInput('files', { required: true });
const files = core.getInput('files');

if (files === '') {
return [];
}

const inputFiles: Inputs.File[] = [];

for (const file of parse.parseMultiInput(files)) {
let label: string;
let filePath: string;

return parse.parseMultiInput(files).map(file => {
if (!file.includes(':')) {
return { label: path.parse(file).name.toLowerCase(), path: file };
label = path.parse(file).name.toLowerCase();
filePath = file;
} else {
label = file.split(':')[0];
filePath = file.split(':').slice(1).join(':');
}

const [label, ...paths] = file.split(':');
const files = globSync(filePath);

if (files.length > 1) {
for (const file of files) {
const fileName = path.parse(file).name;
inputFiles.push({ label: `${label}-${fileName}`, path: file });
}
} else if (files.length === 1) {
inputFiles.push({ label, path: files[0] });
} else {
console.log(`File ${label} not found at ${filePath}`);
core.setFailed(`File ${label} not found at ${filePath}`);
}
}

console.log(`Using label ${label} for file path ${paths.join(':')}`);
return { label, path: paths.join(':') };
});
return inputFiles;
}

async function getRelease(inp: {api: OctokitApi, changes: Inputs.Change[], tag: Inputs.Tag, repoData: Repo, success: boolean}): Promise<Inputs.Release> {
@@ -159,9 +184,9 @@ async function getChanges(inp: {api: OctokitApi, prevRelease: PreviousRelease, r
const timestamp = c.commit.committer && c.commit.committer.date ? new Date(c.commit.committer.date).getTime().toString() : '';
const author = c.author ? c.author.login : '';
const coauthors = c.commit.message.match(/Co-authored-by: (.*) <(.*)>/g)
?.map(coauthor => coauthor.replace(/Co-authored-by: (.*) <(.*)>/, '$1'))
?.map((coauthor) => coauthor.replace(/Co-authored-by: (.*) <(.*)>/, '$1'))
.filter((value, index, array) => array.indexOf(value) === index)
.filter(coauthor => coauthor !== '') ?? [];
.filter((coauthor) => coauthor !== '') ?? [];

changes.push({ commit, summary, message, timestamp, author, coauthors });
}
4 changes: 2 additions & 2 deletions src/action/output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import { ReleaseResponse } from "../types/release";
import { Inputs } from '../types/inputs';
import { ReleaseResponse } from "../types/release.js";
import { Inputs } from '../types/inputs.js';

export async function setOutputs(inp: {release: ReleaseResponse | null, inputs: Inputs}): Promise<void> {
const { release, inputs } = inp;
8 changes: 4 additions & 4 deletions src/action/release.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OctokitApi } from '../types/auth';
import { Inputs } from '../types/inputs';
import { ReleaseResponse } from '../types/release';
import { Repo } from '../types/repo';
import { OctokitApi } from '../types/auth.js';
import { Inputs } from '../types/inputs.js';
import { ReleaseResponse } from '../types/release.js';
import { Repo } from '../types/repo.js';

export async function writeRelease(inp: {inputs: Inputs, api: OctokitApi, repoData: Repo}): Promise<ReleaseResponse | null> {
const { inputs, api, repoData } = inp;
4 changes: 2 additions & 2 deletions src/action/repo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseRepo } from "../types/repo";
import * as parse from '../util/parse';
import { BaseRepo } from "../types/repo.js";
import * as parse from '../util/parse.js';
import * as core from '@actions/core'

export function getRepoData(): BaseRepo {
6 changes: 3 additions & 3 deletions src/action/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OctokitApi } from '../types/auth';
import { OctokitApi } from '../types/auth.js';
import core from '@actions/core';
import { Inputs } from "../types/inputs";
import { Repo } from "../types/repo";
import { Inputs } from "../types/inputs.js";
import { Repo } from "../types/repo.js";
import { isDeepStrictEqual } from 'util';

export async function storeReleaseData(inp: {inputs: Inputs, api: OctokitApi, repoData: Repo}) {
2 changes: 1 addition & 1 deletion src/types/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Octokit } from "@octokit/core";
import { Api } from "@octokit/plugin-rest-endpoint-methods/dist-types/types";
import { Api } from "@octokit/plugin-rest-endpoint-methods";

export type OctokitApi = Octokit & Api;

0 comments on commit e1194c6

Please sign in to comment.