Skip to content

Commit ec7b4ec

Browse files
style: use semicolons, trailing comma with prettier (#539)
Co-authored-by: Sid Vishnoi <[email protected]>
1 parent fb893a7 commit ec7b4ec

Some content is hidden

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

90 files changed

+3560
-3526
lines changed
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// @ts-check
22
/* eslint-disable @typescript-eslint/no-require-imports, no-console */
3-
const fs = require('node:fs/promises')
3+
const fs = require('node:fs/promises');
44

55
/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */
66
module.exports = async ({ core }) => {
7-
const manifestPath = './src/manifest.json'
8-
const manifestFile = await fs.readFile(manifestPath, 'utf8')
9-
const manifest = JSON.parse(manifestFile)
7+
const manifestPath = './src/manifest.json';
8+
const manifestFile = await fs.readFile(manifestPath, 'utf8');
9+
const manifest = JSON.parse(manifestFile);
1010
/**@type {string} */
11-
const existingVersion = manifest.version
11+
const existingVersion = manifest.version;
1212

13-
const bumpType = /** @type {BumpType} */ (process.env.INPUT_VERSION)
13+
const bumpType = /** @type {BumpType} */ (process.env.INPUT_VERSION);
1414
if (!bumpType) {
15-
throw new Error('Missing bump type')
15+
throw new Error('Missing bump type');
1616
}
1717

18-
const version = bumpVersion(existingVersion, bumpType).join('.')
18+
const version = bumpVersion(existingVersion, bumpType).join('.');
1919

20-
console.log({ existingVersion, bumpType, version })
20+
console.log({ existingVersion, bumpType, version });
2121

22-
manifest.version = version
23-
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2))
24-
core.setOutput('version', version)
25-
}
22+
manifest.version = version;
23+
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
24+
core.setOutput('version', version);
25+
};
2626

2727
/**
2828
* @typedef {'build' | 'patch' | 'minor'} BumpType
@@ -31,20 +31,20 @@ module.exports = async ({ core }) => {
3131
* @return {[major: number, minor: number, patch: number, build: number]}
3232
*/
3333
function bumpVersion(existingVersion, type) {
34-
const parts = existingVersion.split('.').map(Number)
34+
const parts = existingVersion.split('.').map(Number);
3535
if (parts.length !== 4 || parts.some((e) => !Number.isSafeInteger(e))) {
36-
throw new Error('Existing version does not have right format')
36+
throw new Error('Existing version does not have right format');
3737
}
38-
const [major, minor, patch, build] = parts
38+
const [major, minor, patch, build] = parts;
3939

4040
switch (type) {
4141
case 'build':
42-
return [major, minor, patch, build + 1]
42+
return [major, minor, patch, build + 1];
4343
case 'patch':
44-
return [major, minor, patch + 1, 0]
44+
return [major, minor, patch + 1, 0];
4545
case 'minor':
46-
return [major, minor + 1, 0, 0]
46+
return [major, minor + 1, 0, 0];
4747
default:
48-
throw new Error('Unknown bump type: ' + type)
48+
throw new Error('Unknown bump type: ' + type);
4949
}
5050
}

.github/actions/constants.cjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
*/
66

77
const BADGE =
8-
'<img src="https://img.shields.io/badge/{{ CONCLUSION }}-{{ BADGE_COLOR }}?style=for-the-badge&label={{ BADGE_LABEL }}" alt="Badge" />'
8+
'<img src="https://img.shields.io/badge/{{ CONCLUSION }}-{{ BADGE_COLOR }}?style=for-the-badge&label={{ BADGE_LABEL }}" alt="Badge" />';
99
/** @type {Browser[]} */
10-
const BROWSERS = ['chrome', 'firefox']
10+
const BROWSERS = ['chrome', 'firefox'];
1111
const COLORS = {
1212
green: '3fb950',
13-
red: 'd73a49'
14-
}
13+
red: 'd73a49',
14+
};
1515
const TEMPLATE_VARS = {
1616
tableBody: '{{ TABLE_BODY }}',
1717
sha: '{{ SHA }}',
1818
conclusion: '{{ CONCLUSION }}',
1919
badgeColor: '{{ BADGE_COLOR }}',
2020
badgeLabel: '{{ BADGE_LABEL }}',
21-
jobLogs: '{{ JOB_LOGS }}'
22-
}
21+
jobLogs: '{{ JOB_LOGS }}',
22+
};
2323

