Skip to content
Open
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
207 changes: 207 additions & 0 deletions .github/workflows/next-build-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
name: Next.js build check

# Проверяет, что конечный пакет (packages/<pkg>) реально собирается внутри Next.js-приложения
# для конкретного build-варианта из его package.json#exports.
#
# Запуск:
# - комментарий в PR: /next-build <package> [build]
# (build не указан -> прогоняются все варианты из exports)
# - вручную через workflow_dispatch

on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
package:
description: 'Имя папки пакета под packages/, например sdds-serv'
required: true
type: string
build:
description: 'Ключ из exports, например "." или "styled-components". Пусто = все варианты.'
required: false
type: string

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.inputs.package }}
cancel-in-progress: true

jobs:
parse-command:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: read
outputs:
allowed: ${{ steps.parse.outputs.allowed }}
package: ${{ steps.parse.outputs.package }}
build: ${{ steps.parse.outputs.build }}
pr-number: ${{ steps.parse.outputs.pr-number }}
head-sha: ${{ steps.parse.outputs.head-sha }}
steps:
- name: Parse command and check authorization
id: parse
uses: actions/github-script@v9
with:
script: |
if (context.eventName === 'workflow_dispatch') {
core.setOutput('allowed', 'true');
core.setOutput('package', context.payload.inputs.package);
core.setOutput('build', context.payload.inputs.build || '');
core.setOutput('pr-number', '');
core.setOutput('head-sha', context.sha);

return;
}

const comment = context.payload.comment;
const issue = context.payload.issue;

if (!issue?.pull_request) {
core.setOutput('allowed', 'false');

return;
}

const match = comment.body.match(/^\/next-build\s+([A-Za-z0-9_-]+)(?:\s+(\S+))?\s*$/m);

if (!match) {
core.setOutput('allowed', 'false');

return;
}

const { data: access } = await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo,
username: comment.user.login,
});
const permissionLevels = {
none: 0,
read: 1,
triage: 2,
write: 3,
maintain: 4,
admin: 5,
};

if ((permissionLevels[access.permission] || 0) < permissionLevels.write) {
core.setOutput('allowed', 'false');
core.warning(
`/next-build triggered by ${comment.user.login} (${access.permission}) — not authorized, skipping.`,
);

return;
}

const { data: pr } = await github.rest.pulls.get({
...context.repo,
pull_number: issue.number,
});

core.setOutput('allowed', 'true');
core.setOutput('package', match[1]);
core.setOutput('build', match[2] || '');
core.setOutput('pr-number', String(issue.number));
core.setOutput('head-sha', pr.head.sha);

await github.rest.reactions.createForIssueComment({
...context.repo,
comment_id: comment.id,
content: 'eyes',
});

