Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tk0miya
Last active May 11, 2022 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk0miya/3f5b0aa8a06f74eb043de53a954108ac to your computer and use it in GitHub Desktop.
Save tk0miya/3f5b0aa8a06f74eb043de53a954108ac to your computer and use it in GitHub Desktop.
Rails: DB スキーマの変更がマージされたら自動的に tbls を実行して main ブランチに push する
on:
push:
branches: [main]
paths:
- db/schema.rb
- .tbls.yml
permissions:
contents: write
jobs:
tbls:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
ports:
- 3306:3306
env:
MYSQL_ALLOW_EMPTY_PASSWORD: y
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: true
- name: Install Bundler
run: gem install bundler --no-document -v $(grep "BUNDLED WITH" -1 Gemfile.lock | tail -n 1)
- name: Bundle install
run: bundle install --path=vendor/bundle --jobs 4 --retry 3
- name: DB setup
run: |
cp config/database.yml.example config/database.yml
bundle exec rails db:create db:migrate
- name: Execute tbls
run: |
curl -sL https://git.io/use-tbls > use-tbls.tmp && . ./use-tbls.tmp && rm ./use-tbls.tmp
rm -rf docs/schema
tbls doc
- name: Count changed or untracked files
id: check_diff
run: |
git status --porcelain | wc -l
file_count=$(git status --porcelain | wc -l)
echo "::set-output name=file_count::$file_count"
- name: Commit ER graph
if: ${{ steps.check_diff.outputs.file_count != '0' }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add docs/schema
git commit -m "generate ER graphs from actions"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment