Delete old files
This commit is contained in:
parent
5f836e8716
commit
b8902a20c8
@ -1,22 +0,0 @@
|
||||
# Contributors
|
||||
|
||||
### Checkin
|
||||
|
||||
- Do checkin source (src)
|
||||
- Do checkin build output (lib)
|
||||
- Do checkin runtime node_modules
|
||||
- Do not checkin devDependency node_modules (husky can help see below)
|
||||
|
||||
### devDependencies
|
||||
|
||||
In order to handle correctly checking in node_modules without devDependencies, we run [Husky](https://github.com/typicode/husky) before each commit.
|
||||
This step ensures that formatting and checkin rules are followed and that devDependencies are excluded. To make sure Husky runs correctly, please use the following workflow:
|
||||
|
||||
```
|
||||
npm install # installs all devDependencies including Husky
|
||||
git add abc.ext # Add the files you've changed. This should include files in src, lib, and node_modules (see above)
|
||||
git commit -m "Informative commit message" # Commit. This will run Husky
|
||||
```
|
||||
|
||||
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) as well as pruning out devDependencies using `npm prune --production`.
|
||||
It will also make sure these changes are appropriately included in your commit (no further work is needed)
|
111
lib/main.js
111
lib/main.js
@ -1,111 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const github = __importStar(require("@actions/github"));
|
||||
const path = __importStar(require("path"));
|
||||
const glob = require("glob");
|
||||
function get_release_by_tag(tag, octokit, context) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
core.debug(`Getting release by tag ${tag}.`);
|
||||
return yield octokit.repos.getReleaseByTag(Object.assign({}, context.repo, { tag: tag }));
|
||||
}
|
||||
catch (error) {
|
||||
// If this returns 404, we need to create the release first.
|
||||
if (error.status === 404) {
|
||||
core.debug(`Release for tag ${tag} doesn't exist yet so we'll create it now.`);
|
||||
return yield octokit.repos.createRelease(Object.assign({}, context.repo, { tag_name: tag }));
|
||||
}
|
||||
else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function upload_to_release(release, file, asset_name, tag, overwrite, octokit, context) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const stat = fs.statSync(file);
|
||||
if (!stat.isFile()) {
|
||||
core.debug(`Skipping ${file}, since its not a file`);
|
||||
return;
|
||||
}
|
||||
const file_size = stat.size;
|
||||
const file_bytes = fs.readFileSync(file);
|
||||
// Check for duplicates.
|
||||
const assets = yield octokit.repos.listAssetsForRelease(Object.assign({}, context.repo, { release_id: release.data.id }));
|
||||
const duplicate_asset = assets.data.find(a => a.name === asset_name);
|
||||
if (duplicate_asset !== undefined) {
|
||||
if (overwrite === "true") {
|
||||
core.debug(`An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.`);
|
||||
yield octokit.repos.deleteReleaseAsset(Object.assign({}, context.repo, { asset_id: duplicate_asset.id }));
|
||||
}
|
||||
else {
|
||||
core.setFailed(`An asset called ${asset_name} already exists.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.debug(`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`);
|
||||
}
|
||||
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`);
|
||||
yield octokit.repos.uploadReleaseAsset({
|
||||
url: release.data.upload_url,
|
||||
name: asset_name,
|
||||
file: file_bytes,
|
||||
headers: {
|
||||
"content-type": "binary/octet-stream",
|
||||
"content-length": file_size
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const token = core.getInput('repo_token', { required: true });
|
||||
const file = core.getInput('file', { required: true });
|
||||
const file_glob = core.getInput('file_glob');
|
||||
const tag = core.getInput('tag', { required: true }).replace("refs/tags/", "");
|
||||
const overwrite = core.getInput('overwrite');
|
||||
const octokit = new github.GitHub(token);
|
||||
const context = github.context;
|
||||
const release = yield get_release_by_tag(tag, octokit, context);
|
||||
if (file_glob === "true") {
|
||||
const files = glob.sync(file);
|
||||
if (files.length > 0) {
|
||||
for (let file of files) {
|
||||
const asset_name = path.basename(file);
|
||||
yield upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.setFailed("No files matching the glob pattern found.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
const asset_name = core.getInput('asset_name', { required: true }).replace(/\$tag/g, tag);
|
||||
yield upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
run();
|
Loading…
Reference in New Issue
Block a user