Skip to content

Commit

Permalink
merge composite action into reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shota-kamezawa committed Jun 12, 2023
1 parent 53fd9cc commit c487bc4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- id: setup-node
uses: actions/setup-node@v3
with:
node-version-file: .tool-versions
node-version: ${{ needs.install-dependencies.outputs.node-version }}

- uses: actions/cache@v3
with:
Expand Down
41 changes: 31 additions & 10 deletions .github/workflows/_install-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
node-modules-cache-path:
description: For 'path' of actions/cache
value: ${{ jobs.install-dependencies.outputs.node-modules-cache-path }}
node-version:
description: Same as of actions/setup-node
value: ${{ jobs.install-dependencies.outputs.node-version }}

env:
NODE_ENV: ${{ inputs.node-env }}
Expand All @@ -22,8 +25,9 @@ jobs:
install-dependencies:
runs-on: ubuntu-latest
outputs:
node-modules-cache-key: ${{ steps.node-modules-cache-key.outputs.key }}
node-modules-cache-path: ${{ steps.node-modules-cache-key.outputs.path }}
node-modules-cache-key: ${{ steps.cache-key.outputs.value }}
node-modules-cache-path: ${{ steps.cache-path.outputs.value }}
node-version: ${{ steps.setup-node.outputs.node-version }}
steps:
- uses: actions/checkout@v3

Expand All @@ -32,17 +36,34 @@ jobs:
with:
node-version-file: .tool-versions

- id: node-modules-cache-key
uses: ./.github/workflows/composite/node-modules-cache-key
with:
node-env: ${{ env.NODE_ENV }}
node-version: ${{ steps.setup-node.outputs.node-version }}
- id: cache-restore-key
name: Define restore key
run: |
NODE_MAJOR=$(echo $NODE_VERSION | cut -f 1 -d .)
echo "value=node-modules-${NODE_MAJOR}-${NODE_ENV}-" >> $GITHUB_OUTPUT
env:
NODE_ENV: ${{ inputs.node-env }}
NODE_VERSION: ${{ steps.setup-node.outputs.node-version }}
shell: bash

- id: cache-key
name: Define cache key
run: echo "value=${RESTORE_KEY}${IDENTIFIER}" >> $GITHUB_OUTPUT
env:
IDENTIFIER: ${{ hashFiles('yarn.lock') }}
RESTORE_KEY: ${{ steps.cache-restore-key.outputs.value }}
shell: bash

- id: cache-path
name: Define cache path
run: echo "value=node_modules" >> $GITHUB_OUTPUT
shell: bash

- uses: actions/cache@v3
with:
key: ${{ steps.node-modules-cache-key.outputs.key }}
path: ${{ steps.node-modules-cache-key.outputs.path }}
restore-keys: ${{ steps.node-modules-cache-key.outputs.restore-keys }}
key: ${{ steps.cache-key.outputs.value }}
path: ${{ steps.cache-path.outputs.value }}
restore-keys: ${{ steps.cache-restore-key.outputs.value }}

- run: yarn install --frozen-lockfile
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- id: setup-node
uses: actions/setup-node@v3
with:
node-version-file: .tool-versions
node-version: ${{ needs.install-dependencies.outputs.node-version }}

- uses: actions/cache@v3
with:
Expand All @@ -48,7 +48,7 @@ jobs:
- id: setup-node
uses: actions/setup-node@v3
with:
node-version-file: .tool-versions
node-version: ${{ needs.install-dependencies.outputs.node-version }}

- uses: actions/cache@v3
with:
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/composite/node-modules-cache-key/action.yml

This file was deleted.

0 comments on commit c487bc4

Please sign in to comment.