-
Notifications
You must be signed in to change notification settings - Fork 8
Added Theme builder workflow to detect change in variables #312
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
Open
ruchI9897
wants to merge
24
commits into
main
Choose a base branch
from
theme-builder-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7692c99
added workflow
ruchI9897 c49d9d6
fixed changes
ruchI9897 f7f9c81
added in main.yml
ruchI9897 734d977
fixed workflow
ruchI9897 a3bdbce
fixed workflow
ruchI9897 4264a6f
fixed workflow
ruchI9897 bc67408
fix 1
ruchI9897 a8a4174
fix 2
ruchI9897 c3314ba
fix 3
ruchI9897 8fd06c9
fix 4
ruchI9897 38c3eb5
fix 5
ruchI9897 7b36bba
fix 6
ruchI9897 cd3e4c1
added new var
ruchI9897 92d6fb6
fix 7
ruchI9897 6c9b93f
fix 8
ruchI9897 3066ed4
fix 9
ruchI9897 db2c883
fix 10
ruchI9897 dd4367d
removing esisting
ruchI9897 fcb85ab
fixed with correct variables
ruchI9897 0a02986
added workflow
ruchI9897 860f2af
fixed all
ruchI9897 0b3eef4
code refactoring
ruchI9897 4b63b08
Merge branch 'main' into theme-builder-workflow
ruchI9897 d830fc2
fixed console errors
ruchI9897 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: CSS Variables Validation | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'src/css-variables.ts' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| validate-css-variables: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout current repository | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
|
|
||
| - name: Checkout theme builder repository | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| repository: thoughtspot/Thoughtspot-theme-builder | ||
| path: theme-builder | ||
| ref: main | ||
| token: ${{ secrets.THEME_BUILDER_TOKEN }} | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Verify theme builder file access | ||
| run: | | ||
| echo "Verifying theme builder file access..." | ||
| echo "Theme builder file: theme-builder/src/data/sdkVariable.ts" | ||
|
|
||
| - name: Validate CSS variables consistency | ||
| run: | | ||
| echo "Running validation..." | ||
| node scripts/validate-css-variables.js "$(cat theme-builder/src/data/sdkVariable.ts)" | ||
| echo "CSS variables validation completed successfully!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Script to validate CSS variables consistency between repositories | ||
| * This script extracts CSS variable names from the TypeScript interface | ||
| * and compares them with the implementation in another repository | ||
| */ | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| /** | ||
| * Extract CSS variable names from the TypeScript interface | ||
| * @param {string} filePath - Path to the css-variables.ts file | ||
| * @returns {string[]} Array of CSS variable names | ||
| */ | ||
| function extractVariablesFromInterface(filePath) { | ||
| try { | ||
| const content = fs.readFileSync(filePath, 'utf8'); | ||
|
|
||
| // Extract variable names using regex | ||
| const variableRegex = /'--ts-var-[^']+'/g; | ||
| const matches = content.match(variableRegex); | ||
|
|
||
| if (!matches) { | ||
| console.error('No CSS variables found in the interface file'); | ||
| return []; | ||
| } | ||
|
|
||
| // Remove quotes and sort for consistent comparison | ||
| return matches.map(match => match.replace(/'/g, '')).sort(); | ||
| } catch (error) { | ||
| console.error(`Error reading interface file: ${error.message}`); | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extract CSS variable names from the implementation object | ||
| * @param {string} content - Content of the implementation file | ||
| * @returns {string[]} Array of CSS variable names | ||
| */ | ||
| function extractVariablesFromImplementation(content) { | ||
| try { | ||
| // Extract variable names from object keys | ||
| const variableRegex = /'--ts-var-[^']+'\s*:/g; | ||
| const matches = content.match(variableRegex); | ||
|
|
||
| if (!matches) { | ||
| console.error('No CSS variables found in the implementation'); | ||
| return []; | ||
| } | ||
|
|
||
| // Remove quotes and colon, then sort for consistent comparison | ||
| return matches.map(match => match.replace(/[':]/g, '').trim()).sort(); | ||
| } catch (error) { | ||
| console.error(`Error parsing implementation: ${error.message}`); | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Compare two arrays of CSS variables and report differences | ||
| * @param {string[]} interfaceVars - Variables from TypeScript interface | ||
| * @param {string[]} implementationVars - Variables from implementation | ||
| * @returns {object} Comparison result | ||
| */ | ||
| function compareVariables(interfaceVars, implementationVars) { | ||
| const implementationSet = new Set(implementationVars); | ||
| const interfaceSet = new Set(interfaceVars); | ||
| const missingInImplementation = interfaceVars.filter(varName => !implementationSet.has(varName)); | ||
| const extraInImplementation = implementationVars.filter(varName => !interfaceSet.has(varName)); | ||
|
|
||
| return { | ||
| interfaceCount: interfaceVars.length, | ||
| implementationCount: implementationVars.length, | ||
| missingInImplementation, | ||
| extraInImplementation, | ||
| isConsistent: missingInImplementation.length === 0 && extraInImplementation.length === 0 | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Main validation function | ||
| */ | ||
| function validateCSSVariables() { | ||
| // Path to the interface file | ||
| const interfacePath = path.join(__dirname, '..', 'src', 'css-variables.ts'); | ||
|
|
||
| // Check if interface file exists | ||
| if (!fs.existsSync(interfacePath)) { | ||
| console.error(`Interface file not found: ${interfacePath}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Extract variables from interface | ||
| const interfaceVars = extractVariablesFromInterface(interfacePath); | ||
| if (interfaceVars === null) { | ||
| console.error('Error extracting variables from interface'); | ||
| process.exit(1); | ||
| } | ||
| // Get implementation content from command line argument or environment | ||
| const implementationContent = process.argv[2] || process.env.CSS_VARS_IMPLEMENTATION; | ||
|
|
||
| if (!implementationContent) { | ||
| console.log('No implementation content provided'); | ||
| return; | ||
| } | ||
|
|
||
| // Extract variables from implementation | ||
| const implementationVars = extractVariablesFromImplementation(implementationContent); | ||
| if (implementationVars === null) { | ||
| console.error('Error extracting variables from implementation'); | ||
| process.exit(1); | ||
| } | ||
| // Compare variables | ||
| const comparison = compareVariables(interfaceVars, implementationVars); | ||
|
|
||
| if (comparison.isConsistent) { | ||
| console.log('CSS variables are consistent'); | ||
| process.exit(0); | ||
| } else { | ||
| console.log('CSS variables are NOT consistent:'); | ||
|
|
||
| if (comparison.missingInImplementation.length > 0) { | ||
| console.log('Variables missing in Theme builder, please add them to the Theme builder:'); | ||
| comparison.missingInImplementation.forEach(varName => { | ||
| console.log(` - ${varName}`); | ||
| }); | ||
| } | ||
|
|
||
| if (comparison.extraInImplementation.length > 0) { | ||
| console.log('Variables extra in Theme builder, please remove them from the Theme builder:'); | ||
| comparison.extraInImplementation.forEach(varName => { | ||
| console.log(` - ${varName}`); | ||
| }); | ||
| } | ||
|
|
||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| // Run validation if this script is executed directly | ||
| if (require.main === module) { | ||
| validateCSSVariables(); | ||
| } | ||
|
|
||
| module.exports = { | ||
| extractVariablesFromInterface, | ||
| extractVariablesFromImplementation, | ||
| compareVariables, | ||
| validateCSSVariables | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for extracting variables from the implementation string is a bit brittle. The regular expression on line 46 doesn't account for optional whitespace between the variable name and the colon, which could cause validation to fail on slightly different but valid formatting. The suggestion below adjusts the regex to handle whitespace and updates the mapping function to trim the result, making the extraction more robust.