2424
module.exports = {
2525
BADGE,
2626
BROWSERS,
2727
COLORS,
28-
TEMPLATE_VARS
29-
}
28+
TEMPLATE_VARS,
29+
};

.github/actions/delete-artifacts.cjs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
/* eslint-disable @typescript-eslint/no-require-imports, no-console */
3-
const { BROWSERS } = require('./constants.cjs')
3+
const { BROWSERS } = require('./constants.cjs');
44

55
/**
66
* @param {Pick<import('github-script').AsyncFunctionArguments, 'github' | 'context'>} AsyncFunctionArguments
@@ -10,9 +10,9 @@ async function getBrowserArtifacts({ github, context }, name) {
1010
const result = await github.rest.actions.listArtifactsForRepo({
1111
owner: context.repo.owner,
1212
repo: context.repo.repo,
13-
name
14-
})
15-
return result.data.artifacts
13+
name,
14+
});
15+
return result.data.artifacts;
1616
}
1717

1818
/**
@@ -22,40 +22,40 @@ async function getBrowserArtifacts({ github, context }, name) {
2222
async function getPRArtifacts({ github, context }, prNumber) {
2323
const data = await Promise.all(
2424
BROWSERS.map((browser) =>
25-
getBrowserArtifacts({ github, context }, `${prNumber}-${browser}`)
26-
)
27-
)
25+
getBrowserArtifacts({ github, context }, `${prNumber}-${browser}`),
26+
),
27+
);
2828

2929
/** @type {{id: number}[]} */
30-
const artifacts = []
30+
const artifacts = [];
3131
for (let i = 0; i < data.length; i++) {
3232
// same as `artifacts.push(...data[i])` but it's a bit faster
33-
artifacts.push.apply(artifacts, data[i])
33+
artifacts.push.apply(artifacts, data[i]);
3434
}
35-
return artifacts
35+
return artifacts;
3636
}
3737

3838
/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */
3939
module.exports = async ({ github, context, core }) => {
4040
if (context.payload.action !== 'closed') {
41-
core.setFailed('This action only works on closed PRs.')
41+
core.setFailed('This action only works on closed PRs.');
4242
}
4343

44-
const { owner, repo } = context.repo
44+
const { owner, repo } = context.repo;
4545
/** @type {number} */
46-
const prNumber = context.payload.number
46+
const prNumber = context.payload.number;
4747

48-
const artifacts = await getPRArtifacts({ github, context }, prNumber)
48+
const artifacts = await getPRArtifacts({ github, context }, prNumber);
4949

5050
await Promise.all(
5151
artifacts.map((artifact) =>
5252
github.rest.actions.deleteArtifact({
5353
owner,
5454
repo,
55-
artifact_id: artifact.id
56-
})
57-
)
58-
)
55+
artifact_id: artifact.id,
56+
}),
57+
),
58+
);
5959

60-
console.log(`Deleted ${artifacts.length} artifacts for PR #${prNumber}.`)
61-
}
60+
console.log(`Deleted ${artifacts.length} artifacts for PR #${prNumber}.`);
61+
};

.github/actions/get-built-version.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
/* eslint-disable @typescript-eslint/no-require-imports */
3-
const fs = require('node:fs/promises')
3+
const fs = require('node:fs/promises');
44

55
/**
66
* Retrieves the manifest version from the built extension.
@@ -9,7 +9,7 @@ const fs = require('node:fs/promises')
99
module.exports = async ({ core }) => {
1010
const manifest = await fs
1111
.readFile('./dist/chrome/manifest.json', 'utf8')
12-
.then(JSON.parse)
12+
.then(JSON.parse);
1313

14-
core.setOutput('version', manifest.version)
15-
}
14+
core.setOutput('version', manifest.version);
15+
};
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
/* eslint-disable @typescript-eslint/no-require-imports, no-console */
3-
const fs = require('node:fs/promises')
4-
const { COLORS, TEMPLATE_VARS, BADGE } = require('./constants.cjs')
3+
const fs = require('node:fs/promises');
4+
const { COLORS, TEMPLATE_VARS, BADGE } = require('./constants.cjs');
55

