Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

feat: display specberus errors in more friendly way #17

Merged
merged 1 commit into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const https = require('https');
const { existsSync } = require('fs');
const { spawn } = require('child_process');
const core = require('@actions/core');
const { issueCommand } = require('@actions/core/lib/command');

const ECHIDNA_SUCCESS_STATUS = 'success';
const ECHIDNA_FAILURE_STATUS = 'failure';
Expand Down Expand Up @@ -62,6 +63,7 @@ async function publish() {
token: core.getInput('ECHIDNA_TOKEN', { required: true }),
cc: core.getInput('CC'),
};
const file = core.getInput('INPUT_FILE');
core.setSecret(data.token);

const body = new URLSearchParams(Object.entries(data)).toString();
Expand All @@ -78,8 +80,13 @@ async function publish() {
switch (result.status) {
case ECHIDNA_SUCCESS_STATUS:
return core.info(`🎉 Published at: ${result.url}`);
case ECHIDNA_FAILURE_STATUS:
case ECHIDNA_FAILURE_STATUS: {
for (const { message, id, name } of getSpecberusErrors(result.response)) {
const msg = `echidna/specberus:\n\t${name}/${id}:\n\t${message}`;
issueCommand('error', { file, line: '1' }, msg);
}
throw new Error('💥 Echidna publish has failed.');
}
default:
core.warning('🚧 Echidna publish job is pending.');
}
Expand Down Expand Up @@ -131,6 +138,23 @@ async function getPublishStatus(id) {
return state;
}

function getSpecberusErrors(response) {
let errors = [];
let profile;
try {
profile = response.results.metadata.profile;
errors = response.results.jobs.specberus.errors || [];
} catch (err) {
console.error(err);
return [];
}

const specberus = require('./specberus/messages.js');
return errors.map(({ type, key, extra }) =>
specberus.getMessage(profile, type, key, extra),
);
}

// Utils

function shell(command, args = [], options = {}) {
Expand Down
6 changes: 6 additions & 0 deletions specberus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# This script updates specberus rules and messages.
set -ex
cd specberus
curl -O https://raw.githubusercontent.com/w3c/specberus/master/lib/rules.json
curl -O https://raw.githubusercontent.com/w3c/specberus/master/lib/l10n-en_GB.js
Loading