Skip to content

Commit cc2c0b0

Browse files
setup basic github action
1 parent de22d3c commit cc2c0b0

File tree

11 files changed

+458
-4
lines changed

11 files changed

+458
-4
lines changed

.github/workflows/main.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Run action locally'
2+
on: [push]
3+
jobs:
4+
run-lighthouse:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v1
8+
- name: Run Lighthouse
9+
uses: ./
10+
with:
11+
pages: ['https://treo.sh/']

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false,
4+
"printWidth": 120
5+
}

CONTRIBUTING.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# How to Contribute
2+
3+
First of all, thank you for your interest in `lighthouse-actions`!
4+
We'd love to accept your patches and contributions!
5+
6+
```bash
7+
# install deps
8+
npm install
9+
10+
# ensure all tests pass
11+
npm test
12+
13+
# build /dist for action distribution
14+
# more info: https://help.github.com/en/articles/creating-a-javascript-action#commit-and-push-your-action-to-github
15+
npm run build
16+
```

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# lighthouse-actions
22

3-
> Github actions integration for Lighthouse
3+
> Github actions integration for Lighthouse

action.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Lighthouse Actions'
2+
description: 'Run Lighthouse for the list of pages'
3+
inputs:
4+
pages:
5+
description: 'The list of pages'
6+
required: true
7+
default: []
8+
outputs:
9+
results:
10+
description: 'Lighthouse results paths'
11+
runs:
12+
using: 'node10'
13+
main: 'dist/index.js'

dist/index.js

