Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: init pnpm workspace #84

Closed
wants to merge 10 commits into from
Closed
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
!.github
node_modules/
dist
56 changes: 56 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
root: true,
env: {
es2020: true,
browser: true,
node: true,
},
extends: [
'plugin:@typescript-eslint/recommended',
'eslint:recommended',
'plugin:import/typescript',
'plugin:jsx-a11y/recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
ecmaFeatures: { jsx: true },
},
plugins: [
'html',
'node',
'@typescript-eslint',
'jest',
'@typescript-eslint',
'simple-import-sort',
],
rules: {
'no-param-reassign': 'error',
'no-use-before-define': 'off',
'no-underscore-dangle': 'off',
'no-implicit-coercion': ['error', { allow: ['!!'] }],
'block-scoped-var': 'error',
'no-shadow': 'warn',
'no-unsafe-optional-chaining': ['error', { disallowArithmeticOperators: true }],
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'no-return-assign': 'warn',
'consistent-return': 'off',
'no-redeclare': 'error',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'import/prefer-default-export': 'off',
'jsx-a11y/anchor-is-valid': 'warn',
'jsx-a11y/no-noninteractive-tabindex': 'warn',
'jsx-a11y/tabindex-no-positive': 'warn',
'jsx-a11y/click-events-have-key-events': 'warn',
'jsx-a11y/no-static-element-interactions': 'warn',
'jsx-a11y/no-noninteractive-element-interactions': 'warn',
// TODO: Re-ctivate rule when we have a custom logger
'no-console': 'off',
'no-empty': ['error', { allowEmptyCatch: true }],
'@typescript-eslint/no-explicit-any': 'off',
},
ignorePatterns: ['**/dist/**', '**/dev/**', '**/coverage/**', '**/temp/**'],
};
104 changes: 0 additions & 104 deletions .eslintrc.json

This file was deleted.

10 changes: 5 additions & 5 deletions .github/actions/constants.cjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const BADGE =
'<img src="https://img.shields.io/badge/{{ CONCLUSION }}-{{ BADGE_COLOR }}?style=for-the-badge&label={{ BADGE_LABEL }}" alt="Badge" />'
const BROWSERS = ['chrome', 'firefox', 'opera', 'edge']
'<img src="https://img.shields.io/badge/{{ CONCLUSION }}-{{ BADGE_COLOR }}?style=for-the-badge&label={{ BADGE_LABEL }}" alt="Badge" />';
const BROWSERS = ['chrome', 'firefox', 'opera', 'edge'];
const COLORS = {
green: '3fb950',
red: 'd73a49',
}
};
const TEMPLATE_VARS = {
tableBody: '{{ TABLE_BODY }}',
sha: '{{ SHA }}',
conslusion: '{{ CONCLUSION }}',
badgeColor: '{{ BADGE_COLOR }}',
badgeLabel: '{{ BADGE_LABEL }}',
jobLogs: '{{ JOB_LOGS }}',
}
};

module.exports = {
BADGE,
BROWSERS,
COLORS,
TEMPLATE_VARS,
}
};
40 changes: 20 additions & 20 deletions .github/actions/delete-artifacts.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
const { BROWSERS } = require('./constants.cjs')
const { BROWSERS } = require('./constants.cjs');

async function getBrowserArfifacts({ github, owner, repo, name }) {
const artifacts = []
const artifacts = [];
const result = await github.rest.actions.listArtifactsForRepo({
owner,
repo,
name,
})
});

for (let i = 0; i < result.data.total_count; i++) {
artifacts.push(result.data.artifacts[i].id)
artifacts.push(result.data.artifacts[i].id);
}

return artifacts
return artifacts;
}

async function getPRArtifacts({ github, owner, repo, prNumber }) {
const promises = []
const artifacts = []
const promises = [];
const artifacts = [];

BROWSERS.forEach(browser =>
promises.push(
Expand All @@ -30,27 +30,27 @@ async function getPRArtifacts({ github, owner, repo, prNumber }) {
name: `${prNumber}-${browser}`,
}),
),
)
);

const data = await Promise.all(promises)
const data = await Promise.all(promises);

for (let i = 0; i < data.length; i++) {
artifacts.push.apply(artifacts, data[i])
artifacts.push.apply(artifacts, data[i]);
}

return artifacts
return artifacts;
}

module.exports = async ({ github, context, core }) => {
if (context.payload.action !== 'closed') {
core.setFailed('This action only works on closed PRs.')
core.setFailed('This action only works on closed PRs.');
}

const { owner, repo } = context.repo
const prNumber = context.payload.number
const promises = []
const { owner, repo } = context.repo;
const prNumber = context.payload.number;
const promises = [];

const artifacts = await getPRArtifacts({ github, owner, repo, prNumber })
const artifacts = await getPRArtifacts({ github, owner, repo, prNumber });

for (let i = 0; i < artifacts.length; i++) {
promises.push(
Expand All @@ -59,9 +59,9 @@ module.exports = async ({ github, context, core }) => {
repo,
artifact_id: artifacts[i],
}),
)
);
}

