1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub ActionsでenvがUnexpected valueエラーになる原因と正しい書き方

Posted at

はじめに

作成したアプリにCI/CDの設定したところ、以下の問題に直面したため問題点と解決策をまとめます。

問題

Github Actionsで以下のエラーが出た。

(Line: 33, Col: 5): Unexpected value 'FIREBASE_TOKEN',
(Line: 34, Col: 5): Unexpected value 'VITE_SUPABASE_URL',
(Line: 35, Col: 5): Unexpected value 'VITE_SUPABASE_ANON_KEY',
(Line: 33, Col: 5): There's not enough info to determine what you meant.
Add one of these properties: cancel-timeout-minutes, container, continue-on-error, defaults, env, environment, outputs, runs-on, secrets, services, snapshot, steps, timeout-minutes, uses, with

修正前のコード

name: Firebase Hosting CI/CD

on:
  push:
    branches:
      - main

permissions:
  checks: write
  contents: read
  pull-requests: write

jobs:
  build_and_deploy:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
          channelId: live
          projectId: your-project-id

      - name: Deploy to Firebase
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only hosting

  env:
    FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
    VITE_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
    VITE_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}

修正後のコード

name: Firebase Hosting CI/CD

on:
  push:
    branches:
      - main

permissions:
  checks: write
  contents: read
  pull-requests: write

jobs:
  build_and_deploy:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest

    env:
      FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
      VITE_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
      VITE_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}

    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - run: npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
          channelId: live
          projectId: your-project-id

      - name: Deploy to Firebase
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only hosting

エラーの意味と原因

意味

  • ymlファイルの書き方が誤っていることを示している

原因

  • env: を jobs: の外に書いていた
  • GitHub Actions では環境変数 env: を書ける位置が決まっている

終わりに

ymlファイルを作成するのが初めてだったため、エラーが出たことで初めて何が間違っているのかに気づくことができました。
きちんとエラーの意味を読み解くことで解決でき、よかったです!

参考

https://docs.github.com/ja/actions/reference/workflows-and-actions/workflow-syntax#example-of-env
https://docs.github.com/ja/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables?utm_source=chatgpt.com

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?