-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
174 lines (150 loc) Β· 7.1 KB
/
export.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Export JSON/XML/YAML/CSV/MYSQL/PSQL/SQLITE
on:
push:
branches:
- master
paths-ignore:
- "**"
- "!scripts/export**"
workflow_dispatch:
inputs:
pass:
description: "Passcode"
required: true
jobs:
export:
name: JSON/XML/YAML/CSV/MYSQL/PSQL/SQLITE/SQLSERVER
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [8.1]
node-version: [20.x]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
ref: ${{ github.head_ref }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: intl #optional
coverage: none
ini-values: "post_max_size=256M" #optional
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Start MySQL service
run: |
sudo systemctl start mysql.service
mysql -V
- name: Start PostgreSQL service
run: |
sudo systemctl start postgresql.service
pg_isready
pg_lsclusters
sudo -u postgres psql -c "CREATE DATABASE world;"
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo -u postgres psql -c "\l"
- name: Add clean commands to world.sql
run: |
grep -v "DROP TABLE" sql/world.sql > tmpfile && mv tmpfile sql/world.sql
echo -e "DROP TABLE IF EXISTS \`regions\`;\n\n$(cat sql/world.sql)" > sql/world.sql
echo -e "DROP TABLE IF EXISTS \`subregions\`;\n$(cat sql/world.sql)" > sql/world.sql
echo -e "DROP TABLE IF EXISTS \`countries\`;\n$(cat sql/world.sql)" > sql/world.sql
echo -e "DROP TABLE IF EXISTS \`states\`;\n$(cat sql/world.sql)" > sql/world.sql
echo -e "DROP TABLE IF EXISTS \`cities\`;\n$(cat sql/world.sql)" > sql/world.sql
- name: Setup MySQL DB
run: |
ls -R
mysql -uroot -proot -e "CREATE DATABASE world;"
mysql -uroot -proot -e "SHOW DATABASES;"
mysql -uroot -proot --default-character-set=utf8mb4 world < sql/world.sql
- name: Setup & Run NMIG (MySQL to PostgreSQL)
run: |
cp nmig.config.json nmig/config/config.json
cd nmig
npm install
npm run build
npm start
- name: Setup MySQLtoSQLite
run: |
python -m pip install --upgrade pip
pip install mysql-to-sqlite3
mysql2sqlite --version
- name: Setup variables
run: |
echo "region_count=$(mysql -uroot -proot -e 'SELECT COUNT(*) FROM world.regions;' -s)" >> $GITHUB_ENV
echo "subregion_count=$(mysql -uroot -proot -e 'SELECT COUNT(*) FROM world.subregions;' -s)" >> $GITHUB_ENV
echo "country_count=$(mysql -uroot -proot -e 'SELECT COUNT(*) FROM world.countries;' -s)" >> $GITHUB_ENV
echo "state_count=$(mysql -uroot -proot -e 'SELECT COUNT(*) FROM world.states;' -s)" >> $GITHUB_ENV
echo "city_count=$(mysql -uroot -proot -e 'SELECT COUNT(*) FROM world.cities;' -s)" >> $GITHUB_ENV
echo "current_date=$(date +'%dth %b %Y')" >> $GITHUB_ENV
- name: Composer Dependencies
run: |
cd scripts/vendor
composer install
- name: Export JSON
run: |
php scripts/export.php
- name: Export XML
run: |
php scripts/export_xml.php
- name: Export YAML
run: |
php scripts/export_yaml.php
- name: Export CSV
run: |
php scripts/export_csv.php
- name: Export MySQL SQL
run: |
mysqldump -uroot -proot --add-drop-table --disable-keys --set-charset --skip-add-locks world regions > sql/regions.sql
mysqldump -uroot -proot --add-drop-table --disable-keys --set-charset --skip-add-locks world subregions > sql/subregions.sql
mysqldump -uroot -proot --add-drop-table --disable-keys --set-charset --skip-add-locks world countries > sql/countries.sql
mysqldump -uroot -proot --add-drop-table --disable-keys --set-charset --skip-add-locks world states > sql/states.sql
mysqldump -uroot -proot --add-drop-table --disable-keys --set-charset --skip-add-locks world cities > sql/cities.sql
- name: Export PostgreSQL SQL
env:
PGPASSWORD: postgres
run: |
pg_dump --dbname=postgresql://postgres:postgres@localhost/world -Fp --inserts --clean -t regions > psql/regions.sql
pg_dump --dbname=postgresql://postgres:postgres@localhost/world -Fp --inserts --clean -t subregions > psql/subregions.sql
pg_dump --dbname=postgresql://postgres:postgres@localhost/world -Fp --inserts --clean -t countries > psql/countries.sql
pg_dump --dbname=postgresql://postgres:postgres@localhost/world -Fp --inserts --clean -t states > psql/states.sql
pg_dump --dbname=postgresql://postgres:postgres@localhost/world -Fp --inserts --clean -t cities > psql/cities.sql
pg_dump --dbname=postgresql://postgres:postgres@localhost/world -Fp --inserts --clean > psql/world.sql
- name: Export SQLite
run: |
mysql2sqlite -d world -t regions --mysql-password root -u root -f sqlite/regions.sqlite3
mysql2sqlite -d world -t subregions --mysql-password root -u root -f sqlite/subregions.sqlite3
mysql2sqlite -d world -t countries --mysql-password root -u root -f sqlite/countries.sqlite3
mysql2sqlite -d world -t states --mysql-password root -u root -f sqlite/states.sqlite3
mysql2sqlite -d world -t cities --mysql-password root -u root -f sqlite/cities.sqlite3
mysql2sqlite -d world --mysql-password root -u root -f sqlite/world.sqlite3
- name: Export SQL Server
run: |
php scripts/export_sql_server.php
- name: Update README.md
run: |
sed -i "s/Total Regions : [0-9]* <br>/Total Regions : $region_count <br>/" README.md
sed -i "s/Total Sub Regions : [0-9]* <br>/Total Sub Regions : $subregion_count <br>/" README.md
sed -i "s/Total Countries : [0-9]* <br>/Total Countries : $country_count <br>/" README.md
sed -i "s/Total States\/Regions\/Municipalities : [0-9]* <br>/Total States\/Regions\/Municipalities : $state_count <br>/" README.md
sed -i "s/Total Cities\/Towns\/Districts : [0-9]* <br>/Total Cities\/Towns\/Districts : $city_count <br>/" README.md
sed -i "s/Last Updated On : .*$/Last Updated On : $current_date/" README.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: Add exported JSON, CSV, XML, YAML, MYSQL, PSQL, SQLITE & SQL Server files
committer: Darshan Gada <[email protected]>
signoff: true
branch: export/Files
delete-branch: true
title: "(chore): Export JSON, CSV, XML, YAML, MYSQL, PSQL, SQLITE & SQL Server files"
labels: |
exports
automated
reviewers: dr5hn