1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-10 10:38:01 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
jbranchaud
fa20b1aa66 Add Cache Playwright Dependencies Across Workflows as a GitHub Actions TIL 2023-06-14 16:40:23 -05:00
jbranchaud
00481bb71a Add Get The Time Components Of A Date as a JavaScript TIL 2023-06-14 12:50:06 -05:00
3 changed files with 75 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1309 TILs and counting..._
_1311 TILs and counting..._
---
@@ -344,6 +344,7 @@ _1309 TILs and counting..._
### GitHub Actions
- [Cache Playwright Dependencies Across Workflows](github-actions/cache-playwright-dependencies-across-workflows.md)
- [Capture An Output Value For Use In A Later Step](github-actions/capture-an-output-value-for-use-in-a-later-step.md)
- [Reference An Encrypted Secret In An Action](github-actions/reference-an-encrypted-secret-in-an-action.md)
@@ -432,6 +433,7 @@ _1309 TILs and counting..._
- [Generate Random Integers](javascript/generate-random-integers.md)
- [Get The Location And Size Of An Element](javascript/get-the-location-and-size-of-an-element.md)
- [Get The Response Status From An Axios Error](javascript/get-the-response-status-from-an-axios-error.md)
- [Get The Time Components Of A Date](javascript/get-the-time-components-of-a-date.md)
- [Get The Time Zone Of The Client Computer](javascript/get-the-time-zone-of-the-client-computer.md)
- [Globally Install A Package With Yarn](javascript/globally-install-a-package-with-yarn.md)
- [Globally Install Specific Version Of PNPM](javascript/globally-install-specific-version-of-pnpm.md)

View File

@@ -0,0 +1,43 @@
# Cache Playwright Dependencies Across Workflows
With the help of `actions/cache@v3`, I can cache the dependency install and
setup involved with using Playwright in GitHub Actions. That setup, in my
experience, typically takes ~45s. When it is already cached, it is able to skip
that step entirely greatly reducing the overall run time of the script.
First, I need to define a cache (`playwright-cache`). Second, I need to only
install the Playwright dependencies when that cache isn't available (`cache-hit
!= 'true'`).
Here is a striped down workflow demonstrating that.
```yaml
name: Playwright Script
on:
workflow_dispatch:
jobs:
Cached-Playwright-Script:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- uses: actions/cache@v3
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm ci
- name: Install playwright deps
run: npx playwright install --with-deps chromium
if: steps.playwright-cache.outputs.cache-hit != 'true'
- run: node playwright-script.js
```
If I add the caching step and the cache-conditional `playwright install` steps
to another workflow in this project, the cache will be available to both of
them. That means they both benefit from the savings of that work having already
been cached.
[source](https://justin.poehnelt.com/posts/caching-playwright-in-github-actions/)

View File

@@ -0,0 +1,29 @@
# Get The Time Components Of A Date
A `Date` object in JavaScript has several functions available to it for getting
at the time components of that date.
```javascript
> const now = new Date()
undefined
> now
2023-06-14T17:44:06.425Z
> now.getMinutes()
44
> now.getSeconds()
6
> now.getHours()
12
```
For a given `Date` object, you can access the hours with
[`getHours()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours),
the minutes with
[`getMinutes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes),
and the seconds with
[`getSeconds()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds).
To round things out, there is also
[`getMilliseconds()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
and
[`getTimezoneOffset()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset).