-
Notifications
You must be signed in to change notification settings - Fork 19
156 lines (134 loc) · 5.83 KB
/
make-docs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Make-docs-to-webpage
# Trigger running when a PR is closed
on:
pull_request:
types: [ closed ]
jobs:
make_docs:
name: Update DB schema files in webpage
# Only run if the PR has been merged (rather than simply closed)
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
env:
POSTGRES_DB: caseflow_certification_test
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports: ["5432:5432"]
steps:
- name: Debugging info
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
# prints GITHUB_CONTEXT env variable
env
- name: Checkout code
uses: actions/checkout@v2
# Since installing a client to Oracle DB is a pain and setting up the VACOLS DB is not necessary, let's skip it.
- name: Remove references to VACOLS Oracle DB
run: |
sed '/ruby-oci8/d' -i Gemfile
sed '/activerecord-oracle_enhanced-adapter/d' -i Gemfile
# Would like to run `bundle lock --update` to update Gemfile.lock without installing gems (to be done in next step)
# but bundler is not installed yet, so manually modify it:
sed '/ruby-oci8/d' -i Gemfile.lock
sed '/^ activerecord-oracle_enhanced-adapter/,/^ [a-z]/{/^ activerecord-oracle_enhanced-adapter/!{/^ [a-z]/!d}}' -i Gemfile.lock
sed '/activerecord-oracle_enhanced-adapter/d' -i Gemfile.lock
sed '/ruby-plsql/d' -i Gemfile.lock
# Remove VACOLS database configuration
# https://stackoverflow.com/questions/6287755/using-sed-to-delete-all-lines-between-two-matching-patterns
sed '/_vacols:$/,/^$/{/^_vacols:$/!{/^$/!d}}' -i config/database.yml
# Even though it won't be used in this script, Rails expects a 'test_vacols' configuration due to "#{Rails.env}_vacols"
echo '# Copied from demo_vacols configuration
test_vacols:
adapter: postgresql
pool: 1
timeout: 5000
database: test-vacols
' >> config/database.yml
- name: Setup Ruby and install gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Setup test database
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
run: |
echo "::group::Set up Caseflow DB"
bin/rails db:create && bin/rails db:schema:load
echo "::endgroup::"
echo "::group::Set up Caseflow ETL DB"
DB=etl bundle exec rake db:create db:schema:load
echo "::endgroup::"
# Skipping VACOLS since Oracle DB is not set up
# bundle exec rake spec:setup_vacols
# Need graphviz to create ERDs
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1
- name: Create DB schema documentation
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
UPDATE_SCHEMA_ERD_IMAGES: true
run: |
ln -s Makefile.example Makefile
echo "::group::Caseflow schema"
make erd-caseflow doc-schema-caseflow
echo "::endgroup::"
echo "::group::Caseflow ETL schema"
make erd-etl doc-schema-etl
echo "::endgroup::"
# Skipping VACOLS since Oracle DB is not set up
# make erd-vacols
# The following is adapted from: https://github.com/SwiftDocOrg/github-wiki-publish-action/blob/v1/entrypoint.sh
# and https://github.com/Andrew-Chen-Wang/github-wiki-action/blob/master/entrypoint.sh
# and https://github.community/t/how-to-updade-repo-wiki-from-github-actions/121151/7
- name: Checkout branch main-gh-pages
uses: actions/checkout@v2
with:
ref: main-gh-pages
path: main-gh-pages_checkout
- name: Copy results of `make docs` to checkout of main-gh-pages
run: |
rsync -av --exclude .git --exclude .keep "docs/schema/" "main-gh-pages_checkout/schema/make_docs/"
- name: Update Jailer-generated DB schema docs for Caseflow using results of `make docs`
env:
POSTGRES_DB: caseflow_certification_test
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
run: |
CASEFLOW_HOME=`pwd`
cd main-gh-pages_checkout/schema/bin
sh ./gen_jailer_schema_docs.sh "$CASEFLOW_HOME" ../make_docs/caseflow-jailer_polymorphic_associations.csv
- name: Compare (and locally commit) generated docs against main-gh-pages branch
id: compare_docs
env:
WIKI_COMMIT_MESSAGE: '`make docs` GH Action: automatically update DB schema documentation files'
WIKI_COMMIT_USER_EMAIL: '[email protected]'
WIKI_COMMIT_USER_NAME: 'samantha-quillman'
run: |
cd main-gh-pages_checkout
make github_action_pre_commit_hook
git add .
if git diff-index --quiet HEAD; then
echo "::set-output name=changes_docs::false"
echo "::group::No changes to make_docs"
ls -alR schema/make_docs
echo "::endgroup::"
else
echo "::set-output name=changes_docs::true"
echo "::group::Committing changes locally"
git config --local user.email "$WIKI_COMMIT_USER_EMAIL"
git config --local user.name "$WIKI_COMMIT_USER_NAME"
git commit -m "$WIKI_COMMIT_MESSAGE"
echo "::endgroup::"
fi