Skip to content

Commit

Permalink
testing custom action
Browse files Browse the repository at this point in the history
  • Loading branch information
Uroš Marolt committed Jan 9, 2024
1 parent 6ffb59c commit ca768fb
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 1 deletion.
173 changes: 173 additions & 0 deletions .github/actions/node/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,126 @@ function isLoopbackAddress(host) {
}
//# sourceMappingURL=proxy.js.map

/***/ }),

/***/ 8248:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

/* @flow */
/*::

type DotenvParseOptions = {
debug?: boolean
}

// keys and values from src
type DotenvParseOutput = { [string]: string }

type DotenvConfigOptions = {
path?: string, // path to .env file
encoding?: string, // encoding of .env file
debug?: string // turn on logging for debugging purposes
}

type DotenvConfigOutput = {
parsed?: DotenvParseOutput,
error?: Error
}

*/

const fs = __nccwpck_require__(7147)
const path = __nccwpck_require__(1017)

function log (message /*: string */) {
console.log(`[dotenv][DEBUG] ${message}`)
}

const NEWLINE = '\n'
const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/
const RE_NEWLINES = /\\n/g
const NEWLINES_MATCH = /\n|\r|\r\n/

// Parses src into an Object
function parse (src /*: string | Buffer */, options /*: ?DotenvParseOptions */) /*: DotenvParseOutput */ {
const debug = Boolean(options && options.debug)
const obj = {}

// convert Buffers before splitting into lines and processing
src.toString().split(NEWLINES_MATCH).forEach(function (line, idx) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
const keyValueArr = line.match(RE_INI_KEY_VAL)
// matched?
if (keyValueArr != null) {
const key = keyValueArr[1]
// default undefined or missing values to empty string
let val = (keyValueArr[2] || '')
const end = val.length - 1
const isDoubleQuoted = val[0] === '"' && val[end] === '"'
const isSingleQuoted = val[0] === "'" && val[end] === "'"

// if single or double quoted, remove quotes
if (isSingleQuoted || isDoubleQuoted) {
val = val.substring(1, end)

// if double quoted, expand newlines
if (isDoubleQuoted) {
val = val.replace(RE_NEWLINES, NEWLINE)
}
} else {
// remove surrounding whitespace
val = val.trim()
}

obj[key] = val
} else if (debug) {
log(`did not match key and value when parsing line ${idx + 1}: ${line}`)
}
})

return obj
}

// Populates process.env from .env file
function config (options /*: ?DotenvConfigOptions */) /*: DotenvConfigOutput */ {
let dotenvPath = path.resolve(process.cwd(), '.env')
let encoding /*: string */ = 'utf8'
let debug = false

if (options) {
if (options.path != null) {
dotenvPath = options.path
}
if (options.encoding != null) {
encoding = options.encoding
}
if (options.debug != null) {
debug = true
}
}

try {
// specifying an encoding returns a string instead of a buffer
const parsed = parse(fs.readFileSync(dotenvPath, { encoding }), { debug })

Object.keys(parsed).forEach(function (key) {
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
process.env[key] = parsed[key]
} else if (debug) {
log(`"${key}" is already defined in \`process.env\` and will not be overwritten`)
}
})

return { parsed }
} catch (e) {
return { error: e }
}
}

module.exports.config = config
module.exports.parse = parse


/***/ }),

/***/ 8672:
Expand Down Expand Up @@ -24735,11 +24855,16 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const inputs_1 = __nccwpck_require__(2117);
const state_1 = __nccwpck_require__(5034);
const core = __importStar(__nccwpck_require__(3949));
const utils_1 = __nccwpck_require__(7407);
/**
* Runs the action
*/
async function run() {
const inputs = await (0, inputs_1.loadInputs)();
const builderDefinitions = await (0, utils_1.loadBuilderDefinitions)();
for (const def of builderDefinitions) {
core.info(`Loaded builder definition: ${JSON.stringify(def)}`);
}
for (const step of inputs.steps) {
core.info(`Running step: ${step}`);
}
Expand Down Expand Up @@ -24913,6 +25038,54 @@ var ActionStep;
})(ActionStep || (exports.ActionStep = ActionStep = {}));


/***/ }),

/***/ 7407:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.loadBuilderDefinitions = void 0;
const dotenv_1 = __importDefault(__nccwpck_require__(8248));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const loadBuilderDefinitions = async () => {
const results = [];
const files = fs_1.default.readdirSync('./scripts/builders');
for (const result of files) {
if (result.endsWith('.env')) {
const content = fs_1.default.readFileSync(`./scripts/builders/${result}`, 'utf-8');
const parsed = dotenv_1.default.parse(content);
const imageName = result.split('.env')[0];
const dockerRepository = parsed.REPO;
let services = [];
if (parsed.SERVICES !== undefined) {
services = parsed.SERVICES.split(' ')
.map((s) => s.trim())
.filter((s) => s.length > 0);
}
let prioritizedServices = [];
if (parsed.PRIORITIZED !== undefined) {
prioritizedServices = parsed.PRIORITIZED.split(' ')
.map((s) => s.trim())
.filter((s) => s.length > 0);
}
results.push({
imageName,
dockerRepository,
services,
prioritizedServices,
});
}
}
return results;
};
exports.loadBuilderDefinitions = loadBuilderDefinitions;


/***/ }),

/***/ 9491:
Expand Down
6 changes: 6 additions & 0 deletions .github/actions/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { loadInputs } from './inputs'
import { IS_POST } from './state'
import * as core from '@actions/core'
import { loadBuilderDefinitions } from './utils'
/**
* Runs the action
*/
async function run() {
const inputs = await loadInputs()

const builderDefinitions = await loadBuilderDefinitions()
for (const def of builderDefinitions) {
core.info(`Loaded builder definition: ${JSON.stringify(def)}`)
}

for (const step of inputs.steps) {
core.info(`Running step: ${step}`)
}
Expand Down
7 changes: 7 additions & 0 deletions .github/actions/node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export interface IDeployInput {
services: string[]
}

export interface IBuilderDefinition {
imageName: string
dockerRepository: string
services: string[]
prioritizedServices: string[]
}

export type IActionInputs = {
steps: ActionStep[]
[ActionStep.BUILD]?: IBuildInput
Expand Down
41 changes: 40 additions & 1 deletion .github/actions/node/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
import * as exec from '@actions/exec'
import dotenv from 'dotenv'
import { IBuilderDefinition } from './types'
import fs from 'fs'

export const loadBuilderDefinitions = async (): Promise<IBuilderDefinition[]> => {
const results: IBuilderDefinition[] = []
const files = fs.readdirSync('./scripts/builders')

for (const result of files) {
if (result.endsWith('.env')) {
const content = fs.readFileSync(`./scripts/builders/${result}`, 'utf-8')
const parsed = dotenv.parse(content)

const imageName = result.split('.env')[0]
const dockerRepository = parsed.REPO
let services: string[] = []
if (parsed.SERVICES !== undefined) {
services = parsed.SERVICES.split(' ')
.map((s) => s.trim())
.filter((s) => s.length > 0)
}

let prioritizedServices: string[] = []
if (parsed.PRIORITIZED !== undefined) {
prioritizedServices = parsed.PRIORITIZED.split(' ')
.map((s) => s.trim())
.filter((s) => s.length > 0)
}

results.push({
imageName,
dockerRepository,
services,
prioritizedServices,
})
}
}

return results
}

0 comments on commit ca768fb

Please sign in to comment.