66
/**
77
* @typedef {import('./constants.cjs').Browser} Browser
@@ -12,14 +12,14 @@ const ARTIFACTS_DATA = {
1212
chrome: {
1313
name: 'Chrome',
1414
url: '',
15-
size: ''
15+
size: '',
1616
},
1717
firefox: {
1818
name: 'Firefox',
1919
url: '',
20-
size: ''
21-
}
22-
}
20+
size: '',
21+
},
22+
};
2323

2424
/**
2525
* @param {string} conclusion
@@ -29,81 +29,81 @@ const ARTIFACTS_DATA = {
2929
function getBadge(conclusion, badgeColor, badgeLabel) {
3030
return BADGE.replace(TEMPLATE_VARS.conclusion, conclusion)
3131
.replace(TEMPLATE_VARS.badgeColor, badgeColor)
32-
.replace(TEMPLATE_VARS.badgeLabel, badgeLabel)
32+
.replace(TEMPLATE_VARS.badgeLabel, badgeLabel);
3333
}
3434

3535
/**
3636
* @param {number} bytes
3737
* @param {number} decimals
3838
*/
3939
function formatBytes(bytes, decimals = 2) {
40-
if (!Number(bytes)) return '0B'
41-
const k = 1024
42-
const dm = decimals < 0 ? 0 : decimals
43-
const sizes = ['B', 'KB', 'MB', 'GB']
44-
const i = Math.floor(Math.log(bytes) / Math.log(k))
45-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`
40+
if (!Number(bytes)) return '0B';
41+
const k = 1024;
42+
const dm = decimals < 0 ? 0 : decimals;
43+
const sizes = ['B', 'KB', 'MB', 'GB'];
44+
const i = Math.floor(Math.log(bytes) / Math.log(k));
45+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`;
4646
}
4747

4848
/** @param {import('github-script').AsyncFunctionArguments} AsyncFunctionArguments */
4949
module.exports = async ({ github, context, core }) => {
50-
const { owner, repo } = context.repo
51-
const baseUrl = context.payload.repository?.html_url
52-
const suiteId = context.payload.workflow_run.check_suite_id
53-
const runId = context.payload.workflow_run.id
54-
const conclusion = context.payload.workflow_run.conclusion
55-
const sha = context.payload.workflow_run.pull_requests[0].head.sha
56-
const prNumber = context.payload.workflow_run.pull_requests[0].number
57-
const jobLogsUrl = `${baseUrl}/actions/runs/${context.payload.workflow_run.id}`
50+
const { owner, repo } = context.repo;
51+
const baseUrl = context.payload.repository?.html_url;
52+
const suiteId = context.payload.workflow_run.check_suite_id;
53+
const runId = context.payload.workflow_run.id;
54+
const conclusion = context.payload.workflow_run.conclusion;
55+
const sha = context.payload.workflow_run.pull_requests[0].head.sha;
56+
const prNumber = context.payload.workflow_run.pull_requests[0].number;
57+
const jobLogsUrl = `${baseUrl}/actions/runs/${context.payload.workflow_run.id}`;
5858
const template = await fs.readFile(
5959
'./.github/actions/templates/build-status.md',
60-
'utf8'
61-
)
60+
'utf8',
61+
);
6262

6363
/** @type {string[]} */
64-
const tableRows = []
64+
const tableRows = [];
6565

66-
core.setOutput('conclusion', conclusion)
66+
core.setOutput('conclusion', conclusion);
6767

6868
if (conclusion === 'cancelled') {
69-
return
69+
return;
7070
}
7171

7272
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
7373
owner,
7474
repo,
75-
run_id: runId
76-
})
75+
run_id: runId,
76+
});
7777

7878
artifacts.data.artifacts.forEach((artifact) => {
79-
const key = /** @type {Browser} */ (artifact.name.split('-')[1])
79+
const key = /** @type {Browser} */ (artifact.name.split('-')[1]);
8080
ARTIFACTS_DATA[key].url =
81-
`${baseUrl}/suites/${suiteId}/artifacts/${artifact.id}`
82-
ARTIFACTS_DATA[key].size = formatBytes(artifact.size_in_bytes)
83-
})
81+
`${baseUrl}/suites/${suiteId}/artifacts/${artifact.id}`;
82+
ARTIFACTS_DATA[key].size = formatBytes(artifact.size_in_bytes);
83+
});
8484