build:
name: Build (${{ needs.parse-command.outputs.package }} / ${{ needs.parse-command.outputs.build || 'all' }})
needs: parse-command
if: ${{ needs.parse-command.outputs.allowed == 'true' }}
runs-on: ubuntu-22.04
permissions:
contents: read
outputs:
results: ${{ steps.run-checks.outputs.results }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
ref: ${{ needs.parse-command.outputs.head-sha }}
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
package-manager-cache: false

- name: Validate package exists
env:
PKG: ${{ needs.parse-command.outputs.package }}
run: |
if [[ ! "$PKG" =~ ^[A-Za-z0-9_-]+$ ]]; then
echo "::error::Недопустимое имя пакета: $PKG"
exit 1
fi

if [ ! -f "packages/$PKG/package.json" ]; then
echo "::error::packages/$PKG не найден"
exit 1
fi

- name: Install dependencies and build target package
env:
PKG: ${{ needs.parse-command.outputs.package }}
run: npm run setup:ci -- --scope="@salutejs/$PKG" --include-dependencies

- name: Run Next.js build check(s)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
id: run-checks
env:
PKG: ${{ needs.parse-command.outputs.package }}
BUILD: ${{ needs.parse-command.outputs.build }}
run: |
set -e
STATUS=0
RESULTS_FILE=$(mktemp)

if [ -n "$BUILD" ]; then
KEYS="$BUILD"
else
KEYS=$(node -e "console.log(Object.keys(require('./packages/${PKG}/package.json').exports).join(' '))")
fi

for KEY in $KEYS; do
if npx ts-node --project utils/next-build-check/tsconfig.json utils/next-build-check/cli.ts --package="$PKG" --build="$KEY" --ci; then
echo "- ✅ \`$KEY\`" >> "$RESULTS_FILE"
else
echo "- ❌ \`$KEY\`" >> "$RESULTS_FILE"
STATUS=1
fi
done

{
echo "results<<NEXT_BUILD_RESULTS_EOF"
cat "$RESULTS_FILE"
echo "NEXT_BUILD_RESULTS_EOF"
} >> "$GITHUB_OUTPUT"

exit $STATUS

comment-result:
name: Report result
needs: [parse-command, build]
if: ${{ always() && github.event_name == 'issue_comment' && needs.parse-command.outputs.allowed == 'true' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ needs.parse-command.outputs.pr-number }}
header: Next.js build check
message: |
**Пакет:** `${{ needs.parse-command.outputs.package }}`
**Build:** `${{ needs.parse-command.outputs.build || 'все варианты из exports' }}`

${{ needs.build.outputs.results }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ s3_build
temp
**/.DS_Store
**/.swc
*.tgz
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cy:run": "node scripts/cy-run.js",
"cy:cli": "node scripts/cy-cli.js",
"cy:open": "cypress open --component --browser chromium",
"next:build": "ts-node --project utils/next-build-check/tsconfig.json utils/next-build-check/cli.ts",
"cy:report:coverage": "nyc report --reporter=cobertura --reporter=html",
"extract-docgen-info": "lerna run extract-docgen-info",
"lint:scripts": "eslint ./scripts ./auto-plugins/src --ext .js,.ts --quiet",
Expand Down
1 change: 1 addition & 0 deletions packages/plasma-b2c/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/plasma-giga/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/plasma-homeds/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/plasma-new-hope/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz

/ai-components-build-sb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Items = Array<{
В режиме `textfield-like` target внешне мимикрирует под компонент <b>TextField</b> и наследует все его свойства.

```tsx live
import React from 'react';
import React, { useState } from 'react';
import { Select } from '@salutejs/{{ package }}';

export function App() {
Expand Down
1 change: 1 addition & 0 deletions packages/plasma-web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-bizcom/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-dfa/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-finai/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-insol-next/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-insol/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-netology/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-os/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-platform-ai/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-sbcom/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
1 change: 1 addition & 0 deletions packages/sdds-scan/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
2 changes: 2 additions & 0 deletions packages/sdds-serv/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ emotion/es
styled-components/*
build-sb-draft
emotion/*
*.tgz
*.tgz
38 changes: 2 additions & 36 deletions scripts/cy-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,9 @@
const inquirer = require('inquirer');
const { spawnSync } = require('child_process');

const prompt = inquirer.prompt || inquirer.default?.prompt || inquirer.createPromptModule?.();
const { PACKAGES, PACKAGE_MAP } = require('./lib/final-packages');

const PACKAGES = [
'b2c',
'giga',
'web',
'cs',
'insol',
'insol-next',
'netology',
'bizcom',
'serv',
'scan',
'os',
'platform-ai',
'finai',
'dfa',
'homeds',
];

const PACKAGE_MAP = {
b2c: 'plasma-b2c',
giga: 'plasma-giga',
web: 'plasma-web',
cs: 'sdds-cs',
insol: 'sdds-insol',
'insol-next': 'sdds-insol-next',
netology: 'sdds-netology',
bizcom: 'sdds-bizcom',
serv: 'sdds-serv',
scan: 'sdds-scan',
os: 'sdds-os',
'platform-ai': 'sdds-platform-ai',
finai: 'sdds-finai',
dfa: 'sdds-dfa',
homeds: 'plasma-homeds',
};
const prompt = inquirer.prompt || inquirer.default?.prompt || inquirer.createPromptModule?.();

async function main() {
const { action } = await prompt([
Expand Down
2 changes: 2 additions & 0 deletions scripts/lib/final-packages.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const PACKAGES: string[];
export const PACKAGE_MAP: Record<string, string>;
37 changes: 37 additions & 0 deletions scripts/lib/final-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const PACKAGES = [
'b2c',
'giga',
'web',
'cs',
'insol',
'insol-next',
'netology',
'bizcom',
'serv',
'scan',
'os',
'platform-ai',
'finai',
'dfa',
'homeds',
];

const PACKAGE_MAP = {
b2c: 'plasma-b2c',
giga: 'plasma-giga',
web: 'plasma-web',
cs: 'sdds-cs',
insol: 'sdds-insol',
'insol-next': 'sdds-insol-next',
netology: 'sdds-netology',
bizcom: 'sdds-bizcom',
serv: 'sdds-serv',
scan: 'sdds-scan',
os: 'sdds-os',
'platform-ai': 'sdds-platform-ai',
finai: 'sdds-finai',
dfa: 'sdds-dfa',
homeds: 'plasma-homeds',
};

module.exports = { PACKAGES, PACKAGE_MAP };
Loading
Loading