Code N Solve ๐: Playwright์ Gatsby CI/CD ๊ณผ์ ์์ ๋ฐ์ํ browserType.launch ์ค๋ฅ ๋ฐ ํด๊ฒฐ ๋ฐฉ๋ฒ ์ ๋ฆฌ
์ด์ ์ ํด๊ฒฐํ๋ค๊ณ ์๊ฐํ๋ Playwright1 ๊ด๋ จ ๋ฌธ์ ๊ฐ ๋ค์ ๋ฐ์ํ๋ค.
Gatsby build ๊ณผ์ ์์ ์ง์์ ์ผ๋ก ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค.
๋ฌธ์ : Playwright Chromium ๋ธ๋ผ์ฐ์ ๋ฒ์ ์ฐธ์กฐ ์ค๋ฅ2
- Gatsby ๋ธ๋ก๊ทธ์ ๋ฐฐํฌ๋ฅผ ์ํ GitHub Actions์์ Playwright ์ค์น ์, ์ค๋๋ Chromium ๋ธ๋ผ์ฐ์ ๋ฒ์ (์: chromium-1129)์ ๊ณ์ ์ฐธ์กฐํ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค.
- ์บ์๋ฅผ ๋น์๋ ํด๊ฒฐ๋์ง ์๊ฑฐ๋, ์ต์ ๋ธ๋ผ์ฐ์ ๋ฒ์ (chromium-1134)์ ์ฌ๋ฐ๋ฅด๊ฒ ์ฌ์ฉํ์ง ๋ชปํ๋ค.
-
browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium-1129/chrome-linux/chrome
๋ฌธ์ ๋ถ์
- ์ด์ ์ ์บ์๋ Playwright ๋ธ๋ผ์ฐ์ ๊ฒฝ๋ก๊ฐ GitHub Actions์์ ์ฐธ์กฐ๋๋ฉด์, ์ต์ ๋ฒ์ ์ค์น ํ์๋ ์๋ชป๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํจ.
- Playwright ๊ฒฝ๋ก๋ฅผ ๋ช ํํ๊ฒ ์ง์ ํ์ง ์์ Gatsby ๋น๋์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํจ.
ํด๊ฒฐ ๋ฐฉ๋ฒ
-
Playwright ์บ์ ๊ฐ์ ์ญ์
- ์บ์๋ Playwright ๋ธ๋ผ์ฐ์ ํ์ผ๋ค์ ๊ฐ์ ๋ก ์ญ์ ํ ํ, ์ต์ ๋ฒ์ ์ผ๋ก ๋ค์ ์ค์นํ์๋ค.
-
- name: Remove Playwright Cache run: | rm -rf ~/.cache/ms-playwright rm -rf ~/work/<your-repo-name>/<your-repo-name>/.cache/ms-playwright
- ์์ฉ์ ์์๋ค.
-
Chromium ๊ฒฝ๋ก ๋ช ํํ ์ง์
- Playwright ๋ธ๋ผ์ฐ์ ๋ฅผ ์ค์นํ ํ, ์ต์ Chromium ๊ฒฝ๋ก๋ฅผ ํ์ธํ์ฌ ๋ช ํํ๊ฒ ์ค์ ํ๋ค.
- ์ด๋ฅผ ํ๊ฒฝ ๋ณ์์ ์ ์ฅํ์ฌ GitHub Actions์ Gatsby ๋น๋ ์ ๋ช ์์ ์ผ๋ก ํด๋น ๊ฒฝ๋ก๋ฅผ ์ฐธ์กฐํ๊ฒํ๋ค.
-
- name: Install Playwright and Set Browser Path run: | npx playwright install --with-deps chromium CHROMIUM_DIR=$(ls -d $HOME/.cache/ms-playwright/chromium-*/ | sort -V | tail -n 1) echo "CHROMIUM_DIR=$CHROMIUM_DIR" >> $GITHUB_ENV ls -al $CHROMIUM_DIR
- ์์ฉ์ ์์๋ค.
-
๋น๋ ์ Playwright ๊ฒฝ๋ก ํ์ธ
- ๋น๋ ๋์ค Playwright ๋ธ๋ผ์ฐ์ ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ค์น๋์๋์ง, ๊ทธ๋ฆฌ๊ณ ์ ํํ ๊ฒฝ๋ก๋ฅผ ์ฐธ์กฐํ๊ณ ์๋์ง ํ์ธํ๋ ๋ก๊ทธ๋ฅผ ์ถ๊ฐํ์ฌ ๋๋ฒ๊น ์ ํ์ฉํ๋ค.
-
- name: Verify Playwright Installation and Path run: | npx playwright --version echo "Using Chromium from: $CHROMIUM_DIR" ls -al $CHROMIUM_DIR
-
๋น๋ ์ gatsby ์บ์ ์ญ์
- ๋น๋ ์คํ ์ ์
package.json
์ ์ค์ ํด๋ cache clean ๋ช ๋ น์ด๋ฅผ ๋ฏธ๋ฆฌ ์ฌ์ฉํ์ฌ ๋น๋ ์ ์ด์ cache๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๋น๋ํ์ฌ ์ฌ๋ฐ๋ฅธ ๋๋ ํ ๋ฆฌ๋ฅผ ์ฐพ๋๋ก ํ์๋ค. -
- name: Build with Gatsby env: PREFIX_PATHS: "true" CHROMIUM_DIR: ${{ env.CHROMIUM_DIR }} run: | yarn clean yarn build
- ๋น๋ ์คํ ์ ์
์ต์ข CI/CD ์ํฌํ๋ก
-
CI ํ์ดํ๋ผ์ธ
- ์ต์ Playwright ๋ธ๋ผ์ฐ์ ๋ฅผ
$HOME/.cache/ms-playwright
๊ฒฝ๋ก์ ์ค์นํ๊ณ , ์ด ๋ฒ์ ์ ๊ฒฝ๋ก๋ฅผ ํ๊ฒฝ ๋ณ์๋ก ์ค์ ํ์ฌ ๋น๋ ๊ณผ์ ์์ ํ์ฉํ์๋ค. - ๋, pull request์ push ์ํฉ์ ๋๋์ด ๊ด๋ฆฌํ์๋ค.
-
name: CI on: pull_request: branches: - main push: branches: - main jobs: check_on_pull_request: if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20" - name: Remove Playwright Cache run: | rm -rf ~/.cache/ms-playwright - name: Install Playwright and Chromium Browser run: | npx playwright install --with-deps chromium CHROMIUM_DIR=$(ls -d $HOME/.cache/ms-playwright/chromium-*/ | sort -V | tail -n 1) echo "CHROMIUM_DIR=$CHROMIUM_DIR" >> $GITHUB_ENV ls -al $CHROMIUM_DIR - name: Install node packages run: yarn - name: Check lint run: yarn check:lint - name: Check prettier run: yarn check:prettier build_on_push: if: github.event_name == 'push' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20" - name: Remove Playwright Cache run: | rm -rf ~/.cache/ms-playwright - name: Install Playwright and Chromium Browser run: | npx playwright install --with-deps chromium CHROMIUM_DIR=$(ls -d $HOME/.cache/ms-playwright/chromium-*/ | sort -V | tail -n 1) echo "CHROMIUM_DIR=$CHROMIUM_DIR" >> $GITHUB_ENV ls -al $CHROMIUM_DIR - name: Install node packages run: yarn - name: Build run: yarn build - name: Verify Playwright Installation run: npx playwright --version
- ์ต์ Playwright ๋ธ๋ผ์ฐ์ ๋ฅผ
-
CD ํ์ดํ๋ผ์ธ
- CI๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋๋ฉด ์๋์ผ๋ก ์งํ๋๋ฉด์ build ์ ์ ์บ์ ์ญ์ ํ build๋ฅผ ์งํํ์ฌ ์ด์ ์ ์ฌ์ฉํ๋ ๊ฒฝ๋ก๊ฐ ์๋ ์๋ก์ด ๋ฒ์ ์ playwright๊ฐ ์ค์น๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ๋๋ก ํ์๋ค.
-
name: CD on: workflow_run: workflows: ["CI"] types: - completed permissions: contents: read pages: write id-token: write jobs: build: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Remove Playwright Cache run: | rm -rf ~/.cache/ms-playwright - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "20" - name: Install Project Dependencies and Playwright Browsers run: | yarn install npx playwright install --with-deps chromium CHROMIUM_DIR=$(ls -d $HOME/.cache/ms-playwright/chromium-* | sort -V | tail -n 1) echo "CHROMIUM_DIR=$CHROMIUM_DIR" >> $GITHUB_ENV ls -al $CHROMIUM_DIR - name: Build with Gatsby env: PREFIX_PATHS: "true" CHROMIUM_DIR: ${{ env.CHROMIUM_DIR }} run: | yarn clean yarn build - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: ./public deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4
์ถ๊ฐ
- Gatsby ํ์ด์ง ์ค์ ๋ฐ 404 ์ค๋ฅ ํด๊ฒฐ
- Node.js 20 ๋ฒ์ ์ค์น ํ
actions/configure-pages@v5
์ ์ถ๊ฐํ์ฌ Gatsby ํ์ด์ง๋ฅผ ์ค์ ํ์ฌ ๋น๋๋ ๋ธ๋ก๊ทธ๊ฐ ์ ์์ ์ผ๋ก ๋ฐฐํฌ๋๋๋ก ํ๋ค. -
- name: Setup Pages id: pages uses: actions/configure-pages@v5 with: static_site_generator: gatsby
- Node.js 20 ๋ฒ์ ์ค์น ํ
Github Pages์ ๋์ ๋ฐฉ์:
- Github Pages๋ ์ ์ ์น์ฌ์ดํธ ํธ์คํ ์๋น์ค๋ก, HTML, CSS, JavaScript์ ๊ฐ์ ์ ์ ํ์ผ์ ์ ๊ณตํ๋ค.
- ์ฌ์ฉ์๊ฐ ํน์ URL์ ์ ์ํ๋ฉด, Github Pages๋ ํด๋น URL์ ๋ง๋ HTML ํ์ผ์ ์ฐพ์์ ์ ๊ณตํ๋ค.
- ๋ง์ฝ ํด๋น URL์ ๋ง๋ HTML ํ์ผ์ด ์์ผ๋ฉด, 404 ์ค๋ฅ ํ์ด์ง๋ฅผ ํ์ํ๋ค.
Gatsby์ ํน์ง:
- Gatsby๋ React ๊ธฐ๋ฐ์ ์ ์ ์น์ฌ์ดํธ ์์ฑ ํ๋ ์์ํฌ๋ก ๋น๋ ๊ณผ์ ์์ ๋ชจ๋ ํ์ด์ง๋ฅผ ๋ฏธ๋ฆฌ ์์ฑํ์ฌ ์ ์ HTML ํ์ผ๋ก ์ ์ฅํ๋ค.
- ํ์ง๋ง Gatsby๋ ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ๋ผ์ฐํ ์ ์ฌ์ฉํ์ฌ ํ์ด์ง ์ ํ์ ์ฒ๋ฆฌํ๋ค.3
- ์ฆ, ์ฌ์ฉ์๊ฐ ์น์ฌ์ดํธ ๋ด์์ ๋งํฌ๋ฅผ ํด๋ฆญํ๋ฉด, ์ค์ ๋ก ์๋ก์ด ํ์ด์ง๋ฅผ ์์ฒญํ๋ ๊ฒ์ด ์๋ JavaScript๋ฅผ ํตํด ํ์ด์ง ๋ด์ฉ์ ๋ณ๊ฒฝํ๋ค.
๋ฌธ์ ๋ฐ์ ์์ธ:
actions/configure-pages@v5
4 ์ก์ ์ด ์์ผ๋ฉด, Github Pages๋ Gatsby์ ํด๋ผ์ด์ธํธ ์ฌ์ด๋ ๋ผ์ฐํ ์ ์ดํดํ์ง ๋ชปํ๋ค.5- ์ฌ์ฉ์๊ฐ Gatsby ๋ธ๋ก๊ทธ ๋ด์์ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ํ์ด์ง๋ฅผ ์ ํํ๋ฉด, ์ค์ ๋ก ์๋ก์ด URL์ ์ ์ํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง Github Pages๋ ํด๋น URL์ ๋ง๋ HTML ํ์ผ์ ์ฐพ์ง ๋ชปํด 404 ์ค๋ฅ ํ์ด์ง๋ฅผ ํ์ํ๋ ๊ฒ์ด๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ:
actions/configure-pages@v5
์ก์ ์ฌ์ฉ์ ํตํด, Gatsby ๋ธ๋ก๊ทธ์ ํน์ง์ Github Pages์ ์๋ ค์ค๋ค.- ์ด ์ก์ ์ Gatsby ๋ธ๋ก๊ทธ์ ๋น๋ ๊ฒฐ๊ณผ๋ฅผ ๋ถ์ํ์ฌ, ๊ฐ ํ์ด์ง์ ๋ํ ์ ๋ณด๋ฅผ Github Pages์ ์ ๊ณตํ๋ค.
- ๋ฐ๋ผ์ ์ฌ์ฉ์๊ฐ Gatsby ๋ธ๋ก๊ทธ ๋ด์์ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ํ์ด์ง๋ฅผ ์ ํํ๋๋ผ๋, Github Pages๋ ํด๋น URL์ ๋ง๋ HTML ํ์ผ์ ์ฐพ์์ ์ ๊ณตํ ์ ์๊ฒ ๋๋ค.
๊ฒฐ๋ก
- Playwright ๊ฒฝ๋ก ๋ฌธ์
- ์ต์ playwright ๋ฒ์ ์ ํ์ธํ๊ณ , ํด๋น ๋ฒ์ ์ ์ต์ playwright๋ฅผ ์ฌ์ฉํ๋๋ก, ์ด์ ์บ์๋ฅผ ์ญ์ ํจ์ผ๋ก์จ ์ํ๋ ๋๋ก ์ต์ playwright๋ฅผ ์ฌ์ฉํ๋๋ก ์ง์ ํ ์ ์์๋ค.
- Gatsby ํ์ด์ง ์ค์ ๋ฐ 404 ์ค๋ฅ ํด๊ฒฐ
actions/configure-pages@v5
์ก์ ์ ์ถ๊ฐํ์ฌ Gatsby ํ์ด์ง๋ฅผ ์ค์ ํ๊ณ 404 ํ์ด์ง ์ค๋ฅ๋ฅผ ํด๊ฒฐํ ์ ์์๋ค.
- https://playwright.dev/โฉ
- https://github.com/microsoft/playwright/issues/5767โฉ
- https://www.gatsbyjs.com/docs/conceptual/rendering-options/โฉ
- https://github.com/actions/configure-pages?tab=readme-ov-fileโฉ
- https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/how-gatsby-works-with-github-pages/#github-actionsโฉ