-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(infrastructure): Upload compiled screenshot test assets to GCS #2500
Conversation
New NPM command: `screenshot:upload-assets`. First, run: ```bash npm start ``` Then, in another terminal, run: ```bash npm run screenshot:upload-assets ``` All files are uploaded to a directory containing a random UUID to prevent collisions between developers.
Codecov Report
@@ Coverage Diff @@
## master #2500 +/- ##
=======================================
Coverage 98.82% 98.82%
=======================================
Files 102 102
Lines 4079 4079
Branches 511 511
=======================================
Hits 4031 4031
Misses 48 48 Continue to review full report at Codecov.
|
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.
Looks dope. Got a few comments.
test/screenshot/asset-uploader.js
Outdated
const relativeLocalFilePaths = glob.sync(path.join(LOCAL_DIRECTORY_PREFIX, '**/*.*')); | ||
|
||
relativeLocalFilePaths.forEach((relativeLocalFilePath) => { | ||
const fileContents = fs.readFileSync(relativeLocalFilePath); |
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.
readFileSync
to avoid having too many open files at once?
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.
No, it's to ensure that upload()
doesn't immediately return an empty array.
I tried several different approaches first, but they were all more convoluted and harder to read, so I went with readFileSync()
cuz it was the simplest.
test/screenshot/asset-uploader.js
Outdated
} | ||
|
||
function handleUploadFailure(absoluteGcsBaseDir, relativeGcsFilePath, err) { | ||
console.error(`❌︎ FAILED to upload ${GCLOUD_STORAGE_BASE_URL}${absoluteGcsBaseDir}${relativeGcsFilePath}:\n`, err); |
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.
What icon is this? I only see a square.
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.
Good catch! Changed to ✗ (Ballot X)
test/screenshot/run-upload-assets.js
Outdated
console.log('\n\nDONE!\n\n'); | ||
console.log(htmlFileUrls.join('\n')); | ||
}, | ||
(err) => { |
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.
Nit: Use .catch
instead. It's 100% a personal preference but I find it much more obvious what the function is doing.
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.
Good idea! Done.
E.g.: `advorak/2018/04/03/23_00_32_993/5ca514fe/assets/`
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.
LGTM
test/screenshot/asset-uploader.js
Outdated
promises.push( | ||
file.save(fileContents, fileOptions).then( | ||
() => handleUploadSuccess(baseGcsDir, relativeGcsFilePath), | ||
(err) => handleUploadFailure(baseGcsDir, relativeGcsFilePath, err) |
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.
SUPER NIT: use .catch
here, too. Gonna LGTM this without because this is just me being obscenely picky.
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.
Good catch! Done.
Resolves #1996
New NPM command:
screenshot:upload-assets
.First, run:
Then, in another terminal, run:
export MDC_GCLOUD_SERVICE_ACCOUNT_KEY_FILE_PATH=path/to/gcloud-service-account-key.json npm run screenshot:upload-assets
To avoid collisions between developers, every batch of files is uploaded to a directory with the following format:
E.g.:
/mdc-web-screenshot-tests/advorak/2018/04/03/23_00_32_993/5ca514fe/assets/
.Sample output:
mdc-button/classes/baseline.html
mdc-button/classes/dense.html
mdc-button/mixins/container-fill-color.html
mdc-button/mixins/corner-radius.html
mdc-button/mixins/filled-accessible.html
mdc-button/mixins/horizontal-padding-baseline.html
mdc-button/mixins/horizontal-padding-dense.html
mdc-button/mixins/icon-color.html
mdc-button/mixins/ink-color.html
mdc-button/mixins/stroke-color.html
mdc-button/mixins/stroke-width.html