Skip to content
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

Cleanup #2801

Merged
merged 5 commits into from
Dec 10, 2023
Merged

Cleanup #2801

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
124 changes: 124 additions & 0 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
########################################################################################
# "yarn install" composite action for yarn 3/4+ and "nodeLinker: node-modules" #
#--------------------------------------------------------------------------------------#
# Requirement: @setup/node should be run before #
# #
# Usage in workflows steps: #
# #
# - name: 📥 Monorepo install #
# uses: ./.github/actions/yarn-nm-install #
# with: #
# enable-corepack: false # (default = 'false') #
# cache-npm-cache: false # (default = 'true') #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# cache-prefix: add cache key prefix # (default = 'default') #
# cache-node-modules: false # (default = 'false') #
# cache-install-state: false # (default = 'false') #
# #
# Reference: #
# - latest: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a #
# #
# Versions: #
# - 1.1.0 - 22-07-2023 - Option to enable npm global cache folder. #
# - 1.0.4 - 15-07-2023 - Fix corepack was always enabled. #
# - 1.0.3 - 05-07-2023 - YARN_ENABLE_MIRROR to false (speed up cold start) #
# - 1.0.2 - 02-06-2023 - install-state default to false #
# - 1.0.1 - 29-05-2023 - cache-prefix doc #
# - 1.0.0 - 27-05-2023 - new input: cache-prefix #
########################################################################################

name: 'Monorepo install (yarn)'
description: 'Run yarn install with node_modules linker and cache enabled'
inputs:
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: '.'
cache-prefix:
description: 'Add a specific cache-prefix'
required: false
default: 'default'
cache-npm-cache:
description: 'Cache npm global cache folder often used by node-gyp, prebuild binaries (invalidated on lock/os/node-version)'
required: false
default: 'true'
cache-node-modules:
description: 'Cache node_modules, might speed up link step (invalidated lock/os/node-version/branch)'
required: false
default: 'false'
cache-install-state:
description: 'Cache yarn install state, might speed up resolution step when node-modules cache is activated (invalidated lock/os/node-version/branch)'
required: false
default: 'false'
enable-corepack:
description: 'Enable corepack'
required: false
default: 'true'

runs:
using: 'composite'

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

- name: ⚙️ Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
working-directory: ${{ inputs.cwd }}
env:
YARN_ENABLE_GLOBAL_CACHE: 'false'
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
echo "CURRENT_NODE_VERSION="node-$(node --version)"" >> $GITHUB_OUTPUT
echo "CURRENT_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's,/,-,g')" >> $GITHUB_OUTPUT
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT

- name: ♻️ Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ inputs.cache-prefix }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
restore-keys: |
yarn-download-cache-${{ inputs.cache-prefix }}-

- name: ♻️ Restore node_modules
if: inputs.cache-node-modules == 'true'
id: yarn-nm-cache
uses: actions/cache@v3
with:
path: ${{ inputs.cwd }}/**/node_modules
key: yarn-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore global npm cache folder
if: inputs.cache-npm-cache == 'true'
id: npm-global-cache
uses: actions/cache@v3
with:
path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}
key: npm-global-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore yarn install state
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true'
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: ${{ inputs.cwd }}/.yarn/ci-cache
key: yarn-install-state-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: 📥 Install dependencies
shell: bash
working-directory: ${{ inputs.cwd }}
run: yarn install --immutable --inline-builds
env:
# Overrides/align yarnrc.yml options (v3, v4) for a CI context
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_ENABLE_MIRROR: 'false' # Prevent populating global cache for caches misses (local cache only)
YARN_NM_MODE: 'hardlinks-local' # Reduce node_modules size
YARN_INSTALL_STATE_PATH: '.yarn/ci-cache/install-state.gz' # Might speed up resolution step when node_modules present
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
4 changes: 2 additions & 2 deletions .github/ci-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
jobs:
build:
name: ${{ matrix.command }}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:

notify:
name: Discord Notification
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs:
- build
if: ${{ github.event_name == 'push' && failure() }}
Expand Down
2 changes: 1 addition & 1 deletion .github/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions: read-all

jobs:
codesee:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
continue-on-error: true
name: Analyze the repo with CodeSee
steps:
Expand Down
6 changes: 3 additions & 3 deletions .github/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ on:
jobs:
test-e2e:
name: ${{ matrix.command }}
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:

# Build packages that have changed (--include & --since), assuming that
# apps build are done already. Otherwise --from & --since
- name: Build
- name: 🏗 Run build
run: yarn build

- name: Run Playwright tests
Expand All @@ -105,7 +105,7 @@ jobs:

notify:
name: Discord Notification
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs:
- test-e2e
if: ${{ failure() }}
Expand Down
28 changes: 12 additions & 16 deletions .github/workflows/ci-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,47 @@ on:
jobs:
build:
name: build
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20.x]
template:
- plate-template
- plate-playground-template
defaults:
run:
working-directory: templates/${{ matrix.template }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
# Fetch all git history so that yarn workspaces --since can compare with the correct commits
# @link https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
fetch-depth: 0
- uses: actions/checkout@v4

- uses: pnpm/[email protected]
name: Install pnpm
with:
version: 8.6.1
run_install: false

- name: Use Node.js 16
uses: actions/setup-node@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: 16
cache: "pnpm"
cache-dependency-path: '**/pnpm-lock.yaml' # THIS PATTERN did the trick for me.
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
name: ♻️ Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
- name: 📥 Install
run: pnpm install

- name: Build
run: pnpm build
- name: 🏗 Run build
run: pnpm build
35 changes: 35 additions & 0 deletions .github/workflows/clean-up-pr-caches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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:
pull_request:
types: [closed]
workflow_dispatch:

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

- name: 🧹 Cleanup
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
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 )

## 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 }}
75 changes: 0 additions & 75 deletions .github/workflows/comment.yml

This file was deleted.

Loading