Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -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
# but its recommended not to check these in https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations
node_modules
lib/*
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 |
| `draft` | Boolean | Indicator of whether or not this release is a draft |
| `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 |
| `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 |
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"@actions/github": "^5.1.1",
"@octokit/plugin-retry": "^4.0.3",
"@octokit/plugin-throttling": "^4.3.2",
"glob": "^8.0.3",
"glob": "^8.1.0",
"mime": "^3.0.0",
"node-fetch": "^2.6.7"
},
Expand Down
27 changes: 23 additions & 4 deletions src/main.ts
Expand Up @@ -9,6 +9,7 @@ import { release, upload, GitHubReleaser } from "./github";
import { getOctokit } from "@actions/github";
import { setFailed, setOutput } from "@actions/core";
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
import * as fs from 'fs';

import { env } from "process";

Expand All @@ -24,9 +25,21 @@ async function run() {
}
if (config.input_files) {
const patterns = unmatchedPatterns(config.input_files);
patterns.forEach((pattern) =>
console.warn(`🤔 Pattern '${pattern}' does not match any files.`)
);
patterns.forEach((pattern) => {
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) {
throw new Error(`⚠️ There were unmatched files`);
}
Expand Down Expand Up @@ -62,8 +75,14 @@ async function run() {
const rel = await release(config, new GitHubReleaser(gh));
if (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) {
console.warn(`🤔 ${config.input_files} not include valid file.`);
console.warn(`🤔 ${config.input_files} did not include valid files.`);
}
const currentAssets = rel.assets;
const assets = await Promise.all(
Expand Down