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

Commit 9319a3b

Browse files
committed
Initial commit
0 parents  commit 9319a3b

File tree

5 files changed

+204
-0
lines changed

5 files changed

+204
-0
lines changed

.github/FUNDING.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These are supported funding model platforms
2+
3+
open_collective: sidvishnoi
4+
custom:
5+
- https://opencollective.com/respec

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Sid Vishnoi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ReSpec W3C Auto-Publish (GitHub Action)
2+
3+
This action lets you validate a ReSpec based spec and publish them to /TR/
4+
5+
## Inputs
6+
7+
Please see [action.yml](action.yml)
8+
9+
## Example Usage
10+
11+
``` yaml
12+
name: Node CI
13+
14+
on:
15+
push:
16+
branches:
17+
- gh-pages
18+
pull_request: {}
19+
20+
jobs:
21+
validate-and-publish:
22+
name: Validate and Publish
23+
runs-on: ubuntu-latest # only linux supported at present
24+
steps:
25+
- uses: actions/checkout@v1
26+
- uses: sidvishnoi/respec-w3c-auto-publish # use the action
27+
with:
28+
ECHIDNA_TOKEN: ${{ secrets.ECHIDNA_TOKEN }}
29+
GH_USER: ${{ secrets.GH_USER }} # optional
30+
GH_TOKEN: ${{ secrets.GH_TOKEN }} # optional
31+
URL: "https://w3c.github.io/gamepad/W3CTRMANIFEST"
32+
DECISION: "https://lists.w3.org/Archives/Public/public-webapps/2014JulSep/0627.html"
33+
34+
PUBLISH: ${{ github.event_name != 'pull_request' }} # publish only on merge (default: false)
35+
```

action.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'ReSpec W3C Auto-Publish'
2+
author: 'Sid Vishnoi'
3+
description: 'Validate ReSpec based specs and publish to /TR/'
4+
inputs:
5+
ECHIDNA_TOKEN:
6+
description: 'Echidna token'
7+
required: true
8+
GH_USER:
9+
description: 'GitHub user login. Used with respec-validator for API request quota limits.'
10+
required: false
11+
GH_TOKEN:
12+
description: 'GitHub user personal token. Used with respec-validator for API request quota limits.'
13+
required: false
14+
URL:
15+
description: 'TR Manfiest URL. Example: https://w3c.github.io/gamepad/W3CTRMANIFEST'
16+
required: true
17+
DECISION:
18+
description: 'Decision'
19+
required: true
20+
CC:
21+
description: "CC to email address"
22+
required: true
23+
PUBLISH:
24+
description: 'Whether to publish to /TR/ or not'
25+
required: false
26+
default: false
27+
runs:
28+
using: 'node12'
29+
main: 'index.js'

index.js

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const https = require('https');
2+
const { existsSync } = require('fs');
3+
const { spawn } = require('child_process');
4+
5+
// GitHub JavaScript Actions require we "must include any package dependencies
6+
// required to run the JavaScript code" - import node_modules in version control
7+
// or other weird things.
8+
// (https://help.github.com/en/articles/creating-a-javascript-action#commit-and-push-your-action-to-github).
9+
// To overcome that, we do `npm install` dynamically from within this script 🎉.
10+
let core; // this will become lazily imported '@actions/core'
11+
12+
main().catch(err => {
13+
core && core.setFailed(err);
14+
process.exit(1);
15+
});
16+
17+
async function main() {
18+
await install(['@actions/core']);
19+
core = require('@actions/core');
20+
21+
await core.group('Install dependencies', installDependencies);
22+
await core.group('Validate spec', validate);
23+
await core.group('Publish to /TR/', publish);
24+
}
25+
26+
async function installDependencies() {
27+
await install(['respec', 'respec-validator']);
28+
}
29+
30+
async function validate() {
31+
const file = 'index.html';
32+
33+
if (!existsSync(file)) {
34+
throw `❌ ${file} not found!`;
35+
}
36+
37+
const ghUser = core.getInput('GH_USER');
38+
const ghToken = core.getInput('GH_USER');
39+
40+
const validator = './node_modules/.bin/respec-validator';
41+
42+
if (!ghUser || !ghToken) {
43+
await shell(validator, [file]);
44+
} else {
45+
await shell(validator, [
46+
`--gh-user=${ghUser}`,
47+
`--gh-token=${ghToken}`,
48+
file
49+
]);
50+
}
51+
}
52+
53+
async function publish() {
54+
// PUBLISH could be 'false' or '0' or 0 or something like that... sanity check
55+
const shouldPublish = JSON.parse(`${core.getInput('PUBLISH')}`);
56+
if (!shouldPublish) {
57+
console.log('👻 Skipped.');
58+
return;
59+
}
60+
61+
console.log(
62+
'💁‍♂️ If it fails, check https://lists.w3.org/Archives/Public/public-tr-notifications/'
63+
);
64+
const res = await request('https://labs.w3.org/echidna/api/request', {
65+
method: 'POST',
66+
body: JSON.stringify({
67+
url: core.getInput('URL'),
68+
decision: core.getInput('DECISION'),
69+
token: core.getInput('ECHIDNA_TOKEN'),
70+
cc: core.getInput('CC')
71+
})
72+
});
73+
console.log(res);
74+
}
75+
76+
// Utils
77+
78+
function shell(command, args = [], options = {}) {
79+
return new Promise((resolve, reject) => {
80+
console.log(`💲 ${command} ${args.join(' ')}`);
81+
const child = spawn(command, args, { stdio: 'inherit', ...options });
82+
child.on('close', code => {
83+
if (code === 0) {
84+
resolve();
85+
} else {
86+
reject(`❌ The process exited with status code: ${code}`);
87+
}
88+
});
89+
});
90+
}
91+
92+
async function install(dependencies) {
93+
await shell('npm', ['install', '--quiet', ...dependencies]);
94+
}
95+
96+
function request(url, options) {
97+
return new Promise((resolve, reject) => {
98+
const req = https.request(url, options, res => {
99+
const chunks = [];
100+
res.on('data', data => chunks.push(data));
101+
res.on('end', () => {
102+
let body = Buffer.concat(chunks);
103+
if (res.headers['content-type'] === 'application/json') {
104+
body = JSON.parse(body);
105+
}
106+
resolve(body);
107+
});
108+
});
109+
110+
req.on('error', reject);
111+
if (options.body) req.write(options.body);
112+
req.end();
113+
});
114+
}

0 commit comments

Comments
 (0)