8585
Object.keys(ARTIFACTS_DATA).forEach((k) => {
86-
const { name, url, size } = ARTIFACTS_DATA[/** @type {Browser} */ (k)]
86+
const { name, url, size } = ARTIFACTS_DATA[/** @type {Browser} */ (k)];
8787
if (!url && !size) {
88-
const badgeUrl = getBadge('failure', COLORS.red, name)
88+
const badgeUrl = getBadge('failure', COLORS.red, name);
8989
tableRows.push(
90-
`<tr><td align="center">${badgeUrl}</td><td align="center">N/A</td></tr>`
91-
)
90+
`<tr><td align="center">${badgeUrl}</td><td align="center">N/A</td></tr>`,
91+
);
9292
} else {
93-
const badgeUrl = getBadge('success', COLORS.green, `${name} (${size})`)
93+
const badgeUrl = getBadge('success', COLORS.green, `${name} (${size})`);
9494
tableRows.push(
95-
`<tr><td align="center">${badgeUrl}</td><td align="center"><a href="${url}">Download</a></td></tr>`
96-
)
95+
`<tr><td align="center">${badgeUrl}</td><td align="center"><a href="${url}">Download</a></td></tr>`,
96+
);
9797
}
98-
})
98+
});
9999

100-
const tableBody = tableRows.join('')
100+
const tableBody = tableRows.join('');
101101
const commentBody = template
102102
.replace(TEMPLATE_VARS.conclusion, conclusion)
103103
.replace(TEMPLATE_VARS.sha, sha)
104104
.replace(TEMPLATE_VARS.jobLogs, `<a href="${jobLogsUrl}">Run #${runId}</a>`)
105-
.replace(TEMPLATE_VARS.tableBody, tableBody)
105+
.replace(TEMPLATE_VARS.tableBody, tableBody);
106106

107-
core.setOutput('comment_body', commentBody)
108-
core.setOutput('pr_number', prNumber)
109-
}
107+
core.setOutput('comment_body', commentBody);
108+
core.setOutput('pr_number', prNumber);
109+
};

.github/actions/validate-stable-release.cjs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,36 @@
77
*/
88
module.exports = async ({ github, context }) => {
99
if (context.ref !== 'refs/heads/main') {
10-
throw new Error('This action only works on main branch')
10+
throw new Error('This action only works on main branch');
1111
}
1212

13-
const { owner, repo } = context.repo
14-
const previewVersionTag = process.env.INPUT_VERSION
13+
const { owner, repo } = context.repo;
14+
const previewVersionTag = process.env.INPUT_VERSION;
1515
if (!previewVersionTag) {
16-
throw new Error('Missing env.INPUT_VERSION')
16+
throw new Error('Missing env.INPUT_VERSION');
1717
}
1818
if (!previewVersionTag.match(/^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+-preview$/)) {
19-
throw new Error('Input "version" must match vX.X.X.X-preview')
19+
throw new Error('Input "version" must match vX.X.X.X-preview');
2020
}
2121

22-
const versionTag = previewVersionTag.replace('-preview', '')
22+
const versionTag = previewVersionTag.replace('-preview', '');
2323
try {
2424
await github.rest.repos.getReleaseByTag({
2525
owner,
2626
repo,
27-
tag: versionTag
28-
})
29-
throw new Error('Release already promoted to stable')
27+
tag: versionTag,
28+
});
29+
throw new Error('Release already promoted to stable');
3030
} catch (error) {
3131
if (!error.status) {
32-
throw error
32+
throw error;
3333
}
3434
if (error.status === 404) {
3535
// do nothing
3636
} else {
37-
throw new Error(`Failed to check: HTTP ${error.status}`, { cause: error })
37+
throw new Error(`Failed to check: HTTP ${error.status}`, {
38+
cause: error,
39+
});
3840
}
3941
}
40-
}
42+
};

0 commit comments

Comments
 (0)