Skip to content

Instantly share code, notes, and snippets.

@ThatGuySam
Forked from belgattitude/ci-pnpm-install.md
Created June 10, 2023 20:23
Show Gist options
  • Save ThatGuySam/663e2d7b798bbedc41a0ff150858ba2c to your computer and use it in GitHub Desktop.
Save ThatGuySam/663e2d7b798bbedc41a0ff150858ba2c to your computer and use it in GitHub Desktop.

Revisions

  1. @belgattitude belgattitude revised this gist May 22, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -65,6 +65,7 @@ runs:
    run: corepack enable

    - uses: pnpm/[email protected]
    if: ${{ inputs.enable-corepack }} == 'false'
    # If you're not setting the packageManager field in package.json, add the version here
    # with:
    # version: 8.5.1
  2. @belgattitude belgattitude revised this gist May 22, 2023. 1 changed file with 26 additions and 5 deletions.
    31 changes: 26 additions & 5 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -30,23 +30,44 @@ With warmed cache: ±40s + (add ±10s for compression). Crafted from benchmarks
    Create a file in `.github/actions/pnpm-install/action.yml` and paste

    ```yml
    #######################################################################################
    # "pnpm install" composite action #
    ########################################################################################
    # "pnpm install" composite action for pnpm 7/8+ #
    #--------------------------------------------------------------------------------------#
    # - bench: https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b #
    # Requirement: @setup/node should be run before #
    # #
    # Usage in workflows steps: #
    # #
    # - name: 📥 Monorepo install #
    # uses: ./.github/actions/pnm-install #
    # with: #
    # enable-corepack: false # (default) #
    # #
    # Reference: #
    # - latest: https://gist.github.com/belgattitude/838b2eba30c324f1f0033a797bab2e31 #
    ########################################################################################

    name: 'Monorepo install (pnpm)'
    description: 'Run pnpm install'
    description: 'Run pnpm install with cache enabled'
    inputs:
    enable-corepack:
    description: 'Enable corepack'
    required: false
    default: 'false'

    runs:
    using: 'composite'

    steps:
    - name: ⚙️ Enable Corepack
    if: ${{ inputs.enable-corepack }} == 'true'
    shell: bash
    working-directory: ${{ inputs.cwd }}
    run: corepack enable

    - uses: pnpm/[email protected]
    # If you're not setting the packageManager field in package.json, add the version here
    # with:
    # version: 8.4.0
    # version: 8.5.1

    - name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
    id: pnpm-config
  3. @belgattitude belgattitude revised this gist May 22, 2023. 1 changed file with 13 additions and 3 deletions.
    16 changes: 13 additions & 3 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -102,6 +102,8 @@ To use it in the workflows
    ## Recommended .npmrc
    > Ensure you're running a recent pnpm version (or adapt)
    ```
    ## PNPM related ###############
    ## https://pnpm.io/npmrc #
    @@ -130,15 +132,23 @@ dedupe-peer-dependents=true
    # https://pnpm.io/npmrc#resolve-peers-from-workspace-root
    resolve-peers-from-workspace-root=true

    # default to 'lowest' in v8.5.0
    # set to highest for reasons specified here: https://github.com/pnpm/pnpm/issues/6463
    # https://pnpm.io/npmrc#resolution-mode
    resolution-mode=lowest
    resolution-mode=highest

    # Default in 8.1.0 to fix issues with root/workspaces hoisting
    # https://github.com/pnpm/pnpm/releases/tag/v8.1.0
    # https://pnpm.io/npmrc#dedupe-direct-deps
    dedupe-direct-deps=false

    save-workspace-protocol=rolling
    # Pinlock to exact version (default is '^')
    # https://pnpm.io/npmrc#save-prefix
    # see also how save-workspace-protocol affect this https://pnpm.io/npmrc#save-workspace-protocol
    save-prefix=''

    # Most of the time, you want to use the rolling protocol for monorepos
    # https://pnpm.io/npmrc#save-workspace-protocol
    save-workspace-protocol=rolling
    ```

    ## Notes
  4. @belgattitude belgattitude revised this gist May 2, 2023. 1 changed file with 35 additions and 3 deletions.
    38 changes: 35 additions & 3 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ Although @setup/node as a [built-in cache option](https://github.com/actions/set

    ## Requirements

    pnpm v7+ (not using pnpm ? see the corresponding [yarn action gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a))
    pnpm v7 or v8 (not using pnpm ? see the corresponding [yarn action gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a))

    ## Bench

    @@ -46,7 +46,7 @@ runs:
    - uses: pnpm/[email protected]
    # If you're not setting the packageManager field in package.json, add the version here
    # with:
    # version: 7.16.1
    # version: 8.4.0

    - name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
    id: pnpm-config
    @@ -103,10 +103,42 @@ To use it in the workflows
    ## Recommended .npmrc
    ```
    ## PNPM related ###############
    ## https://pnpm.io/npmrc #
    ###############################

    # Not always possible to be strict, but if it works for you, keep it to true.
    # https://pnpm.io/next/npmrc#strict-peer-dependencies
    strict-peer-dependencies=true
    strict-peer-dependencies=false

    # Auto install peers should be false to avoid downloading
    # extraneous deps. If the install fails, try first to explicitly add
    # the missing deps in your package. Set it to true at last resort
    # (when the problem comes from upstream dependencies). The best is false.
    # https://pnpm.io/npmrc#auto-install-peers
    auto-install-peers=false

    # Helps locating duplicates, default in v8
    # https://pnpm.io/next/npmrc#use-lockfile-v6
    use-lockfile-v6=true

    # Will fix duplicates due to peer-dependencies (>=7.29.0), default in v8
    # https://github.com/pnpm/pnpm/releases/tag/v7.29.0
    dedupe-peer-dependents=true

    # Helps with peer-deps (>=7.23.0), default in v8
    # https://pnpm.io/npmrc#resolve-peers-from-workspace-root
    resolve-peers-from-workspace-root=true

    # https://pnpm.io/npmrc#resolution-mode
    resolution-mode=lowest

    # Default in 8.1.0 to fix issues with root/workspaces hoisting
    # https://github.com/pnpm/pnpm/releases/tag/v8.1.0
    dedupe-direct-deps=false

    save-workspace-protocol=rolling
    save-prefix=''
    ```

    ## Notes
  5. @belgattitude belgattitude revised this gist Mar 2, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -77,7 +77,7 @@ runs:

    - name: Install dependencies
    shell: bash
    run: pnpm install --frozen-lockfile --strict-peer-dependencies --prefer-offline
    run: pnpm install --frozen-lockfile --prefer-offline
    env:
    # Other environment variables
    HUSKY: '0' # By default do not run HUSKY install
  6. @belgattitude belgattitude revised this gist Feb 7, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -134,7 +134,7 @@ Link: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to
    Here's an example (feel free to adapt if you need to preserse some things, ie `gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 | grep pnpm` will only clear pnpm related caches)

    ```yaml
    # .github/workflows/clean-up-pr-caches.yml
    # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
    name: Cleanup caches for closed branches

    on:
    @@ -150,12 +150,12 @@ jobs:
    - name: Check out code
    uses: actions/checkout@v3

    - name: Cleanup yarn caches
    - name: Cleanup
    run: |
    gh extension install actions/gh-actions-cache
    REPO=${{ github.repository }}
    BRANCH=${{ github.ref }}
    BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
    echo "Fetching list of cache key"
    cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
  7. @belgattitude belgattitude revised this gist Jan 21, 2023. 1 changed file with 55 additions and 0 deletions.
    55 changes: 55 additions & 0 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -120,3 +120,58 @@ Post-install

    ![image](https://user-images.githubusercontent.com/259798/194955031-99208699-1e18-418e-9f3e-1a9dde28941e.png)


    ### Cleanup caches

    When a PR is closed or merged the best is to remove install cache rather than letting github reach the max (10GB) and
    prune.

    ![image](https://user-images.githubusercontent.com/259798/213885213-7bd74ee6-c174-472c-9cbd-3bd406b58e4b.png)


    Link: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries

    Here's an example (feel free to adapt if you need to preserse some things, ie `gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 | grep pnpm` will only clear pnpm related caches)

    ```yaml
    # .github/workflows/clean-up-pr-caches.yml
    name: Cleanup caches for closed branches

    on:
    pull_request:
    types:
    - closed
    workflow_dispatch:

    jobs:
    cleanup:
    runs-on: ubuntu-latest
    steps:
    - name: Check out code
    uses: actions/checkout@v3

    - name: Cleanup yarn caches
    run: |
    gh extension install actions/gh-actions-cache
    REPO=${{ github.repository }}
    BRANCH=${{ github.ref }}
    echo "Fetching list of cache key"
    cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
    ## Setting this to not fail the workflow while deleting cache keys.
    set +e
    echo "Deleting caches..."
    for cacheKey in $cacheKeysForPR
    do
    gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
    done
    echo "Done"
    env:
    GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    ```



  8. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,9 @@ runs:

    steps:
    - uses: pnpm/[email protected]
    # If you're not setting the packageManager field in package.json, add the version here
    # with:
    # version: 7.16.1

    - name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
    id: pnpm-config
  9. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 7 deletions.
    8 changes: 1 addition & 7 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -38,11 +38,6 @@ Create a file in `.github/actions/pnpm-install/action.yml` and paste

    name: 'Monorepo install (pnpm)'
    description: 'Run pnpm install'
    inputs:
    skip-prisma-postinstall-generate:
    description: 'Avoid prisma to automatically generate schema on postinstall'
    required: false
    default: 'true'

    runs:
    using: 'composite'
    @@ -82,8 +77,7 @@ runs:
    run: pnpm install --frozen-lockfile --strict-peer-dependencies --prefer-offline
    env:
    # Other environment variables
    HUSKY: '0' # By default do not run HUSKY install
    PRISMA_SKIP_POSTINSTALL_GENERATE: ${{ inputs.skip-prisma-postinstall-generate }}
    HUSKY: '0' # By default do not run HUSKY install
    ```
    ### Workflow action
  10. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Why

    Although @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data) it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).
    Although @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data), it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

    ## Requirements

  11. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Why

    Although @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data)it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).
    Although @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data) it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

    ## Requirements

  12. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Why

    Althought @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data)it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).
    Although @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data)it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

    ## Requirements

  13. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    >
    ## Why

    The [@setup/node built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data) is fantastic, but lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).
    Althought @setup/node as a [built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data)it lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

    ## Requirements

  14. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ runs:
    using: 'composite'

    steps:
    - uses: pnpm/[email protected].2
    - uses: pnpm/[email protected].4

    - name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
    id: pnpm-config
  15. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,7 @@
    ## Why

    The [@setup/node built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data) is fantastic, but lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325).

    Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).
    The [@setup/node built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data) is fantastic, but lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325). Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

    ## Requirements

  16. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,14 @@
    > Not using pnpm ? see the corresponding [yarn action gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a)
    >
    ## Why

    While @setup/node has a [built-in cache parameter](https://github.com/actions/setup-node#caching-global-packages-data)
    for popular package managers, it discards the cache on every lock file update. This composite action allows to run install with (almost always) warm cache.
    The [@setup/node built-in cache option](https://github.com/actions/setup-node#caching-global-packages-data) is fantastic, but lacks an opportunity [regarding cache persistence](https://github.com/actions/setup-node/issues/325).

    Depending on repo usage, it might reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.
    Depending on usage, the action below might give you faster installs and potentially reduce carbon emissions (♻️🌳❤️).

    ## Requirements

    pnpm v7+
    pnpm v7+ (not using pnpm ? see the corresponding [yarn action gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a))

    ## Bench

  17. @belgattitude belgattitude revised this gist Nov 16, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,10 @@ for popular package managers, it discards the cache on every lock file update. T

    Depending on repo usage, it might reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.

    ## Requirements

    pnpm v7+

    ## Bench

    Based on the [nextjs-monorepo-example](https://github.com/belgattitude/nextjs-monorepo-example) with pnpm.
  18. @belgattitude belgattitude revised this gist Oct 13, 2022. 1 changed file with 18 additions and 11 deletions.
    29 changes: 18 additions & 11 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -51,24 +51,32 @@ runs:
    steps:
    - uses: pnpm/[email protected]

    - name: Get pnpm store directory
    - name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
    id: pnpm-config
    shell: bash
    id: pnpm-cache
    run: |
    echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
    echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
    - name: Cache rotation keys
    id: cache-rotation
    shell: bash
    run: |
    echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
    - uses: actions/cache@v3
    name: Setup pnpm cache
    with:
    path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
    key: ${{ runner.os }}-pnpm-store-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
    path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
    key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
    restore-keys: |
    ${{ runner.os }}-pnpm-store-cache-
    ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
    # Prevent store to grow over time (different from yarn which prunes when enableGlobalCache is false)
    - name: Prune pnpm store
    shell: bash
    run: pnpm prune store
    # Prevent store to grow over time (not needed with yarn)
    # Note: not perfect as it prune too much in monorepos so the idea
    # is to use cache-rotation as above. In the future this might work better.
    #- name: Prune pnpm store
    # shell: bash
    # run: pnpm prune store

    - name: Install dependencies
    shell: bash
    @@ -77,7 +85,6 @@ runs:
    # Other environment variables
    HUSKY: '0' # By default do not run HUSKY install
    PRISMA_SKIP_POSTINSTALL_GENERATE: ${{ inputs.skip-prisma-postinstall-generate }}
    PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${{ inputs.playwright-skip-browser-download }}
    ```
    ### Workflow action
  19. @belgattitude belgattitude revised this gist Oct 13, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    While @setup/node has a [built-in cache parameter](https://github.com/actions/setup-node#caching-global-packages-data)
    for popular package managers, it discards the cache on every lock file update. This composite action allows to run install with (almost always) warm cache.

    That might reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.
    Depending on repo usage, it might reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.

    ## Bench

  20. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -115,4 +115,5 @@ Install

    Post-install

    ![image](https://user-images.githubusercontent.com/259798/194955031-99208699-1e18-418e-9f3e-1a9dde28941e.png)

  21. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -105,3 +105,14 @@ strict-peer-dependencies=true
    # https://pnpm.io/npmrc#auto-install-peers
    auto-install-peers=false
    ```

    ## Notes

    Install

    ![image](https://user-images.githubusercontent.com/259798/194954708-fb3fff70-375b-4769-8aeb-7c3b1d586418.png)


    Post-install


  22. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,7 @@ runs:
    restore-keys: |
    ${{ runner.os }}-pnpm-store-cache-
    # Prevent store to grow over time (not needed with yarn)
    # Prevent store to grow over time (different from yarn which prunes when enableGlobalCache is false)
    - name: Prune pnpm store
    shell: bash
    run: pnpm prune store
    @@ -97,3 +97,11 @@ To use it in the workflows
    uses: ./.github/actions/pnpm-install
    ```
    ## Recommended .npmrc
    ```
    # https://pnpm.io/next/npmrc#strict-peer-dependencies
    strict-peer-dependencies=true
    # https://pnpm.io/npmrc#auto-install-peers
    auto-install-peers=false
    ```
  23. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 2 additions and 8 deletions.
    10 changes: 2 additions & 8 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -44,10 +44,6 @@ inputs:
    description: 'Avoid prisma to automatically generate schema on postinstall'
    required: false
    default: 'true'
    playwright-skip-browser-download:
    description: 'Avoid playwright to download browsers automatically'
    required: false
    default: '1'

    runs:
    using: 'composite'
    @@ -60,8 +56,7 @@ runs:
    id: pnpm-cache
    run: |
    echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
    # Diffently from yarn, caching the store is not independent from os/arch.
    - uses: actions/cache@v3
    name: Setup pnpm cache
    with:
    @@ -77,8 +72,7 @@ runs:

    - name: Install dependencies
    shell: bash
    run: |
    pnpm install --frozen-lockfile
    run: pnpm install --frozen-lockfile --strict-peer-dependencies --prefer-offline
    env:
    # Other environment variables
    HUSKY: '0' # By default do not run HUSKY install
  24. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ runs:
    run: |
    echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
    # Diffently from yarn, caching the store is no independent from os/arch.
    # Diffently from yarn, caching the store is not independent from os/arch.
    - uses: actions/cache@v3
    name: Setup pnpm cache
    with:
  25. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -60,7 +60,8 @@ runs:
    id: pnpm-cache
    run: |
    echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
    # Diffently from yarn, caching the store is no independent from os/arch.
    - uses: actions/cache@v3
    name: Setup pnpm cache
    with:
  26. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    > Not using pnpm ?, see the [corresponding yarn gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a)
    > Not using pnpm ? see the corresponding [yarn action gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a)
    ## Why

  27. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    While @setup/node has a [built-in cache parameter](https://github.com/actions/setup-node#caching-global-packages-data)
    for popular package managers, it discards the cache on every lock file update. This composite action allows to run install with (almost always) warm cache.

    That will reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.
    That might reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.

    ## Bench

  28. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,19 @@
    > Not using pnpm ?, see the [corresponding yarn gist](https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a)
    ## Why

    While @setup/node has a [built-in cache parameter](https://github.com/actions/setup-node#caching-global-packages-data)
    for popular package managers, it discards the cache on every lock file update. This composite action allows to run install with (almost always) warm cache.

    That might reduces the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.
    That will reduce the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.

    ## Bench

    Based on the [nextjs-monorepo-example](https://github.com/belgattitude/nextjs-monorepo-example) with pnpm.

    A cold cache install on the ci is more than 2 minutes.
    A cold cache install on the ci is around ±1m20s.

    With warmed cache: 1 minute. Crafted from benchmarks results in https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b. Depending on repo (renovatebot...), the slight complexity increase in ci setup might worth it.
    With warmed cache: ±40s + (add ±10s for compression). Crafted from benchmarks results in https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b. Depending on repo (renovatebot...), the slight complexity increase in ci setup might worth it.

    ## Structure

  29. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 32 additions and 46 deletions.
    78 changes: 32 additions & 46 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -19,74 +19,68 @@ With warmed cache: 1 minute. Crafted from benchmarks results in https://gist.git
    .
    └── .github
    ├── actions
    │ └── yarn-nm-install/action.yml (composite action)
    │ └── pnpm-install/action.yml (composite action)
    └── workflows
    └── ci.yml (uses: ./.github/actions/yarn-nm-install)
    └── ci.yml (uses: ./.github/actions/pnpm-install)
    ```

    ### Composite action

    Create a file in `.github/actions/yarn-nm-install/action.yml` and paste
    Create a file in `.github/actions/pnpm-install/action.yml` and paste

    ```yml
    ########################################################################################
    # "yarn install" composite action for yarn 2/3/4+ and "nodeLinker: node-modules" #
    #######################################################################################
    # "pnpm install" composite action #
    #--------------------------------------------------------------------------------------#
    # Cache: #
    # - Downloaded zip archive (multi-arch, preserved across yarn.lock changes) #
    # - Yarn install state (discarded in yarn.lock changes) #
    # References: #
    # - bench: https://gist.github.com/belgattitude/0ecd26155b47e7be1be6163ecfbb0f0b #
    # - vs @setup/node: https://github.com/actions/setup-node/issues/325 #
    ########################################################################################

    name: 'Yarn install'
    description: 'Run yarn install with node_modules linker and cache enabled'
    name: 'Monorepo install (pnpm)'
    description: 'Run pnpm install'
    inputs:
    skip-prisma-postinstall-generate:
    description: 'Avoid prisma to automatically generate schema on postinstall'
    required: false
    default: 'false'
    default: 'true'
    playwright-skip-browser-download:
    description: 'Avoid playwright to download browsers automatically'
    required: false
    default: '1'

    runs:
    using: 'composite'

    steps:
    - name: Get yarn cache directory path
    id: yarn-cache-dir-path
    - uses: pnpm/[email protected]

    - name: Get pnpm store directory
    shell: bash
    run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
    id: pnpm-cache
    run: |
    echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
    # Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
    - name: Restore yarn cache
    uses: actions/cache@v3
    id: yarn-download-cache
    - uses: actions/cache@v3
    name: Setup pnpm cache
    with:
    path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
    key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
    path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
    key: ${{ runner.os }}-pnpm-store-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
    restore-keys: |
    yarn-download-cache-
    ${{ runner.os }}-pnpm-store-cache-
    # Invalidated on yarn.lock changes
    - name: Restore yarn install state
    id: yarn-install-state-cache
    uses: actions/cache@v3
    with:
    path: |
    .ci-cache/yarn-state
    key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
    # Prevent store to grow over time (not needed with yarn)
    - name: Prune pnpm store
    shell: bash
    run: pnpm prune store

    - name: Install dependencies
    shell: bash
    run: |
    yarn install --immutable --inline-builds
    pnpm install --frozen-lockfile
    env:
    # CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
    YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
    YARN_NM_MODE: 'hardlinks-local' # Hardlinks-(local|global) reduces io / node_modules size
    YARN_INSTALL_STATE_PATH: .ci-cache/yarn-state/install-state.gz # Very small speedup when lock does not change
    # Other environment variables
    HUSKY: '0' # By default do not run HUSKY install
    PRISMA_SKIP_POSTINSTALL_GENERATE: ${{ inputs.skip-prisma-postinstall-generate }}
    PRISMA_SKIP_POSTINSTALL_GENERATE: ${{ inputs.skip-prisma-postinstall-generate }}
    PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${{ inputs.playwright-skip-browser-download }}
    ```
    ### Workflow action
    @@ -103,14 +97,6 @@ To use it in the workflows
    node-version: ${{ matrix.node-version }}

    - name: 📥 Monorepo install
    uses: ./.github/actions/yarn-nm-install
    ```
    ### yarnrc.yml
    uses: ./.github/actions/pnpm-install
    ```
    # .yarnrc.yml
    nodeLinker: node-modules
    yarnPath: .yarn/releases/yarn-4.0.0-rc.24.cjs # or v3...
    ```
  30. @belgattitude belgattitude revised this gist Oct 10, 2022. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions ci-pnpm-install.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,7 @@
    ## Why

    While @setup/node has a [built-in cache parameter](https://github.com/actions/setup-node#caching-global-packages-data) for popular package managers,
    it discards the cache on every lock file update.

    This composite action allows to run install with (almost always) warm cache.
    While @setup/node has a [built-in cache parameter](https://github.com/actions/setup-node#caching-global-packages-data)
    for popular package managers, it discards the cache on every lock file update. This composite action allows to run install with (almost always) warm cache.

    That might reduces the monthly ci-time and decrease the carbon emissions. See also https://github.com/actions/setup-node/issues/325.