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

plasma-infra: Refactoring deploy documentations artefacts [PR context] #1125

Merged
merged 9 commits into from
Mar 21, 2024
Merged
13 changes: 13 additions & 0 deletions .github/config-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"PACKAGES_CYPRESS": ["plasma-web", "plasma-b2c", "plasma-ui"],
"PACKAGES_DS": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а что такое DS ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yeti-or design system типа вертикаль.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не, это не вертикали же. Это именно библиотеки

"plasma-web",
"plasma-b2c",
"plasma-ui",
"plasma-new-hope",
"plasma-asdk",
"caldera",
"caldera-online",
"sdds-serv"
]
}
13 changes: 13 additions & 0 deletions .github/create-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = () => {
const { PACKAGES_DS, BASE_URL } = process.env;

const links = JSON.parse(PACKAGES_DS)
.map((item) => {
const name = item.replace('plasma-', '');

return `${name} storybook: ${BASE_URL}/${name}-storybook/`;
})
.join('\n');

return 'Documentation preview deployed!' + '\n\n' + `website:${BASE_URL}/` + '\n' + `${links}`;
};
108 changes: 45 additions & 63 deletions .github/processing-scope.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,76 @@
const CYPRESS_SCOPE = ['@salutejs/plasma-web', '@salutejs/plasma-b2c', '@salutejs/plasma-ui'];
// INFO: HAS_ASSETS - это флаг для управления логикой "@auto-it" плагина upload-assets-extend
// INFO: Изменения в plasma-tokens или plasma-tokens-utils так же повлияют на то что в packagesList окажется plasma-tokens-native

/**
* Define CI config
* @typedef {object} json
* @property {Array<string>} PACKAGES_CYPRESS
* @property {Array<string>} PACKAGES_DS
*/
const CONFIG = require('./config-ci.json');

module.exports = () => {
const { CHANGED_STATE, AS_ENUMERATION } = process.env;
const { RAW_DATA } = process.env;

/**
*
* @param CHANGED_STATE Information about the changed state
* @param CHANGED_STATE.name The name of the package.
* @param CHANGED_STATE.version The version of the package.
* @param CHANGED_STATE.private The type of the package.
* @param CHANGED_STATE.location The path of the package.
* @param RAW_DATA Information about the changed state
* @param RAW_DATA.name The name of the package.
* @param RAW_DATA.version The version of the package.
* @param RAW_DATA.private The type of the package.
* @param RAW_DATA.location The path of the package.
*
* @example
* {
* "name": "@salutejs/plasma-website",
* "version": "0.184.0",
* "private": true,
* "location": "/Users/workspace/plasma/website/plasma-website"
* "location": ".../plasma/website/plasma-website"
* }
*/
const changedState = JSON.parse(JSON.parse(CHANGED_STATE));
const rawData = JSON.parse(RAW_DATA).map(({ name }) => name);

if (!changedState || !changedState.length) {
return { SCOPE: [], HAS_SCOPE: false };
if (!rawData || !rawData.length) {
return {
RAW_DATA: [],
PACKAGES_CYPRESS_RUN: [],
PACKAGES_DOCUMENTATIONS_RUN: [],
PROCESSED_DATA: [],
HAS_PACKAGES_CYPRESS_RUN: false,
HAS_PACKAGES_DS_CHANGES: false,
HAS_ASSETS: false,
};
}

/**
* Processed data - packages name without "@salutejs/"
* @example
* ['@salutejs/plasma-ui-docs', '@salutejs/plasma-ui', '@salutejs/plasma-core']
* ["plasma-web", "plasma-ui", "caldera"]
*/
const packagesList = changedState.map(({ name }) => name);

const HAS_PLASMA_UI_DOCS = packagesList.includes('@salutejs/plasma-ui-docs');
const HAS_PLASMA_WEB_DOCS = packagesList.includes('@salutejs/plasma-web-docs');

const HAS_PLASMA_UI = packagesList.includes('@salutejs/plasma-ui');
const HAS_PLASMA_WEB = packagesList.includes('@salutejs/plasma-web');
const HAS_PLASMA_B2C = packagesList.includes('@salutejs/plasma-b2c');
const HAS_PLASMA_HOPE = packagesList.includes('@salutejs/plasma-new-hope');
const HAS_PLASMA_ASDK = packagesList.includes('@salutejs/plasma-asdk');
const HAS_CALDERA = packagesList.includes('@salutejs/caldera');
const HAS_CALDERA_ONLINE = packagesList.includes('@salutejs/caldera-online');
const HAS_SDDS_SERV = packagesList.includes('@salutejs/sdds-serv');
const HAS_PLASMA_WEBSITE = packagesList.includes('@salutejs/plasma-website');

const HAS_DOCUMENTATION_CHANGED =
HAS_PLASMA_WEBSITE ||
HAS_PLASMA_UI_DOCS ||
HAS_PLASMA_WEB_DOCS ||
HAS_PLASMA_ASDK ||
HAS_CALDERA ||
HAS_CALDERA_ONLINE ||
HAS_SDDS_SERV;

// Флаг для управления логикой "@auto-it" плагина upload-assets-extend
// Изменения в plasma-tokens или plasma-tokens-utils так же повлияют на то что в packagesList окажется plasma-tokens-native
const HAS_ASSETS = packagesList.includes('@salutejs/plasma-tokens-native');
const PROCESSED_DATA = rawData.map((item) => item.replace('@salutejs/', ''));

/**
* List short packages name
* List short packages name for run cypress test
* @example
* ["web", "ui", "b2c"]
*/
const scope = packagesList.filter((item) => CYPRESS_SCOPE.includes(item)).map((item) => `"${item.split('-')[1]}"`);
const PACKAGES_CYPRESS_RUN = PROCESSED_DATA.filter((item) => CONFIG.PACKAGES_CYPRESS.includes(item)).map((item) =>
item.replace('plasma-', ''),
);

/**
* Enumeration packages name
* List packages who has a documentations artifacts: storybook, docusaurus
* @example
* ["plasma-web", "plasma-ui", "plasma-b2c"]
* ["plasma-web", "caldera", "sdds-serv"]
*/
const packagesEnumeration = AS_ENUMERATION === 'true' ? packagesList.map((item) => `"${item.split('/')[1]}"`) : [];

console.log('packagesEnumeration =>', packagesEnumeration);
console.log('packagesList =>', packagesList);
const PACKAGES_DOCUMENTATIONS_RUN = PROCESSED_DATA.filter((item) => CONFIG.PACKAGES_DS.includes(item));

return {
SCOPE: JSON.stringify(scope),
PACKAGES_ENUMERATION: JSON.stringify(packagesEnumeration),
HAS_SCOPE: Boolean(scope.length),
HAS_DOCUMENTATION_CHANGED,
HAS_PLASMA_UI_DOCS,
HAS_PLASMA_WEB_DOCS,
HAS_PLASMA_UI,
HAS_PLASMA_WEB,
HAS_PLASMA_B2C,
HAS_PLASMA_HOPE,
HAS_PLASMA_ASDK,
HAS_ASSETS,
HAS_CALDERA,
HAS_CALDERA_ONLINE,
HAS_SDDS_SERV,
RAW_DATA: JSON.stringify(rawData),
PACKAGES_DOCUMENTATIONS_RUN: JSON.stringify(PACKAGES_DOCUMENTATIONS_RUN),
PACKAGES_CYPRESS_RUN: JSON.stringify(PACKAGES_CYPRESS_RUN),
PROCESSED_DATA: JSON.stringify(PROCESSED_DATA),
HAS_PACKAGES_CYPRESS_RUN: Boolean(PACKAGES_CYPRESS_RUN.length),
HAS_PACKAGES_DS_CHANGES: Boolean(PACKAGES_DOCUMENTATIONS_RUN.length),
HAS_ASSETS: PROCESSED_DATA.includes('plasma-tokens-native'),
};
};
96 changes: 10 additions & 86 deletions .github/workflows/change-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,19 @@ on:
description: 'Lerna boostrap filter-option, exclude all transitive dependents when running a command with --since'
default: false
type: boolean
as-enumeration:
description: 'Get scope as "[plasma-core,plasma-ui]", etc'
default: false
type: boolean
ref:
type: string
description: "Manual set repo ref"
default: ''
outputs:
SCOPE:
description: "scope collection"
value: ${{ jobs.run.outputs.SCOPE }}
HAS_SCOPE:
description: "has scope"
value: ${{ jobs.run.outputs.HAS_SCOPE }}
HAS_DOCUMENTATION_CHANGED:
description: ""
value: ${{ jobs.run.outputs.HAS_DOCUMENTATION_CHANGED }}
HAS_PLASMA_UI_DOCS:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_UI_DOCS }}
HAS_PLASMA_WEB_DOCS:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_WEB_DOCS }}
HAS_PLASMA_UI:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_UI }}
HAS_PLASMA_WEB:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_WEB }}
HAS_PLASMA_B2C:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_B2C }}
HAS_PLASMA_HOPE:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_HOPE }}
HAS_PLASMA_ASDK:
description: ""
value: ${{ jobs.run.outputs.HAS_PLASMA_ASDK }}
HAS_CALDERA:
description: ""
value: ${{ jobs.run.outputs.HAS_CALDERA }}
HAS_CALDERA_ONLINE:
description: ""
value: ${{ jobs.run.outputs.HAS_CALDERA_ONLINE }}
HAS_SDDS_SERV:
description: ""
value: ${{ jobs.run.outputs.HAS_SDDS_SERV }}
HAS_ASSETS:
description: ""
value: ${{ jobs.run.outputs.HAS_ASSETS }}
PACKAGES_ENUMERATION:
description: ""
value: ${{ jobs.run.outputs.PACKAGES_ENUMERATION }}
STATE:
description: "state based on changed state of lerna packages"
value: ${{ jobs.run.outputs.STATE }}
jobs:
run:
runs-on: ubuntu-latest
outputs:
SCOPE: ${{ steps.set-output.outputs.SCOPE }}
HAS_SCOPE: ${{ steps.set-output.outputs.HAS_SCOPE }}
HAS_DOCUMENTATION_CHANGED: ${{ steps.set-output.outputs.HAS_DOCUMENTATION_CHANGED }}
HAS_PLASMA_UI_DOCS: ${{ steps.set-output.outputs.HAS_PLASMA_UI_DOCS }}
HAS_PLASMA_WEB_DOCS: ${{ steps.set-output.outputs.HAS_PLASMA_WEB_DOCS }}
HAS_PLASMA_B2C: ${{ steps.set-output.outputs.HAS_PLASMA_B2C }}
HAS_PLASMA_WEB: ${{ steps.set-output.outputs.HAS_PLASMA_WEB }}
HAS_PLASMA_UI: ${{ steps.set-output.outputs.HAS_PLASMA_UI }}
HAS_PLASMA_HOPE: ${{ steps.set-output.outputs.HAS_PLASMA_HOPE }}
HAS_PLASMA_ASDK: ${{ steps.set-output.outputs.HAS_PLASMA_ASDK }}
HAS_CALDERA: ${{ steps.set-output.outputs.HAS_CALDERA }}
HAS_CALDERA_ONLINE: ${{ steps.set-output.outputs.HAS_CALDERA_ONLINE }}
HAS_SDDS_SERV: ${{ steps.set-output.outputs.HAS_SDDS_SERV }}
HAS_ASSETS: ${{ steps.set-output.outputs.HAS_ASSETS }}
PACKAGES_ENUMERATION: ${{ steps.set-output.outputs.PACKAGES_ENUMERATION }}
STATE: ${{ steps.set-output.outputs.STATE }}

steps:
- uses: actions/checkout@v4
Expand All @@ -96,18 +36,16 @@ jobs:
run: echo "EXCLUDE_DEPENDENTS=--exclude-dependents" >> $GITHUB_ENV

- name: Get lerna ls output
shell: bash
id: changed-state
id: lerna-state
run: |
#INFO: `jq -c` => Делаем вывод в одну JSON строку
echo "CHANGED_STATE=$(npx lerna la --json --since=$(git merge-base --fork-point origin/dev) ${{ env.EXCLUDE_DEPENDENTS }} | jq -c)" >> "$GITHUB_OUTPUT"
echo "RAW_DATA=$(npx lerna la --json --since=$(git merge-base --fork-point origin/dev) ${{ env.EXCLUDE_DEPENDENTS }} | jq -c)" >> "$GITHUB_OUTPUT"

- name: Computed scope state
id: scope
uses: actions/github-script@v6
id: state
uses: actions/github-script@v7
env:
CHANGED_STATE: ${{ toJSON(steps.changed-state.outputs.CHANGED_STATE) }}
AS_ENUMERATION: ${{ inputs.as-enumeration }}
RAW_DATA: ${{ steps.lerna-state.outputs.RAW_DATA }}
with:
script: |
const processingScope = require('./.github/processing-scope.js');
Expand All @@ -117,19 +55,5 @@ jobs:
- name: Set "GITHUB_OUTPUT"
id: set-output
run: |
echo "SCOPE=${{ fromJSON(steps.scope.outputs.result).SCOPE }}" >> $GITHUB_OUTPUT
echo "HAS_SCOPE=${{ fromJSON(steps.scope.outputs.result).HAS_SCOPE }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_UI_DOCS=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_UI_DOCS }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_WEB_DOCS=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_WEB_DOCS }}" >> $GITHUB_OUTPUT
echo "HAS_DOCUMENTATION_CHANGED=${{ fromJSON(steps.scope.outputs.result).HAS_DOCUMENTATION_CHANGED }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_B2C=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_B2C }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_WEB=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_WEB }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_UI=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_UI }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_HOPE=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_HOPE }}" >> $GITHUB_OUTPUT
echo "HAS_PLASMA_ASDK=${{ fromJSON(steps.scope.outputs.result).HAS_PLASMA_ASDK }}" >> $GITHUB_OUTPUT
echo "HAS_CALDERA=${{ fromJSON(steps.scope.outputs.result).HAS_CALDERA }}" >> $GITHUB_OUTPUT
echo "HAS_CALDERA_ONLINE=${{ fromJSON(steps.scope.outputs.result).HAS_CALDERA_ONLINE }}" >> $GITHUB_OUTPUT
echo "HAS_SDDS_SERV=${{ fromJSON(steps.scope.outputs.result).HAS_SDDS_SERV }}" >> $GITHUB_OUTPUT
echo "HAS_ASSETS=${{ fromJSON(steps.scope.outputs.result).HAS_ASSETS }}" >> $GITHUB_OUTPUT
echo "PACKAGES_ENUMERATION=${{ fromJSON(steps.scope.outputs.result).PACKAGES_ENUMERATION }}" >> $GITHUB_OUTPUT
echo "STATE=${{ steps.state.outputs.result }}" >> $GITHUB_OUTPUT

