Skip to content

Commit

Permalink
ci: 파이프라인 버전 최신화 반영 및 빌드 캐시 적용 (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
saseungmin authored Aug 10, 2024
1 parent 7f8c9b5 commit a126aaa
Showing 1 changed file with 58 additions and 39 deletions.
97 changes: 58 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,55 @@ env:
CACHED_DEPENDENCY_PATHS: |
${{ github.workspace }}/.yarn/cache
${{ github.workspace }}/.yarn/unplugged
${{ github.workspace }}/.pnp.*
CACHED_BUILD_PATHS: ${{ github.workspace }}/.next
BUILD_CACHE_KEY: ${{ github.sha }}
DEFAULT_NODE_VERSION: "v20.12.2"
DEFAULT_YARN_VERSION: "4.4.0"

jobs:
job_install_dependencies:
name: Install Dependencies
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}

- name: Set up Yarn
run: |
corepack enable
yarn set version ${{ env.DEFAULT_YARN_VERSION }}
yarn --version
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Compute dependency cache key
id: compute_lockfile_hash
run: echo "::set-output name=hash::${{ hashFiles('yarn.lock') }}"
run: echo "hash=${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}" >> $GITHUB_OUTPUT

- name: Check dependency cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache_dependencies
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
path: |
${{ env.CACHED_DEPENDENCY_PATHS }}
${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit == ''
if: steps.cache_dependencies.outputs.cache-hit != 'true'
run: yarn install --immutable

outputs:
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
yarn_cache_dir_path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
${{ env.CACHED_DEPENDENCY_PATHS }}
job_build:
name: Build
Expand All @@ -51,23 +67,28 @@ jobs:
timeout-minutes: 15
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}

- name: Check dependency cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
path: ${{ needs.job_install_dependencies.outputs.yarn_cache_dir_path }}
key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}

- name: Compute build cache key
id: compute_build_cache_key
run: echo "hash=${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}" >> $GITHUB_OUTPUT

- name: Check build cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache_built_packages
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
key: ${{ steps.compute_build_cache_key.outputs.hash }}

- name: Create env file
run: |
Expand All @@ -76,31 +97,34 @@ jobs:
echo NEXT_PUBLIC_ORIGIN = ${{ secrets.NEXT_PUBLIC_ORIGIN }} >> .env
echo NEXT_PUBLIC_GA_MEASUREMENT_ID = ${{ secrets.NEXT_PUBLIC_GA_MEASUREMENT_ID }} >> .env
cat .env
- name: Build
if: steps.cache_built_packages.outputs.cache-hit == ''
if: steps.cache_built_packages.outputs.cache-hit != 'true'
run: yarn build

outputs:
yarn_cache_dir_path: ${{ needs.job_install_dependencies.outputs.yarn_cache_dir_path }}
dependency_cache_key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}
build_cache_key: ${{ steps.compute_build_cache_key.outputs.hash }}

continuous-integration:
name: check unit test & lint
needs: [job_install_dependencies]
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}

- name: Check dependency cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
path: ${{ needs.job_install_dependencies.outputs.yarn_cache_dir_path }}
key: ${{ needs.job_install_dependencies.outputs.dependency_cache_key }}

- name: Check Lint
Expand All @@ -122,53 +146,48 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}

- name: Check dependency cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
path: ${{ needs.job_build.outputs.yarn_cache_dir_path }}
key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
key: ${{ needs.job_build.outputs.build_cache_key }}

- name: Analyze bundle sizes
uses: transferwise/actions-next-bundle-analyzer@master
uses: transferwise/actions-next-bundle-analyzer@v2
with:
workflow-id: ci.yml
base-branch: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}

job_publish_storybook_chromatic:
name: Chromatic Publish
needs: [job_install_dependencies]
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}

- name: Set node linker to nodeModules
run: yarn config set nodeLinker "node-modules"

- name: Install dependencies
run: yarn install --immutable

- uses: chromaui/action@v1
- name: Publish Project to Chromatic
uses: chromaui/action@latest
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
skip: "dependabot/**"
exitOnceUploaded: true
onlyChanged: true
autoAcceptChanges: true
buildScriptName: "build-storybook"

0 comments on commit a126aaa

Please sign in to comment.