Skip to content

Commit

Permalink
ci: cache deps in github actions (#111)
Browse files Browse the repository at this point in the history
* test cache actions

* remove test action deployment

* update publish-beta action

---------

Co-authored-by: Eugene Chybisov <[email protected]>
  • Loading branch information
Marco and chybisov authored Jul 4, 2023
1 parent 2e61b52 commit 04687b4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
48 changes: 48 additions & 0 deletions .github/actions/yarn-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'Yarn install'
description: 'Run yarn install with node_modules linker and cache enabled'

runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'

- name: Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
# Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
# Yarn cache is also reusable between arch and os.
- name: Restore yarn cache
uses: actions/cache@v3
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-download-cache-
# Invalidated on yarn.lock changes
- name: Restore yarn install state
id: yarn-install-state-cache
uses: actions/cache@v3
with:
path: .yarn/ci-cache/
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}

- name: Install dependencies
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: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
shell: bash
run: |
yarn install --immutable --inline-builds
6 changes: 4 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::403372804574:role/github-actions
role-session-name: github-actions-role-session
aws-region: us-east-2
- name: Amazon ECR login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Install dependencies
uses: ./.github/actions/yarn-install
- name: Build React App
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: yarn install && yarn build
run: yarn build
- name: Deploy app build to S3 bucket
run: |
aws s3 sync ./packages/widget-playground/dist/ s3://playground.li.fi --delete
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v3
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
- name: Install modules
run: yarn install
- name: Install dependencies
uses: ./.github/actions/yarn-install
- name: Build
run: yarn release:build
- name: Publish to npm
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v3
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
- name: Install modules
run: yarn install
- name: Install dependencies
uses: ./.github/actions/yarn-install
- name: Build
run: yarn release:build
- name: Publish to npm
Expand Down

0 comments on commit 04687b4

Please sign in to comment.