21 changes: 7 additions & 14 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Cypress component testing

on:
merge_group:
pull_request:
branches:
- master
Expand All @@ -13,39 +12,33 @@ concurrency:
cancel-in-progress: true

jobs:
change-detection:
uses: ./.github/workflows/change-detection.yml
secrets: inherit

change-detection-temple:
state:
uses: ./.github/workflows/change-detection.yml
with:
exclude-dependents: true
secrets: inherit

cypress:
needs: change-detection
if: ${{ needs.change-detection.outputs.HAS_SCOPE == 'true' }}
needs: state
if: ${{ fromJSON(needs.state.outputs.STATE).HAS_PACKAGES_CYPRESS_RUN }}
strategy:
fail-fast: false
matrix:
# [Note]
# Важно что бы массив был со значениями, где `""` экранируются, например -> ["\"b2c\""]
# Можно для этого использовать JSON.stringify()
scope: ${{fromJson(needs.change-detection.outputs.SCOPE)}}
scope: ${{ fromJson(needs.state.outputs.STATE).PACKAGES_CYPRESS_RUN }}

uses: ./.github/workflows/cypress-common.yml
with:
scope: ${{ matrix.scope }}
secrets: inherit

cypress-react-17:
needs: change-detection
if: ${{ needs.change-detection.outputs.HAS_SCOPE == 'true' }}
needs: state
if: ${{ fromJSON(needs.state.outputs.STATE).HAS_PACKAGES_CYPRESS_RUN }}
strategy:
fail-fast: false
matrix:
scope: ${{fromJson(needs.change-detection.outputs.SCOPE)}}
scope: ${{ fromJson(needs.state.outputs.STATE).PACKAGES_CYPRESS_RUN }}

uses: ./.github/workflows/cypress-common.yml
with:
Expand Down
Loading
Loading