Skip to content

Commit

Permalink
Test vars
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Oct 15, 2020
1 parent 7d5f931 commit fdd72e0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
15 changes: 12 additions & 3 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
describe('TODO - Add a test suite', () => {
it('TODO - Add a test', async () => {});
});
import micromatch from 'micromatch';
import * as lib from '../src/index';

test('Test delete_file rule', () => {
const delete_files_pattern = "random-name-*.txt;random-*.txt".split(";")
.map((v) => v.trim())
.filter((v) => !!v);
expect(delete_files_pattern.length).toBe(2);

expect (delete_files_pattern && micromatch.isMatch("random-name-2bf0a034.txt", delete_files_pattern)).toBe(true);
expect (delete_files_pattern && micromatch.isMatch("random-name-d1e43358.txt", delete_files_pattern)).toBe(true);
});
15 changes: 14 additions & 1 deletion lib/index.js

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

15 changes: 14 additions & 1 deletion lib/index.js.map

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

24 changes: 24 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function getInputAsBool(name: string): boolean {
);
}

export { getInputAsArray, getInputAsBool };

async function run() {
try {
const github_token = (process.env["GITHUB_TOKEN"] || "").trim();
Expand Down Expand Up @@ -479,12 +481,25 @@ async function run() {
{
const old_asset_map = {};
const in_delete_rule = {};

if (is_verbose) {
console.log(
`Delete file pattern: ${delete_files_pattern}`
);
}

if (deploy_release && deploy_release.data && deploy_release.data.assets) {
for (const asset of deploy_release.data.assets) {
old_asset_map[asset.name] = asset;
if (delete_files_pattern && micromatch.isMatch(asset.name, delete_files_pattern)) {
in_delete_rule[asset.name] = true;
pending_to_delete.push(asset);

if (is_verbose) {
console.log(
`Old asset file: ${asset.name} match ${delete_files_pattern}.`
);
}
}
}
}
Expand All @@ -494,9 +509,18 @@ async function run() {
if (old_asset_map[file_base_name]) {
if (in_delete_rule[file_base_name]) {
// Already in delete rule, do nothing.
console.log(
`Overwrite asset file: ${file_base_name} , because it match ${delete_files_pattern}.`
);
} else if (is_overwrite) {
pending_to_delete.push(old_asset_map[file_base_name]);
pending_to_upload.push(file_path);

if (is_verbose) {
console.log(
`Overwrite old asset file: ${file_base_name}.`
);
}
} else {
console.log(
`Skip asset file: ${file_base_name}, it's already existed.`
Expand Down

0 comments on commit fdd72e0

Please sign in to comment.