🛠️

GitHubActions個人用まとめ

2021/12/30に公開

下記読めばいいと思いますが、自分用のメモです。
https://docs.github.com/ja/actions

      - name: Debug
        if: ${{ always() }}
        uses: mxschmitt/action-tmate@v3

if: ${{ always() }}で途中でエラーになっても実行されます。

$ php artisan tinker
Psy Shell v0.10.12 (PHP 7.4.26 — cli) by Justin Hileman
>>> config('database.connections.mysql')
=> [
     "driver" => "mysql",
     "url" => null,
     "host" => "127.0.0.1",
     "port" => "3306",
     "database" => "forge",
     "username" => "forge",
     "password" => "",
     "unix_socket" => "",
     "charset" => "utf8mb4",
     "collation" => "utf8mb4_unicode_ci",
     "prefix" => "",
     "prefix_indexes" => true,
     "engine" => null,
     "options" => [],
   ]
>>> DB::connection()->getPdo();
PDOException with message 'SQLSTATE[HY000] [1045] Access denied for user 'forge'@'172.18.0.1' (using password: NO)'

参考になるか分からないですが、下記mysqlを使ったジョブになります。

jobs:
  analyse:
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout"
        uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          extensions: mbstring, mysql
          tools: composer:v2
      - name: Resolve dependencies
        run: composer install --no-progress --prefer-dist --optimize-autoloader
      - name: Run phpstan
        run: ./vendor/bin/phpstan --memory-limit=1G analyse --error-format=github
      - name: Run composer-require-checker
        run: php composer-require-checker.phar check composer.json
  test:
    runs-on: ubuntu-latest
    needs: analyse
    env: 
      DB_HOST: 127.0.0.1
      DB_PASSWORD: root
    steps:
      - name: Set up MySQL
        uses: cweinberger/github-actions-mysql@1.0.0
        with:
          version: 5.7 # Optional, default version is `latest`
          hostPort: 3306 # Optional, default host port is `3306`
          containerPort: 3306 # Optional, default container port is `3306`
          rootPassword: root # Optional, default is `empty` (⚠️ required if you did not specify a user)
          user: root # Optional, default is `empty` (⚠️ required if you did not specify a root password)
          database: narou_test # Optional, default is `TestDatabase`
          characterSet: utf8mb4 # Optional, default is `utf8mb4`
          collation: utf8mb4_general_ci # Optional, default is `utf8mb4_general_ci`
          sqlMode: ""
      - name: "Checkout"
        uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          extensions: mbstring, mysql
          tools: composer:v2
      - name: Resolve dependencies
        run: composer install --no-progress --prefer-dist --optimize-autoloader
      - name: migrate
        run: php artisan migrate --env=testing
      - name: Execute tests (Unit and Feature tests) via PHPUnit
        run: vendor/bin/phpunit
      - name: Debug
        if: ${{ always() }}
        uses: mxschmitt/action-tmate@v3
  deploy:
    runs-on: ubuntu-latest
    needs: test
    steps:
    ...(デプロイのステップは割愛)

Discussion