Last active
November 8, 2021 11:33
-
-
Save junara/99df854e984ae283c38117c865bf2845 to your computer and use it in GitHub Desktop.
GitHub Actions で MySQL + Rails の構成で Annotateを実行してPRを作成する
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
default: &default | |
adapter: mysql2 | |
host: <%= ENV['MYSQL_HOST'] || '127.0.0.1' %> | |
port: <%= ENV['MYSQL_PORT'] || 3306 %> | |
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | |
timeout: 5000 | |
development: | |
<<: *default | |
database: <%= ENV['MYSQL_DATABASE'] || 'junara_annotate_development' %> | |
username: <%= ENV['MYSQL_USER'] || 'root' %> | |
password: <%= ENV['MYSQL_PASSWORD'] || 'password' %> | |
test: | |
<<: *default | |
database: junara_annotate_test | |
username: root | |
password: password | |
production: | |
<<: *default | |
database: junara_annotate_production |
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: Annotate | |
on: | |
workflow_dispatch: # Actionsタブから実行できるようにする。 | |
jobs: | |
createAnnotatePullRequest: | |
services: | |
mysql: | |
image: mysql:5.7 # 8はわからん。 | |
env: | |
MYSQL_ROOT_PASSWORD: password | |
MYSQL_DATABASE: junara_annotate_test | |
ports: | |
- 3306:3306 | |
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10 | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ ubuntu-latest ] | |
ruby: [ 3.0 ] # ruby version指定。matrixでなくても可。 | |
env: | |
ENV: test | |
MYSQL_HOST: 127.0.0.1 # localhostだとつながらない | |
MYSQL_PORT: 3306 | |
MYSQL_DATABASE: junara_annotate_test # servicesの MYSQL_DATABASEと合わせる | |
MYSQL_USER: root | |
MYSQL_PASSWORD: password # servicesの MYSQL_ROOT_PASSWORDとあわせる | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: ${{ matrix.ruby }} # bundle installもやってくれる | |
bundler-cache: true # cacheする。 | |
- name: Run annotate | |
run: | | |
bundle exec rails db:migrate:reset # annotateが読み取れるようにmigrationし直す | |
bundle exec annotate --models --with-comment # annotateを実行する | |
- name: Skip db/schema.rb | |
run: | | |
git checkout db/schema.rb # mysqlの起動設定が、異なるといつもとことなる schema.rbがcommitされてしまうので、commitされないようにする。 | |
- name: set datetime_str to env | |
run: | | |
echo "DATETIME_STR=$(date '+%Y%m%d%H%M%S')" >> $GITHUB_ENV # PRのTITLEに日付を入れるため | |
- name: Create Pull Request | |
id: cpr | |
uses: peter-evans/create-pull-request@v3 # GitHub ActionsでPull requestを作る時の定番 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} # committerがGitHubならこれでOK | |
commit-message: Update annotate # コミットメッセージ | |
committer: GitHub <noreply@github.com> | |
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> # ここら辺変更する場合は tokenの変更も必要そう(未確認) | |
signoff: false | |
branch: create-pull-request/annotate/${{ env.DATETIME_STR }} # ブランチ名。 | |
delete-branch: true | |
title: '[Annotate] annotate --models --with-comment' | |
body: | | |
- Update model annotations | |
- Auto-generated by [create-pull-request][1] | |
[1]: https://github.com/peter-evans/create-pull-request | |
draft: false | |
base: development # PRを作成するベースブランチ。このGitHub Actionsを実行する時にここからbranchを作成し、ここに(developmentブランチに)PRを作成する。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment