Skip to content

Commit

Permalink
🏗 Ensure that z-index table is up to date (#32830)
Browse files Browse the repository at this point in the history
Successful `--fix` run: (truncated)

```diff
gulp get-zindex --fix

[10:10:23] Using gulpfile ~/git/amphtml/gulpfile.js
[10:10:23] Starting 'get-zindex'...

diff --git a/css/Z_INDEX.md b/css/Z_INDEX.md
index 437b768da..a1c673789 100644
--- a/css/Z_INDEX.md
+++ b/css/Z_INDEX.md
@@ -1,7 +1,9 @@
-Run `gulp get-zindex` to generate this file.
+Run `gulp get-zindex --fix` to generate this file.
 
 | selector                                     | z-index    | file                                      |
-| -------------------------------------------- | ---------- | --------------------------------------- |
+| -------------------------------------------- | ---------- | ----------------------------------------- |
 | .i-amphtml-expanded-mode amp-story-grid-lay  | auto       | extensions/amp-story/1.0/amp-story.css    |
 | .i-amphtml-expanded-mode amp-story-grid-lay  | auto       | extensions/amp-story/1.0/amp-story.css    |
+| amp-sidebar::part(c)                         | inherit    | extensions/amp-sidebar/1.0/amp-sidebar.cs |
+| amp-sidebar::part(sidebar)                   | inherit    | extensions/amp-sidebar/1.0/amp-sidebar.cs |
 | amp-story amp-consent                        | initial    | extensions/amp-story/1.0/amp-story.css    |
@@ -9,4 +11,6 @@ Run `gulp get-zindex` to generate this file.
 | .amp-access-scroll-sheet                     | 2147483647 | extensions/amp-access-scroll/0.1/amp-acce |
+| .i-amphtml-onetap-google-iframe              | 2147483647 | extensions/amp-onetap-google/0.1/amp-onet |
 | amp-sidebar                                  | 2147483647 | extensions/amp-sidebar/0.1/amp-sidebar.cs |
 | amp-sidebar                                  | 2147483647 | extensions/amp-sidebar/0.2/amp-sidebar.cs |
+| amp-sidebar                                  | 2147483647 | extensions/amp-sidebar/1.0/amp-sidebar.cs |
 | .amp-apester-fullscreen                      | 2147483646 | extensions/amp-apester-media/0.1/amp-apes |
@@ -59,3 +63,5 @@ Run `gulp get-zindex` to generate this file.
 | amp-app-banner                               | 13         | extensions/amp-app-banner/0.1/amp-app-ban |
+| amp-ad-sticky-padding                        | 12         | extensions/amp-ad/0.1/amp-ad.css          |
 | amp-sticky-ad-top-padding                    | 12         | extensions/amp-sticky-ad/1.0/amp-sticky-a |
+| amp-ad[sticky]                               | 11         | extensions/amp-ad/0.1/amp-ad.css          |
 | amp-sticky-ad                                | 11         | extensions/amp-sticky-ad/1.0/amp-sticky-a |
@@ -72,2 +78,3 @@ Run `gulp get-zindex` to generate this file.
 | .i-amphtml-image-slider-bar                  | 3          | extensions/amp-image-slider/0.1/amp-image |
+| amp-story-cta-layer                          | 3          | extensions/amp-story-auto-ads/0.1/amp-sto |
 | amp-story-page[active] .i-amphtml-story-pag  | 3          | extensions/amp-story/1.0/amp-story-page-a |
@@ -82,2 +89,3 @@ Run `gulp get-zindex` to generate this file.
 | amp-story-grid-layer                         | 2          | extensions/amp-story/1.0/amp-story.css    |
+| .amp-story-player-exit-control-button        | 1          | css/amp-story-player-iframe.css           |
 | .i-amphtml-layout-size-defined > [fallback]  | 1          | css/ampshared.css                         |
@@ -86,3 +94,3 @@ Run `gulp get-zindex` to generate this file.
 | .amp-video-eq                                | 1          | css/video-autoplay.css                    |
-| i-amphtml-video-mask                         | 1          | css/video-autoplay.css                  |
+| .i-amphtml-video-mask                        | 1          | css/video-autoplay.css                    |
 | amp-addthis .i-amphtml-addthis-close         | 1          | extensions/amp-addthis/0.1/amp-addthis.cs |

[10:10:23] Wrote css/Z_INDEX.md
[10:10:23] Finished 'get-zindex' after 720 ms
```

A check failure run is the same, except it errors-out when the table is incomplete.
  • Loading branch information
alanorozco committed Feb 24, 2021
1 parent 9648728 commit bf0e1f3
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 137 deletions.
22 changes: 18 additions & 4 deletions build-system/common/diff.js
Expand Up @@ -24,11 +24,19 @@ const {writeFile} = require('fs-extra');
* Diffs a file against content that might replace it.
* @param {string} filepath
* @param {string} content
* @param {Array<string>=} gitDiffFlags
* @return {!Promise<string>}
*/
const diffTentative = (filepath, content) =>
const diffTentative = (filepath, content, gitDiffFlags = ['-U1']) =>
tempy.write.task(content, (temporary) =>
getStdout(`git -c color.ui=always diff -U1 ${filepath} ${temporary}`)
getStdout(
[
'git -c color.ui=always diff',
...gitDiffFlags,
filepath,
temporary,
].join(' ')
)
.trim()
.replace(new RegExp(temporary, 'g'), `/${filepath}`)
);
Expand All @@ -40,9 +48,15 @@ const diffTentative = (filepath, content) =>
* @param {string} callerTask
* @param {string} filepath
* @param {string} tentative
* @param {Array<string>=} opt_gitDiffFlags
*/
async function writeDiffOrFail(callerTask, filepath, tentative) {
const diff = await diffTentative(filepath, tentative);
async function writeDiffOrFail(
callerTask,
filepath,
tentative,
opt_gitDiffFlags
) {
const diff = await diffTentative(filepath, tentative, opt_gitDiffFlags);

if (!diff.length) {
return;
Expand Down
2 changes: 2 additions & 0 deletions build-system/pr-check/checks.js
Expand Up @@ -43,6 +43,7 @@ function pushBuildWorkflow() {
timedExecOrDie('gulp check-sourcemaps');
timedExecOrDie('gulp performance-urls');
timedExecOrDie('gulp check-video-interface-list');
timedExecOrDie('gulp get-zindex');
}

async function prBuildWorkflow() {
Expand Down Expand Up @@ -105,6 +106,7 @@ async function prBuildWorkflow() {
timedExecOrDie('gulp check-sourcemaps');
timedExecOrDie('gulp performance-urls');
timedExecOrDie('gulp check-video-interface-list');
timedExecOrDie('gulp get-zindex');
}
}

Expand Down
26 changes: 21 additions & 5 deletions build-system/tasks/get-zindex/index.js
Expand Up @@ -20,7 +20,8 @@ const globby = require('globby');
const path = require('path');
const postcss = require('postcss');
const prettier = require('prettier');
const table = require('text-table');
const textTable = require('text-table');
const {writeDiffOrFail} = require('../../common/diff');

const tableHeaders = [
['selector', 'z-index', 'file'],
Expand All @@ -32,7 +33,7 @@ const tableOptions = {
hsep: ' | ',
};

const preamble = 'Run `gulp get-zindex` to generate this file.';
const preamble = '**Run `gulp get-zindex --fix` to generate this file.**';

/**
* @param {!Object<string, !Array<number>} acc accumulator object for selectors
Expand Down Expand Up @@ -121,9 +122,20 @@ async function getZindex() {
const filesData = await getZindexSelectors('{css,src,extensions}/**/*.css');
const filename = 'css/Z_INDEX.md';
const rows = [...tableHeaders, ...createTable(filesData)];
const tbl = table(rows, tableOptions);
const output = `${preamble}\n\n${tbl}`;
fs.writeFileSync(filename, await prettierFormat(filename, output));
const table = textTable(rows, tableOptions);
const output = await prettierFormat(filename, `${preamble}\n\n${table}`);

await writeDiffOrFail(
'get-zindex',
filename,
output,
/* gitDiffFlags */ [
'-U1',
// Rows are formatted to align, so rows with unchanged content may change
// in whitespace, forcing the diff to contain the entire table.
'--ignore-space-change',
]
);
}

async function prettierFormat(filename, output) {
Expand All @@ -141,3 +153,7 @@ module.exports = {

getZindex.description =
'Runs through all css files of project to gather z-index values';

getZindex.flags = {
'fix': ' Write to file',
};

0 comments on commit bf0e1f3

Please sign in to comment.