🖼️

GitHub Actions上のreg-suit runで発生したError: Region is missingへの対応

2024/04/18に公開

状況

  • Github Actions上で、S3 + reg-suitを使って差分検知テストをしている
  • Storybookのバージョンを上げた(^7.6.17 -> ^8.0.5
  • PR上でreg-suitのActionがコケてる!なんでだ!

結論

調査ログ

  • エラー調査した時に調べた内容のメモ

エラーログ:Error: Region is missing

  • Github Actions上でError: Region is missingが発生してコケているっぽい
yarn screenshot
yarn run v1.22.22
$ storycap --serverCmd "npx http-server storybook-static -p 9001 --quiet" http://localhost:9001 --serverTimeout 60000 --captureTimeout 10000
info Wait for connecting storybook server http://localhost:9001.
info Executable Chromium path: /usr/bin/google-chrome-stable
info Storycap runs with managed mode
info Found 820 stories.
info Screenshot stored: __screenshots__/... in 1149 msec.
...
{...スクリーンショットの保存処理の結果が続く}
...
info Screenshot was ended successfully in 316157 msec capturing 1284 PNGs.
Done in 317.14s.
yarn run v1.22.22
$ reg-suit run
  [reg-suit] info version: 0.14.3
  [reg-suit] info Detected the previous snapshot key: 'XXXXXXXX'
Error: Region is missing
at default (/home/runner/work/foo/bar/node_modules/@smithy/config-resolver/dist-cjs/index.js:117:11)
at /home/runner/work/foo/bar/node_modules/@smithy/node-config-provider/dist-cjs/index.js:72:104
at /home/runner/work/foo/bar/node_modules/@smithy/property-provider/dist-cjs/index.js:79:33
at async coalesceProvider (/home/runner/work/foo/bar/node_modules/@smithy/property-provider/dist-cjs/index.js:106:18)
at async /home/runner/work/foo/bar/node_modules/@smithy/property-provider/dist-cjs/index.js:117:20
at async region (/home/runner/work/foo/bar/node_modules/@smithy/config-resolver/dist-cjs/index.js:142:30)
at async /home/runner/work/foo/bar/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:89:28
at async /home/runner/work/foo/bar/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:120:14
at async /home/runner/work/foo/bar/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  Error: Process completed with exit code 1.

エラーをthrowしているライブラリ内部の処理

export const resolveRegionConfig = <T>(input: T & RegionInputConfig & PreviouslyResolved): T & RegionResolvedConfig => {
  const { region, useFipsEndpoint } = input;

  if (!region) {
    throw new Error("Region is missing"); // この部分で例外がthrowされている
  }

  return {
    ...input,
    region: async () => {
      if (typeof region === "string") {
        return getRealRegion(region);
      }
      const providedRegion = await region();
      return getRealRegion(providedRegion);
    },
    useFipsEndpoint: async () => {
      const providedRegion = typeof region === "string" ? region : await region();
      if (isFipsRegion(providedRegion)) {
        return true;
      }
      return typeof useFipsEndpoint !== "function" ? Promise.resolve(!!useFipsEndpoint) : useFipsEndpoint();
    },
  };
};

Github Actions のシークレットにAWS_REGIONを追加

  • 参照しているS3のリージョンに合わせてAWS_REGION=ap-northeast-1を設定する

Github ActionsのワークフローからAWS_REGIONにアクセスする設定を追加

  • .github/workflows/ci-visual-regression.ymlに設定を追加
      - name: run visual regression test
        run: |
          yarn screenshot
          yarn regression
        env:
          REG_SUIT_CLIENT_ID: ${{ secrets.REG_SUIT_CLIENT_ID }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_REGION: ${{ secrets.AWS_REGION }} # 追加
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_BUCKET_NAME: ${{ secrets.STG_VRT_BUCKET_NAME }}
  • yarnのコマンドは↓の通り
    "screenshot": "storycap --serverCmd \"npx http-server storybook-static -p 9001 --quiet\" http://localhost:9001 --serverTimeout 60000 --captureTimeout 10000",
    "regression": "reg-suit run",

結果

  • もう一度Github Actionsのワークフローを実行したら直った🙌

Discussion