Skip to content

Commit 22c8c92

Browse files
committed
Initial attempt
1 parent 98b8b68 commit 22c8c92

File tree

4 files changed

+69
-57
lines changed

4 files changed

+69
-57
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
name: "units-test"
22
on:
3-
pull_request:
43
push:
54
branches:
65
- master
7-
- 'releases/*'
86

97
jobs:
10-
# unit tests
11-
units:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v1
15-
- run: npm ci
16-
- run: npm test
17-
188
# test action works running from the graph
199
test:
2010
runs-on: ubuntu-latest
2111
steps:
2212
- uses: actions/checkout@v1
2313
- uses: ./
2414
with:
25-
milliseconds: 1000
15+
fileName: 'myTemporaryFile.txt'
16+
encodedString: ${{ secrets.SOME_ENCODED_STRING }} # SGVsbG8sIFdvcmxkIQ==

action.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
name: 'Wait'
2-
description: 'Wait a designated number of milliseconds'
1+
name: 'base64-to-file'
2+
description: 'Takes a base64-encoded string and writes to a file.'
3+
branding:
4+
color: 'blue'
5+
icon: 'file'
36
inputs:
4-
milliseconds: # id of input
5-
description: 'number of milliseconds to wait'
7+
fileName:
8+
description: 'Name of the file when written to temp location'
9+
required: true
10+
default: 'decoded-file.file'
11+
encodedString:
12+
description: 'The base64 encoded string'
613
required: true
7-
default: '1000'
814
outputs:
9-
time: # output will be available to future steps
10-
description: 'The message to output'
15+
filePath:
16+
description: 'The temp file location'
1117
runs:
1218
using: 'node12'
1319
main: 'dist/index.js'

dist/index.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,32 @@ module.exports = require("os");
5353
/***/ 104:
5454
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
5555

56-
const core = __webpack_require__(470);
57-
const wait = __webpack_require__(949);
58-
59-
60-
// most @actions toolkit packages have async methods
61-
async function run() {
62-
try {
63-
const ms = core.getInput('milliseconds');
64-
console.log(`Waiting ${ms} milliseconds ...`)
65-
66-
core.debug((new Date()).toTimeString())
67-
wait(parseInt(ms));
68-
core.debug((new Date()).toTimeString())
69-
70-
core.setOutput('time', new Date().toTimeString());
71-
}
72-
catch (error) {
73-
core.setFailed(error.message);
74-
}
75-
}
76-
77-
run()
56+
const core = __webpack_require__(470);
57+
const wait = __webpack_require__(949);
58+
const fs = __webpack_require__(747);
59+
60+
// get input parameter values from config
61+
var fileName = env['TEMP'] + '\\'+ core.getInput('fileName');
62+
var encodedString = core.getInput('encodedString');
63+
64+
// most @actions toolkit packages have async methods
65+
async function run() {
66+
try {
67+
const tempFile = Buffer.from(encodedString, 'base64');
68+
69+
if (certificate.length == 0)
70+
core.setFailed('Certificate value is not set');
71+
72+
await fs.writeFile(fileName, tempFile);
73+
74+
core.setOutput('filePath', fileName);
75+
}
76+
catch (error) {
77+
core.setFailed(error.message);
78+
}
79+
}
80+
81+
run()
7882

7983

8084
/***/ }),
@@ -343,20 +347,27 @@ module.exports = require("path");
343347

344348
/***/ }),
345349

346-
/***/ 949:
350+
/***/ 747:
347351
/***/ (function(module) {
348352

349-
let wait = function(milliseconds) {
350-
return new Promise((resolve, reject) => {
351-
if (typeof(milliseconds) !== 'number') {
352-
throw new Error('milleseconds not a number');
353-
}
353+
module.exports = require("fs");
354+
355+
/***/ }),
354356

355-
setTimeout(() => resolve("done!"), milliseconds)
356-
});
357-
}
357+
/***/ 949:
358+
/***/ (function(module) {
358359

359-
module.exports = wait;
360+
let wait = function(milliseconds) {
361+
return new Promise((resolve, reject) => {
362+
if (typeof(milliseconds) !== 'number') {
363+
throw new Error('milleseconds not a number');
364+
}
365+
366+
setTimeout(() => resolve("done!"), milliseconds)
367+
});
368+
}
369+
370+
module.exports = wait;
360371

361372

362373
/***/ })

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
const core = require('@actions/core');
22
const wait = require('./wait');
3+
const fs = require('fs');
34

5+
// get input parameter values from config
6+
var fileName = env['TEMP'] + '\\'+ core.getInput('fileName');
7+
var encodedString = core.getInput('encodedString');
48

59
// most @actions toolkit packages have async methods
610
async function run() {
711
try {
8-
const ms = core.getInput('milliseconds');
9-
console.log(`Waiting ${ms} milliseconds ...`)
12+
const tempFile = Buffer.from(encodedString, 'base64');
13+
14+
if (certificate.length == 0)
15+
core.setFailed('Certificate value is not set');
16+
17+
await fs.writeFile(fileName, tempFile);
1018

11-
core.debug((new Date()).toTimeString())
12-
wait(parseInt(ms));
13-
core.debug((new Date()).toTimeString())
14-
15-
core.setOutput('time', new Date().toTimeString());
19+
core.setOutput('filePath', fileName);
1620
}
1721
catch (error) {
1822
core.setFailed(error.message);

0 commit comments

Comments
 (0)