Skip to content

Commit 21a9e8b

Browse files
raulpe7eiramhanberg
authored andcommitted
feat: add extra flag to clean your build cache
1 parent ca20977 commit 21a9e8b

File tree

4 files changed

+155
-84
lines changed

4 files changed

+155
-84
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ deploy:
2828

2929
- uses: mhanberg/gigalixir-action@<current release>
3030
with:
31+
APP_SUBFOLDER: my-app-subfolder # Add only if you want to deploy an app that is not at the root of your repository
32+
GIGALIXIR_APP: my-gigalixir-app # Feel free to also put this in your secrets
33+
GIGALIXIR_CLEAN: true # defaults to false
3134
GIGALIXIR_USERNAME: ${{ secrets.GIGALIXIR_USERNAME }}
3235
GIGALIXIR_PASSWORD: ${{ secrets.GIGALIXIR_PASSWORD }}
33-
GIGALIXIR_APP: my-gigalixir-app # Feel free to also put this in your secrets
34-
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
3536
MIGRATIONS: false # defaults to true
36-
APP_SUBFOLDER: my-app-subfolder # Add only if you want to deploy an app that is not at the root of your repository
37+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
3738
```
3839
3940
## Migrations

action.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
name: 'Gigalixir Action'
22
description: 'Deploy to Gigalixir'
33
inputs:
4+
APP_SUBFOLDER:
5+
description: 'Subfolder of your app'
6+
required: false
7+
GIGALIXIR_APP:
8+
description: 'Your gigalixir app name'
9+
required: true
10+
GIGALIXIR_CLEAN:
11+
description: 'Extra flag you can pass to clean your cache before building'
12+
required: false
13+
default: false
414
GIGALIXIR_USERNAME:
515
description: 'Your Gigalixir username'
616
required: true
717
GIGALIXIR_PASSWORD:
818
description: 'Your Gigalixir password'
919
required: true
10-
SSH_PRIVATE_KEY:
11-
description: 'Your ssh private key that is paired with a public key that is uploaded to Gigalixir'
12-
required: true
13-
GIGALIXIR_APP:
14-
description: 'Your gigalixir app name'
15-
required: true
1620
MIGRATIONS:
1721
description: 'Configuration for migrations'
1822
required: true
1923
default: true
20-
APP_SUBFOLDER:
21-
description: 'Subfolder of your app'
22-
required: false
24+
SSH_PRIVATE_KEY:
25+
description: 'Your ssh private key that is paired with a public key that is uploaded to Gigalixir'
26+
required: true
2327

2428
runs:
2529
using: 'node12'

dist/index.js

Lines changed: 121 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
5757
step((generator = generator.apply(thisArg, _arguments || [])).next());
5858
});
5959
};
60+
var __importStar = (this && this.__importStar) || function (mod) {
61+
if (mod && mod.__esModule) return mod;
62+
var result = {};
63+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
64+
result["default"] = mod;
65+
return result;
66+
};
6067
Object.defineProperty(exports, "__esModule", { value: true });
61-
const childProcess = __webpack_require__(129);
62-
const path = __webpack_require__(622);
68+
const childProcess = __importStar(__webpack_require__(129));
69+
const path = __importStar(__webpack_require__(622));
6370
const util_1 = __webpack_require__(669);
64-
const ioUtil = __webpack_require__(672);
71+
const ioUtil = __importStar(__webpack_require__(672));
6572
const exec = util_1.promisify(childProcess.exec);
6673
/**
6774
* Copies a file or folder.
@@ -229,58 +236,73 @@ function which(tool, check) {
229236
throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`);
230237
}
231238
}
239+
return result;
232240
}
233-
try {
234-
// build the list of extensions to try
235-
const extensions = [];
236-
if (ioUtil.IS_WINDOWS && process.env.PATHEXT) {
237-
for (const extension of process.env.PATHEXT.split(path.delimiter)) {
238-
if (extension) {
239-
extensions.push(extension);
240-
}
241-
}
242-
}
243-
// if it's rooted, return it if exists. otherwise return empty.
244-
if (ioUtil.isRooted(tool)) {
245-
const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions);
246-
if (filePath) {
247-
return filePath;
241+
const matches = yield findInPath(tool);
242+
if (matches && matches.length > 0) {
243+
return matches[0];
244+
}
245+
return '';
246+
});
247+
}
248+
exports.which = which;
249+
/**
250+
* Returns a list of all occurrences of the given tool on the system path.
251+
*
252+
* @returns Promise<string[]> the paths of the tool
253+
*/
254+
function findInPath(tool) {
255+
return __awaiter(this, void 0, void 0, function* () {
256+
if (!tool) {
257+
throw new Error("parameter 'tool' is required");
258+
}
259+
// build the list of extensions to try
260+
const extensions = [];
261+
if (ioUtil.IS_WINDOWS && process.env['PATHEXT']) {
262+
for (const extension of process.env['PATHEXT'].split(path.delimiter)) {
263+
if (extension) {
264+
extensions.push(extension);
248265
}
249-
return '';
250-
}
251-
// if any path separators, return empty
252-
if (tool.includes('/') || (ioUtil.IS_WINDOWS && tool.includes('\\'))) {
253-
return '';
254266
}
255-
// build the list of directories
256-
//
257-
// Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
258-
// it feels like we should not do this. Checking the current directory seems like more of a use
259-
// case of a shell, and the which() function exposed by the toolkit should strive for consistency
260-
// across platforms.
261-
const directories = [];
262-
if (process.env.PATH) {
263-
for (const p of process.env.PATH.split(path.delimiter)) {
264-
if (p) {
265-
directories.push(p);
266-
}
267-
}
267+
}
268+
// if it's rooted, return it if exists. otherwise return empty.
269+
if (ioUtil.isRooted(tool)) {
270+
const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions);
271+
if (filePath) {
272+
return [filePath];
268273
}
269-
// return the first match
270-
for (const directory of directories) {
271-
const filePath = yield ioUtil.tryGetExecutablePath(directory + path.sep + tool, extensions);
272-
if (filePath) {
273-
return filePath;
274+
return [];
275+
}
276+
// if any path separators, return empty
277+
if (tool.includes(path.sep)) {
278+
return [];
279+
}
280+
// build the list of directories
281+
//
282+
// Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
283+
// it feels like we should not do this. Checking the current directory seems like more of a use
284+
// case of a shell, and the which() function exposed by the toolkit should strive for consistency
285+
// across platforms.
286+
const directories = [];
287+
if (process.env.PATH) {
288+
for (const p of process.env.PATH.split(path.delimiter)) {
289+
if (p) {
290+
directories.push(p);
274291
}
275292
}
276-
return '';
277293
}
278-
catch (err) {
279-
throw new Error(`which failed with message ${err.message}`);
294+
// find all matches
295+
const matches = [];
296+
for (const directory of directories) {
297+
const filePath = yield ioUtil.tryGetExecutablePath(path.join(directory, tool), extensions);
298+
if (filePath) {
299+
matches.push(filePath);
300+
}
280301
}
302+
return matches;
281303
});
282304
}
283-
exports.which = which;
305+
exports.findInPath = findInPath;
284306
function readCopyOptions(options) {
285307
const force = options.force == null ? true : options.force;
286308
const recursive = Boolean(options.recursive);
@@ -354,13 +376,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
354376
step((generator = generator.apply(thisArg, _arguments || [])).next());
355377
});
356378
};
379+
var __importStar = (this && this.__importStar) || function (mod) {
380+
if (mod && mod.__esModule) return mod;
381+
var result = {};
382+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
383+
result["default"] = mod;
384+
return result;
385+
};
357386
Object.defineProperty(exports, "__esModule", { value: true });
358-
const os = __webpack_require__(87);
359-
const events = __webpack_require__(614);
360-
const child = __webpack_require__(129);
361-
const path = __webpack_require__(622);
362-
const io = __webpack_require__(1);
363-
const ioUtil = __webpack_require__(672);
387+
const os = __importStar(__webpack_require__(87));
388+
const events = __importStar(__webpack_require__(614));
389+
const child = __importStar(__webpack_require__(129));
390+
const path = __importStar(__webpack_require__(622));
391+
const io = __importStar(__webpack_require__(1));
392+
const ioUtil = __importStar(__webpack_require__(672));
364393
/* eslint-disable @typescript-eslint/unbound-method */
365394
const IS_WINDOWS = process.platform === 'win32';
366395
/*
@@ -804,6 +833,12 @@ class ToolRunner extends events.EventEmitter {
804833
resolve(exitCode);
805834
}
806835
});
836+
if (this.options.input) {
837+
if (!cp.stdin) {
838+
throw new Error('child process missing stdin');
839+
}
840+
cp.stdin.end(this.options.input);
841+
}
807842
});
808843
});
809844
}
@@ -1083,17 +1118,25 @@ function formatReleaseMessage(releaseNumber) {
10831118
"This is the first release";
10841119
}
10851120

1121+
function addExtraFlagCleanCache(gigalixirClean) {
1122+
return gigalixirClean ? ` -c http.extraheader="GIGALIXIR-CLEAN: true" ` : ""
1123+
}
1124+
10861125
async function run() {
10871126
try {
1088-
const baseInputOptions = {
1127+
const requiredInputOptions = {
10891128
required: true
10901129
};
1091-
const gigalixirUsername = core.getInput('GIGALIXIR_USERNAME', baseInputOptions);
1092-
const gigalixirPassword = core.getInput('GIGALIXIR_PASSWORD', baseInputOptions);
1093-
const sshPrivateKey = core.getInput('SSH_PRIVATE_KEY', baseInputOptions);
1094-
const gigalixirApp = core.getInput('GIGALIXIR_APP', baseInputOptions);
1095-
const migrations = core.getInput('MIGRATIONS', baseInputOptions);
1096-
const appSubfolder = core.getInput('APP_SUBFOLDER', { required: false });
1130+
const optionalInputOptions = {
1131+
required: false
1132+
};
1133+
const appSubfolder = core.getInput('APP_SUBFOLDER', optionalInputOptions);
1134+
const gigalixirApp = core.getInput('GIGALIXIR_APP', requiredInputOptions);
1135+
const gigalixirClean = core.getInput('GIGALIXIR_CLEAN', optionalInputOptions);
1136+
const gigalixirUsername = core.getInput('GIGALIXIR_USERNAME', requiredInputOptions);
1137+
const gigalixirPassword = core.getInput('GIGALIXIR_PASSWORD', requiredInputOptions);
1138+
const migrations = core.getInput('MIGRATIONS', requiredInputOptions);
1139+
const sshPrivateKey = core.getInput('SSH_PRIVATE_KEY', { required: migrations });
10971140

10981141
await core.group("Installing gigalixir", async () => {
10991142
await exec.exec('pip3 install gigalixir')
@@ -1115,9 +1158,9 @@ async function run() {
11151158

11161159
await core.group("Deploying to gigalixir", async () => {
11171160
if (appSubfolder) {
1118-
await exec.exec(`git subtree push --prefix ${appSubfolder} gigalixir master`);
1161+
await exec.exec(`git ${addExtraFlagCleanCache(gigalixirClean)} subtree push --prefix ${appSubfolder} gigalixir master`);
11191162
} else {
1120-
await exec.exec("git push -f gigalixir HEAD:refs/heads/master");
1163+
await exec.exec(`git ${addExtraFlagCleanCache(gigalixirClean)} push -f gigalixir HEAD:refs/heads/master`);
11211164
}
11221165
});
11231166

@@ -1367,6 +1410,7 @@ exports.getInput = getInput;
13671410
*/
13681411
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13691412
function setOutput(name, value) {
1413+
process.stdout.write(os.EOL);
13701414
command_1.issueCommand('set-output', { name }, value);
13711415
}
13721416
exports.setOutput = setOutput;
@@ -1537,11 +1581,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15371581
step((generator = generator.apply(thisArg, _arguments || [])).next());
15381582
});
15391583
};
1584+
var __importStar = (this && this.__importStar) || function (mod) {
1585+
if (mod && mod.__esModule) return mod;
1586+
var result = {};
1587+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1588+
result["default"] = mod;
1589+
return result;
1590+
};
15401591
var _a;
15411592
Object.defineProperty(exports, "__esModule", { value: true });
15421593
const assert_1 = __webpack_require__(357);
1543-
const fs = __webpack_require__(747);
1544-
const path = __webpack_require__(622);
1594+
const fs = __importStar(__webpack_require__(747));
1595+
const path = __importStar(__webpack_require__(622));
15451596
_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink;
15461597
exports.IS_WINDOWS = process.platform === 'win32';
15471598
function exists(fsPath) {
@@ -1746,8 +1797,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17461797
step((generator = generator.apply(thisArg, _arguments || [])).next());
17471798
});
17481799
};
1800+
var __importStar = (this && this.__importStar) || function (mod) {
1801+
if (mod && mod.__esModule) return mod;
1802+
var result = {};
1803+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1804+
result["default"] = mod;
1805+
return result;
1806+
};
17491807
Object.defineProperty(exports, "__esModule", { value: true });
1750-
const tr = __webpack_require__(9);
1808+
const tr = __importStar(__webpack_require__(9));
17511809
/**
17521810
* Exec a command.
17531811
* Output will be streamed to the live console.

index.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,25 @@ function formatReleaseMessage(releaseNumber) {
7575
"This is the first release";
7676
}
7777

78+
function addExtraFlagCleanCache(gigalixirClean) {
79+
return gigalixirClean ? ` -c http.extraheader="GIGALIXIR-CLEAN: true" ` : ""
80+
}
81+
7882
async function run() {
7983
try {
80-
const baseInputOptions = {
84+
const requiredInputOptions = {
8185
required: true
8286
};
83-
const gigalixirUsername = core.getInput('GIGALIXIR_USERNAME', baseInputOptions);
84-
const gigalixirPassword = core.getInput('GIGALIXIR_PASSWORD', baseInputOptions);
85-
const sshPrivateKey = core.getInput('SSH_PRIVATE_KEY', baseInputOptions);
86-
const gigalixirApp = core.getInput('GIGALIXIR_APP', baseInputOptions);
87-
const migrations = core.getInput('MIGRATIONS', baseInputOptions);
88-
const appSubfolder = core.getInput('APP_SUBFOLDER', { required: false });
87+
const optionalInputOptions = {
88+
required: false
89+
};
90+
const appSubfolder = core.getInput('APP_SUBFOLDER', optionalInputOptions);
91+
const gigalixirApp = core.getInput('GIGALIXIR_APP', requiredInputOptions);
92+
const gigalixirClean = core.getInput('GIGALIXIR_CLEAN', optionalInputOptions);
93+
const gigalixirUsername = core.getInput('GIGALIXIR_USERNAME', requiredInputOptions);
94+
const gigalixirPassword = core.getInput('GIGALIXIR_PASSWORD', requiredInputOptions);
95+
const migrations = core.getInput('MIGRATIONS', requiredInputOptions);
96+
const sshPrivateKey = core.getInput('SSH_PRIVATE_KEY', requiredInputOptions);
8997

9098
await core.group("Installing gigalixir", async () => {
9199
await exec.exec('pip3 install gigalixir')
@@ -107,9 +115,9 @@ async function run() {
107115

108116
await core.group("Deploying to gigalixir", async () => {
109117
if (appSubfolder) {
110-
await exec.exec(`git subtree push --prefix ${appSubfolder} gigalixir master`);
118+
await exec.exec(`git ${addExtraFlagCleanCache(gigalixirClean)} subtree push --prefix ${appSubfolder} gigalixir master`);
111119
} else {
112-
await exec.exec("git push -f gigalixir HEAD:refs/heads/master");
120+
await exec.exec(`git ${addExtraFlagCleanCache(gigalixirClean)} push -f gigalixir HEAD:refs/heads/master`);
113121
}
114122
});
115123

0 commit comments

Comments
 (0)