+335
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
module.exports =
2+
/******/ (function(modules, runtime) { // webpackBootstrap
3+
/******/ "use strict";
4+
/******/ // The module cache
5+
/******/ var installedModules = {};
6+
/******/
7+
/******/ // The require function
8+
/******/ function __webpack_require__(moduleId) {
9+
/******/
10+
/******/ // Check if module is in cache
11+
/******/ if(installedModules[moduleId]) {
12+
/******/ return installedModules[moduleId].exports;
13+
/******/ }
14+
/******/ // Create a new module (and put it into the cache)
15+
/******/ var module = installedModules[moduleId] = {
16+
/******/ i: moduleId,
17+
/******/ l: false,
18+
/******/ exports: {}
19+
/******/ };
20+
/******/
21+
/******/ // Execute the module function
22+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
23+
/******/
24+
/******/ // Flag the module as loaded
25+
/******/ module.l = true;
26+
/******/
27+
/******/ // Return the exports of the module
28+
/******/ return module.exports;
29+
/******/ }
30+
/******/
31+
/******/
32+
/******/ __webpack_require__.ab = __dirname + "/";
33+
/******/
34+
/******/ // the startup function
35+
/******/ function startup() {
36+
/******/ // Load entry module and return exports
37+
/******/ return __webpack_require__(676);
38+
/******/ };
39+
/******/
40+
/******/ // run startup
41+
/******/ return startup();
42+
/******/ })
43+
/************************************************************************/
44+
/******/ ({
45+
46+
/***/ 87:
47+
/***/ (function(module) {
48+
49+
module.exports = require("os");
50+
51+
/***/ }),
52+
53+
/***/ 431:
54+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
55+
56+
"use strict";
57+
58+
Object.defineProperty(exports, "__esModule", { value: true });
59+
const os = __webpack_require__(87);
60+
/**
61+
* Commands
62+
*
63+
* Command Format:
64+
* ##[name key=value;key=value]message
65+
*
66+
* Examples:
67+
* ##[warning]This is the user warning message
68+
* ##[set-secret name=mypassword]definitelyNotAPassword!
69+
*/
70+
function issueCommand(command, properties, message) {
71+
const cmd = new Command(command, properties, message);
72+
process.stdout.write(cmd.toString() + os.EOL);
73+
}
74+
exports.issueCommand = issueCommand;
75+
function issue(name, message = '') {
76+
issueCommand(name, {}, message);
77+
}
78+
exports.issue = issue;
79+
const CMD_STRING = '::';
80+
class Command {
81+
constructor(command, properties, message) {
82+
if (!command) {
83+
command = 'missing.command';
84+
}
85+
this.command = command;
86+
this.properties = properties;
87+
this.message = message;
88+
}
89+
toString() {
90+
let cmdStr = CMD_STRING + this.command;
91+
if (this.properties && Object.keys(this.properties).length > 0) {
92+
cmdStr += ' ';
93+
for (const key in this.properties) {
94+
if (this.properties.hasOwnProperty(key)) {
95+
const val = this.properties[key];
96+
if (val) {
97+
// safely append the val - avoid blowing up when attempting to
98+
// call .replace() if message is not a string for some reason
99+
cmdStr += `${key}=${escape(`${val || ''}`)},`;
100+
}
101+
}
102+
}
103+
}
104+
cmdStr += CMD_STRING;
105+
// safely append the message - avoid blowing up when attempting to
106+
// call .replace() if message is not a string for some reason
107+
const message = `${this.message || ''}`;
108+
cmdStr += escapeData(message);
109+
return cmdStr;
110+
}
111+
}
112+
function escapeData(s) {
113+
return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A');
114+
}
115+
function escape(s) {
116+
return s
117+
.replace(/\r/g, '%0D')
118+
.replace(/\n/g, '%0A')
119+
.replace(/]/g, '%5D')
120+
.replace(/;/g, '%3B');
121+
}
122+
//# sourceMappingURL=command.js.map
123+
124+
/***/ }),
125+
126+
/***/ 470:
127+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
128+
129+
"use strict";
130+
131+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
132+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
133+
return new (P || (P = Promise))(function (resolve, reject) {
134+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
135+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
136+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
137+
step((generator = generator.apply(thisArg, _arguments || [])).next());
138+
});
139+
};
140+
Object.defineProperty(exports, "__esModule", { value: true });
141+
const command_1 = __webpack_require__(431);
142+
const os = __webpack_require__(87);
143+
const path = __webpack_require__(622);
144+
/**
145+
* The code to exit an action
146+
*/
147+
var ExitCode;
148+
(function (ExitCode) {
149+
/**
150+
* A code indicating that the action was successful
151+
*/
152+
ExitCode[ExitCode["Success"] = 0] = "Success";
153+
/**
154+
* A code indicating that the action was a failure
155+
*/
156+
ExitCode[ExitCode["Failure"] = 1] = "Failure";
157+
})(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
158+
//-----------------------------------------------------------------------
159+
// Variables
160+
//-----------------------------------------------------------------------
161+
/**
162+
* sets env variable for this action and future actions in the job
163+
* @param name the name of the variable to set
164+
* @param val the value of the variable
165+
*/
166+
function exportVariable(name, val) {
167+
process.env[name] = val;
168+
command_1.issueCommand('set-env', { name }, val);
169+
}
170+
exports.exportVariable = exportVariable;
171+
/**
172+
* exports the variable and registers a secret which will get masked from logs
173+
* @param name the name of the variable to set
174+
* @param val value of the secret
175+
*/
176+
function exportSecret(name, val) {
177+
exportVariable(name, val);
178+
// the runner will error with not implemented
179+
// leaving the function but raising the error earlier
180+
command_1.issueCommand('set-secret', {}, val);
181+
throw new Error('Not implemented.');
182+
}
183+
exports.exportSecret = exportSecret;
184+
/**
185+
* Prepends inputPath to the PATH (for this action and future actions)
186+
* @param inputPath
187+
*/
188+
function addPath(inputPath) {
189+
command_1.issueCommand('add-path', {}, inputPath);
190+
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
191+
}
192+
exports.addPath = addPath;
193+
/**
194+
* Gets the value of an input. The value is also trimmed.
195+
*
196+
* @param name name of the input to get
197+
* @param options optional. See InputOptions.
198+
* @returns string
199+
*/
200+
function getInput(name, options) {
201+
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
202+
if (options && options.required && !val) {
203+
throw new Error(`Input required and not supplied: ${name}`);
204+
}
205+
return val.trim();
206+
}
207+
exports.getInput = getInput;
208+
/**
209+
* Sets the value of an output.
210+
*
211+
* @param name name of the output to set
212+
* @param value value to store
213+
*/
214+
function setOutput(name, value) {
215+
command_1.issueCommand('set-output', { name }, value);
216+
}
217+
exports.setOutput = setOutput;
218+
//-----------------------------------------------------------------------
219+
// Results
220+
//-----------------------------------------------------------------------
221+
/**
222+
* Sets the action status to failed.
223+
* When the action exits it will be with an exit code of 1
224+
* @param message add error issue message
225+
*/
226+
function setFailed(message) {
227+
process.exitCode = ExitCode.Failure;
228+
error(message);
229+
}
230+
exports.setFailed = setFailed;
231+
//-----------------------------------------------------------------------
232+
// Logging Commands
233+
//-----------------------------------------------------------------------
234+
/**
235+
* Writes debug message to user log
236+
* @param message debug message
237+
*/
238+
function debug(message) {
239+
command_1.issueCommand('debug', {}, message);
240+
}
241+
exports.debug = debug;
242+
/**
243+
* Adds an error issue
244+
* @param message error issue message
245+
*/
246+
function error(message) {
247+
command_1.issue('error', message);
248+
}
249+
exports.error = error;
250+
/**
251+
* Adds an warning issue
252+
* @param message warning issue message
253+
*/
254+
function warning(message) {
255+
command_1.issue('warning', message);
256+
}
257+
exports.warning = warning;
258+
/**
259+
* Writes info to log with console.log.
260+
* @param message info message
261+
*/
262+
function info(message) {
263+
process.stdout.write(message + os.EOL);
264+
}
265+
exports.info = info;
266+
/**
267+
* Begin an output group.
268+
*
269+
* Output until the next `groupEnd` will be foldable in this group
270+
*
271+
* @param name The name of the output group
272+
*/
273+
function startGroup(name) {
274+
command_1.issue('group', name);
275+
}
276+
exports.startGroup = startGroup;
277+
/**
278+
* End an output group.
279+
*/
280+
function endGroup() {
281+
command_1.issue('endgroup');
282+
}
283+
exports.endGroup = endGroup;
284+
/**
285+
* Wrap an asynchronous function call in a group.
286+
*
287+
* Returns the same type as the function itself.
288+
*
289+
* @param name The name of the group
290+
* @param fn The function to wrap in the group
291+
*/
292+
function group(name, fn) {
293+
return __awaiter(this, void 0, void 0, function* () {
294+
startGroup(name);
295+
let result;
296+
try {
297+
result = yield fn();
298+
}
299+
finally {
300+
endGroup();
301+
}
302+
return result;
303+
});
304+
}
305+
exports.group = group;
306+
//# sourceMappingURL=core.js.map
307+
308+
/***/ }),
309+
310+
/***/ 622:
311+
/***/ (function(module) {
312+
313+
module.exports = require("path");
314+
315+
/***/ }),
316+
317+
/***/ 676:
318+
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
319+
320+
const core = __webpack_require__(470)
321+
322+
try {
323+
const pages = core.getInput('pages')
324+
console.log(pages)
325+
/** @type {string[]} */
326+
const results = []
327+
core.setOutput('results', JSON.stringify(results))
328+
} catch (error) {
329+
core.setFailed(error.message)
330+
}
331+
332+
333+
/***/ })
334+
335+
/******/ });

0 commit comments

Comments
 (0)