Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 82eca2e

Browse files
authoredJun 6, 2022
housekeeping after migration (#431)
* houskeeping after migration * fix * add check for file permissions * fix * fix * fix
1 parent 5e687c8 commit 82eca2e

File tree

64 files changed

+1084
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1084
-291
lines changed
 
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
if [ "$(uname)" == "Darwin" ]; then
5+
# Darwin cmd
6+
find . -type f -perm +0111 | node .github/bin/detect-executable-files/to-github-annotations.js
7+
else
8+
# Linux cmd
9+
find . -type f -perm /u=x,g=x,o=x | node .github/bin/detect-executable-files/to-github-annotations.js
10+
fi
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const fs = require('fs');
2+
const data = fs.readFileSync(0, 'utf-8');
3+
let fileNames = data.split(/\r?\n/);
4+
5+
const allowList = [];
6+
7+
fileNames = fileNames.filter((f) => {
8+
if (0 === f.length) {
9+
return false; // trailing newline
10+
}
11+
12+
if (f.includes('node_modules')) {
13+
return false; // node_modules folders are not distributed
14+
}
15+
16+
if (f.startsWith('./.git/')) {
17+
return false; // git stuffs
18+
}
19+
20+
if (f.startsWith('./.github/')) {
21+
return false; // these are not distributed
22+
}
23+
24+
if (f.endsWith('dist/cli.cjs')) {
25+
return false; // this is expected to be executable
26+
}
27+
28+
return !allowList.includes(f);
29+
});
30+
31+
if (!fileNames || !fileNames.length) {
32+
process.exit(0);
33+
}
34+
35+
if (!process.env.GITHUB_ACTIONS) {
36+
console.log(`Unexpected executables:`);
37+
fileNames.forEach((f) => {
38+
console.log(`chmod a-x ${f}`);
39+
});
40+
process.exit(1);
41+
}
42+
43+
fileNames.forEach((f) => {
44+
const annotation = formatGitHubActionAnnotation(
45+
`This file is unexpectedly executable`,
46+
'error',
47+
{
48+
file: f,
49+
line: 1,
50+
col: 1,
51+
}
52+
);
53+
54+
console.log(annotation);
55+
});
56+
57+
process.exit(1);
58+
59+
function formatGitHubActionAnnotation(message, level = 'error', options = {}) {
60+
let output = '::' + level;
61+
62+
const outputOptions = Object.keys(options)
63+
.map((key) => {
64+
return `${key}=${escape(String(options[key]))}`;
65+
})
66+
.join(',');
67+
68+
if (outputOptions) {
69+
output += ` ${outputOptions}`;
70+
}
71+
72+
return `${output}::${escapeData(message || '')}`;
73+
}
74+
75+
function escapeData(s) {
76+
return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A');
77+
}
78+
79+
function escape(s) {
80+
return s
81+
.replace(/\r/g, '%0D')
82+
.replace(/\n/g, '%0A')
83+
.replace(/]/g, '%5D')
84+
.replace(/;/g, '%3B');
85+
}

0 commit comments

Comments
 (0)
Please sign in to comment.