await Promise.all(promises)
console.log(`Deleted ${artifacts.length} artifacts for PR #${prNumber}.`)
}
await Promise.all(promises);
console.log(`Deleted ${artifacts.length} artifacts for PR #${prNumber}.`);
};
76 changes: 38 additions & 38 deletions .github/actions/get-workflow-artifacts.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
const fs = require('node:fs/promises')
const { COLORS, TEMPLATE_VARS, BADGE } = require('./constants.cjs')
const fs = require('node:fs/promises');
const { COLORS, TEMPLATE_VARS, BADGE } = require('./constants.cjs');

const ARTIFACTS_DATA = {
chrome: {
Expand All @@ -24,73 +24,73 @@ const ARTIFACTS_DATA = {
url: null,
size: null,
},
}
};

function getBadge(conclusion, badgeColor, badgeLabel) {
return BADGE.replace(TEMPLATE_VARS.conslusion, conclusion)
.replace(TEMPLATE_VARS.badgeColor, badgeColor)
.replace(TEMPLATE_VARS.badgeLabel, badgeLabel)
.replace(TEMPLATE_VARS.badgeLabel, badgeLabel);
}

function formatBytes(bytes, decimals = 2) {
if (!Number(bytes)) return '0B'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['B', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`
if (!Number(bytes)) return '0B';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`;
}

module.exports = async ({ github, context, core }) => {
const { owner, repo } = context.repo
const baseUrl = context.payload.repository.html_url
const suiteId = context.payload.workflow_run.check_suite_id
const runId = context.payload.workflow_run.id
const conclusion = context.payload.workflow_run.conclusion
const sha = context.payload.workflow_run.pull_requests[0].head.sha
const prNumber = context.payload.workflow_run.pull_requests[0].number
const jobLogsUrl = `${baseUrl}/actions/runs/${context.payload.workflow_run.id}`
const template = await fs.readFile('./.github/actions/templates/build-status.md', 'utf8')
const tableRows = []
const { owner, repo } = context.repo;
const baseUrl = context.payload.repository.html_url;
const suiteId = context.payload.workflow_run.check_suite_id;
const runId = context.payload.workflow_run.id;
const conclusion = context.payload.workflow_run.conclusion;
const sha = context.payload.workflow_run.pull_requests[0].head.sha;
const prNumber = context.payload.workflow_run.pull_requests[0].number;
const jobLogsUrl = `${baseUrl}/actions/runs/${context.payload.workflow_run.id}`;
const template = await fs.readFile('./.github/actions/templates/build-status.md', 'utf8');
const tableRows = [];

core.setOutput('conclusion', conclusion)
core.setOutput('conclusion', conclusion);

if (conclusion === 'cancelled') {
return
return;
}

const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runId,
})
});

artifacts.data.artifacts.forEach(artifact => {
const [, key] = artifact.name.split('-')
ARTIFACTS_DATA[key].url = `${baseUrl}/suites/${suiteId}/artifacts/${artifact.id}`
ARTIFACTS_DATA[key].size = formatBytes(artifact.size_in_bytes)
})
const [, key] = artifact.name.split('-');
ARTIFACTS_DATA[key].url = `${baseUrl}/suites/${suiteId}/artifacts/${artifact.id}`;
ARTIFACTS_DATA[key].size = formatBytes(artifact.size_in_bytes);
});

Object.keys(ARTIFACTS_DATA).forEach(k => {
const { name, url, size } = ARTIFACTS_DATA[k]
const { name, url, size } = ARTIFACTS_DATA[k];
if (url === null && size === null) {
const badgeUrl = getBadge('failure', COLORS.red, name)
tableRows.push(`<tr><td align="center">${badgeUrl}</td><td align="center">N/A</td></tr>`)
const badgeUrl = getBadge('failure', COLORS.red, name);
tableRows.push(`<tr><td align="center">${badgeUrl}</td><td align="center">N/A</td></tr>`);
} else {
const badgeUrl = getBadge('success', COLORS.green, `${name} (${size})`)
const badgeUrl = getBadge('success', COLORS.green, `${name} (${size})`);
tableRows.push(
`<tr><td align="center">${badgeUrl}</td><td align="center"><a href="${url}">Download</a></td></tr>`,
)
);
}
})
});

const tableBody = tableRows.join('')
const tableBody = tableRows.join('');
const commentBody = template
.replace(TEMPLATE_VARS.conslusion, conclusion)
.replace(TEMPLATE_VARS.sha, sha)
.replace(TEMPLATE_VARS.jobLogs, `<a href="${jobLogsUrl}">Run #${runId}</a>`)
.replace(TEMPLATE_VARS.tableBody, tableBody)
.replace(TEMPLATE_VARS.tableBody, tableBody);

core.setOutput('comment_body', commentBody)
core.setOutput('pr_number', prNumber)
}
core.setOutput('comment_body', commentBody);
core.setOutput('pr_number', prNumber);
};
Loading
Loading