Allow renaming of files using ":" and update documentation to match

This commit is contained in:
Brendan Davidson 2023-05-23 13:46:44 -06:00
parent c9b46fe7aa
commit 93cffc984e
6 changed files with 35 additions and 15 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ __tests__/runner/*
# actions requires a node_modules dir https://github.com/actions/toolkit/blob/master/docs/javascript-action.md#publish-a-releasesv1-action # actions requires a node_modules dir https://github.com/actions/toolkit/blob/master/docs/javascript-action.md#publish-a-releasesv1-action
# but its recommended not to check these in https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations # but its recommended not to check these in https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations
node_modules node_modules
lib/*

View file

@ -173,7 +173,7 @@ The following are optional as `step.with` keys
| `body_path` | String | Path to load text communicating notable changes in this release | | `body_path` | String | Path to load text communicating notable changes in this release |
| `draft` | Boolean | Indicator of whether or not this release is a draft | | `draft` | Boolean | Indicator of whether or not this release is a draft |
| `prerelease` | Boolean | Indicator of whether or not is a prerelease | | `prerelease` | Boolean | Indicator of whether or not is a prerelease |
| `files` | String | Newline-delimited globs of paths to assets to upload for release | | `files` | String | Newline-delimited globs of paths to assets to upload for release. Files can be renamed using oldName:newName. |
| `name` | String | Name of the release. defaults to tag name | | `name` | String | Name of the release. defaults to tag name |
| `tag_name` | String | Name of a tag. defaults to `github.ref` | | `tag_name` | String | Name of a tag. defaults to `github.ref` |
| `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing | | `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing |

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

14
package-lock.json generated
View file

@ -12,7 +12,7 @@
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@octokit/plugin-retry": "^4.0.3", "@octokit/plugin-retry": "^4.0.3",
"@octokit/plugin-throttling": "^4.3.2", "@octokit/plugin-throttling": "^4.3.2",
"glob": "^8.0.3", "glob": "^8.1.0",
"mime": "^3.0.0", "mime": "^3.0.0",
"node-fetch": "^2.6.7" "node-fetch": "^2.6.7"
}, },
@ -2212,9 +2212,9 @@
} }
}, },
"node_modules/glob": { "node_modules/glob": {
"version": "8.0.3", "version": "8.1.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
"integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
"dependencies": { "dependencies": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",
@ -6024,9 +6024,9 @@
"dev": true "dev": true
}, },
"glob": { "glob": {
"version": "8.0.3", "version": "8.1.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
"integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
"requires": { "requires": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",

View file

@ -23,7 +23,7 @@
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"@octokit/plugin-retry": "^4.0.3", "@octokit/plugin-retry": "^4.0.3",
"@octokit/plugin-throttling": "^4.3.2", "@octokit/plugin-throttling": "^4.3.2",
"glob": "^8.0.3", "glob": "^8.1.0",
"mime": "^3.0.0", "mime": "^3.0.0",
"node-fetch": "^2.6.7" "node-fetch": "^2.6.7"
}, },

View file

@ -9,6 +9,7 @@ import { release, upload, GitHubReleaser } from "./github";
import { getOctokit } from "@actions/github"; import { getOctokit } from "@actions/github";
import { setFailed, setOutput } from "@actions/core"; import { setFailed, setOutput } from "@actions/core";
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils"; import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
import * as fs from 'fs';
import { env } from "process"; import { env } from "process";
@ -24,9 +25,21 @@ async function run() {
} }
if (config.input_files) { if (config.input_files) {
const patterns = unmatchedPatterns(config.input_files); const patterns = unmatchedPatterns(config.input_files);
patterns.forEach((pattern) => patterns.forEach((pattern) => {
console.warn(`🤔 Pattern '${pattern}' does not match any files.`) console.warn(pattern);
); // Rename file using oldName:newName notation
if (pattern.includes(":")) {
let names = pattern.split(':');
let oldName = names[0];
let newName = names[1];
fs.rename(oldName, newName, () => {
console.warn(`🤔Renamed file from '${oldName}' to '${newName}!`);
});
}
else {
console.warn(`🤔 Pattern '${pattern}' does not match any files.`)
}
});
if (patterns.length > 0 && config.input_fail_on_unmatched_files) { if (patterns.length > 0 && config.input_fail_on_unmatched_files) {
throw new Error(`⚠️ There were unmatched files`); throw new Error(`⚠️ There were unmatched files`);
} }
@ -62,8 +75,14 @@ async function run() {
const rel = await release(config, new GitHubReleaser(gh)); const rel = await release(config, new GitHubReleaser(gh));
if (config.input_files) { if (config.input_files) {
const files = paths(config.input_files); const files = paths(config.input_files);
config.input_files.forEach((file) => {
if (file.includes(":")) {
// Use the new name instead to upload
files.push(file.split(":")[1]);
}
})
if (files.length == 0) { if (files.length == 0) {
console.warn(`🤔 ${config.input_files} not include valid file.`); console.warn(`🤔 ${config.input_files} did not include valid files.`);
} }
const currentAssets = rel.assets; const currentAssets = rel.assets;
const assets = await Promise.all( const assets = await Promise.all(