From 22c8c92cdf69029e280667dfe63c378e0fb4ef90 Mon Sep 17 00:00:00 2001 From: Tim Heuer Date: Sat, 14 Dec 2019 13:30:28 -0800 Subject: [PATCH] Initial attempt --- .github/workflows/test.yml | 13 +------ action.yml | 20 ++++++---- dist/index.js | 77 ++++++++++++++++++++++---------------- index.js | 18 +++++---- 4 files changed, 70 insertions(+), 58 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af0b35e..59afcbf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,20 +1,10 @@ name: "units-test" on: - pull_request: push: branches: - master - - 'releases/*' jobs: - # unit tests - units: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - run: npm ci - - run: npm test - # test action works running from the graph test: runs-on: ubuntu-latest @@ -22,4 +12,5 @@ jobs: - uses: actions/checkout@v1 - uses: ./ with: - milliseconds: 1000 + fileName: 'myTemporaryFile.txt' + encodedString: ${{ secrets.SOME_ENCODED_STRING }} # SGVsbG8sIFdvcmxkIQ== diff --git a/action.yml b/action.yml index 110d5ca..42c2b52 100644 --- a/action.yml +++ b/action.yml @@ -1,13 +1,19 @@ -name: 'Wait' -description: 'Wait a designated number of milliseconds' +name: 'base64-to-file' +description: 'Takes a base64-encoded string and writes to a file.' +branding: + color: 'blue' + icon: 'file' inputs: - milliseconds: # id of input - description: 'number of milliseconds to wait' + fileName: + description: 'Name of the file when written to temp location' + required: true + default: 'decoded-file.file' + encodedString: + description: 'The base64 encoded string' required: true - default: '1000' outputs: - time: # output will be available to future steps - description: 'The message to output' + filePath: + description: 'The temp file location' runs: using: 'node12' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index c83bf9f..2486fc1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -53,28 +53,32 @@ module.exports = require("os"); /***/ 104: /***/ (function(__unusedmodule, __unusedexports, __webpack_require__) { -const core = __webpack_require__(470); -const wait = __webpack_require__(949); - - -// most @actions toolkit packages have async methods -async function run() { - try { - const ms = core.getInput('milliseconds'); - console.log(`Waiting ${ms} milliseconds ...`) - - core.debug((new Date()).toTimeString()) - wait(parseInt(ms)); - core.debug((new Date()).toTimeString()) - - core.setOutput('time', new Date().toTimeString()); - } - catch (error) { - core.setFailed(error.message); - } -} - -run() +const core = __webpack_require__(470); +const wait = __webpack_require__(949); +const fs = __webpack_require__(747); + +// get input parameter values from config +var fileName = env['TEMP'] + '\\'+ core.getInput('fileName'); +var encodedString = core.getInput('encodedString'); + +// most @actions toolkit packages have async methods +async function run() { + try { + const tempFile = Buffer.from(encodedString, 'base64'); + + if (certificate.length == 0) + core.setFailed('Certificate value is not set'); + + await fs.writeFile(fileName, tempFile); + + core.setOutput('filePath', fileName); + } + catch (error) { + core.setFailed(error.message); + } +} + +run() /***/ }), @@ -343,20 +347,27 @@ module.exports = require("path"); /***/ }), +/***/ 747: +/***/ (function(module) { + +module.exports = require("fs"); + +/***/ }), + /***/ 949: /***/ (function(module) { -let wait = function(milliseconds) { - return new Promise((resolve, reject) => { - if (typeof(milliseconds) !== 'number') { - throw new Error('milleseconds not a number'); - } - - setTimeout(() => resolve("done!"), milliseconds) - }); -} - -module.exports = wait; +let wait = function(milliseconds) { + return new Promise((resolve, reject) => { + if (typeof(milliseconds) !== 'number') { + throw new Error('milleseconds not a number'); + } + + setTimeout(() => resolve("done!"), milliseconds) + }); +} + +module.exports = wait; /***/ }) diff --git a/index.js b/index.js index ee57a25..f4e312a 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,22 @@ const core = require('@actions/core'); const wait = require('./wait'); +const fs = require('fs'); +// get input parameter values from config +var fileName = env['TEMP'] + '\\'+ core.getInput('fileName'); +var encodedString = core.getInput('encodedString'); // most @actions toolkit packages have async methods async function run() { try { - const ms = core.getInput('milliseconds'); - console.log(`Waiting ${ms} milliseconds ...`) + const tempFile = Buffer.from(encodedString, 'base64'); + + if (certificate.length == 0) + core.setFailed('Certificate value is not set'); + + await fs.writeFile(fileName, tempFile); - core.debug((new Date()).toTimeString()) - wait(parseInt(ms)); - core.debug((new Date()).toTimeString()) - - core.setOutput('time', new Date().toTimeString()); + core.setOutput('filePath', fileName); } catch (error) { core.setFailed(error.message);