chore(deps): update actions/checkout action to v4 #1573
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 幻水総選挙2018 | |
on: | |
push: | |
branches: | |
- '**' | |
tags-ignore: | |
- 'v*.*.*' | |
workflow_dispatch: | |
env: | |
# TODO: Git のタグを取得して、イメージのタグにする | |
DOCKER_IMAGE: asia-northeast1-docker.pkg.dev/${{ secrets.CLOUD_RUN_PROJECT }}/cloud-run-source-deploy/gensosenkyo-2018 | |
GCP_REGION: ${{ secrets.CLOUD_RUN_REGION }} | |
GCP_AUTH_HOST: asia-northeast1-docker.pkg.dev | |
CLOUD_RUN_SERVICE_NAME: gensosenkyo-2018 | |
RAILS_ENV: test | |
PG_HOST_TEST: localhost | |
PG_PORT_TEST: 5432 | |
PG_USERNAME_TEST: postgres_user | |
PG_PASSWORD_TEST: postgres_password | |
jobs: | |
rails_app_test: | |
name: Rails アプリのテスト | |
runs-on: ubuntu-22.04 | |
services: | |
postgres: | |
image: postgres:15.4 | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_USER: postgres_user | |
POSTGRES_PASSWORD: postgres_password | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- name: コードをチェックアウトする | |
uses: actions/checkout@v4 | |
- name: Ruby のセットアップを行う | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: .ruby-version | |
bundler-cache: true | |
- name: データベースをセットアップする | |
run: | | |
bin/rails db:create | |
bin/rails db:migrate | |
bin/rails db:seed | |
- name: RSpec を実行する | |
run: | | |
bundle exec rspec | |
deploy_to_cloud_run: | |
needs: rails_app_test | |
if: ${{ github.ref_name == 'main' }} | |
name: Cloud Run に production デプロイする | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: ソースコードをチェックアウトする | |
uses: actions/checkout@v4 | |
- name: GCP の認証を行う | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_CREDENTIALS }} | |
- name: GCP の CLI の認証を行う | |
run: | | |
gcloud auth configure-docker ${{ env.GCP_AUTH_HOST }} | |
- name: Docker イメージ をビルドする | |
env: | |
DOCKER_BUILDKIT: 1 # '# syntax = docker/dockerfile:1.2' は不要だが、この指定は 2023/01/23 現在、必須 | |
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} | |
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} | |
run: | | |
docker build --secret id=rails_master_key,env=RAILS_MASTER_KEY --secret id=secret_key_base,env=SECRET_KEY_BASE --tag ${{ env.DOCKER_IMAGE }} . | |
- name: Docker イメージ をプッシュする | |
run: | | |
docker push ${{ env.DOCKER_IMAGE }} | |
- name: Deploy to Cloud Run | |
uses: google-github-actions/deploy-cloudrun@v1 | |
with: | |
service: ${{ env.CLOUD_RUN_SERVICE_NAME }} | |
image: ${{ env.DOCKER_IMAGE }} | |
region: ${{ env.GCP_REGION }} | |
- name: Rake タスク(データベース操作など)があれば行う | |
run: | | |
echo 'Rake タスク(データベース操作など)があれば行う' |