mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
ci: use danger diff to get master data
This commit is contained in:
parent
ef972cf38f
commit
61e1aeeb36
4 changed files with 18 additions and 57 deletions
|
|
@ -1,9 +1,22 @@
|
||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
const { fail, markdown, message, schedule } = require('danger');
|
const { danger, fail, markdown, message, schedule } = require('danger');
|
||||||
const validate = require('./scripts/data-validate');
|
const validate = require('./scripts/data-validate');
|
||||||
|
|
||||||
|
const DATA_FILE = 'src/data.js';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const { data: changedData, errorMsgs, failedUrls } = await validate();
|
if (!danger.git.modified_files.includes(DATA_FILE)) {
|
||||||
|
message(`No changes in \`${DATA_FILE}\``);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const diff = await danger.git.diffForFile(DATA_FILE);
|
||||||
|
// eslint-disable-next-line no-eval
|
||||||
|
const masterData = eval(diff.before);
|
||||||
|
|
||||||
|
const { data: changedData, errorMsgs, failedUrls } = await validate(
|
||||||
|
masterData
|
||||||
|
);
|
||||||
|
|
||||||
// If there are errors, will fail the action & add a comment detailing the issues
|
// If there are errors, will fail the action & add a comment detailing the issues
|
||||||
if (errorMsgs.length) {
|
if (errorMsgs.length) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
const { getMasterData, Schema, getStatusCode } = require('./utils.js');
|
const { Schema, getStatusCode } = require('./utils.js');
|
||||||
const srcData = require('../src/data.js');
|
const srcData = require('../src/data.js');
|
||||||
|
|
||||||
async function main() {
|
async function main(masterData = []) {
|
||||||
// on master branch will be empty array
|
const masterDataUrls = masterData.map(d => d.url);
|
||||||
const masterDataUrls = (await getMasterData()).map(d => d.url);
|
|
||||||
// so here data will be an array with all users
|
// so here data will be an array with all users
|
||||||
const data = srcData.filter(d => !masterDataUrls.includes(d.url));
|
const data = srcData.filter(d => !masterDataUrls.includes(d.url));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
/**
|
|
||||||
* this is a stub file, do not edit it
|
|
||||||
* see `scripts/utils.js` -> `getMasterData`
|
|
||||||
*/
|
|
||||||
module.exports = [];
|
|
||||||
|
|
@ -1,54 +1,8 @@
|
||||||
const exec = require('@actions/exec');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
const Joi = require('@hapi/joi');
|
const Joi = require('@hapi/joi');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const flags = require('./flags.js');
|
const flags = require('./flags.js');
|
||||||
|
|
||||||
async function getCurrentBranchName() {
|
|
||||||
let myOutput = '';
|
|
||||||
let myError = '';
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
silent: true,
|
|
||||||
listeners: {
|
|
||||||
stdout: data => (myOutput += data.toString()),
|
|
||||||
stderr: data => (myError += data.toString()),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
await exec.exec('git rev-parse --abbrev-ref HEAD', [], options);
|
|
||||||
return myOutput.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** on master branch will return an empty array */
|
|
||||||
module.exports.getMasterData = async function() {
|
|
||||||
const options = { silent: true };
|
|
||||||
const curentBranchName = await getCurrentBranchName();
|
|
||||||
// when on a branch/PR different from master
|
|
||||||
// will populate scripts/masterData.js with src/data.js from master
|
|
||||||
if (curentBranchName !== 'master') {
|
|
||||||
core.info('Executing action on branch different from master');
|
|
||||||
await exec.exec('mv src/data.js src/tmpData.js', [], options);
|
|
||||||
await exec.exec('git fetch origin master', [], options);
|
|
||||||
await exec.exec('git restore --source=FETCH_HEAD src/data.js', [], options);
|
|
||||||
await exec.exec('mv src/data.js scripts/masterData.js', [], options);
|
|
||||||
await exec.exec('mv src/tmpData.js src/data.js', [], options);
|
|
||||||
} else {
|
|
||||||
core.info('Executing action on master branch');
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line global-require
|
|
||||||
const masterData = require('./masterData.js');
|
|
||||||
|
|
||||||
// restore `scripts/masterData.js` after was loaded
|
|
||||||
if (curentBranchName !== 'master') {
|
|
||||||
await exec.exec('git restore scripts/masterData.js', [], options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return masterData;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.Schema = Joi.object({
|
module.exports.Schema = Joi.object({
|
||||||
name: Joi.string().required(),
|
name: Joi.string().required(),
|
||||||
description: Joi.string().required(),
|
description: Joi.string().required(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue