Skip to content

Commit

Permalink
refactored the action
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 23, 2023
1 parent f39bdc8 commit 18c1468
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 46 deletions.
47 changes: 1 addition & 46 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,9 @@ jobs:
- name: run tests
run: go test -v ./...
working-directory: ./server
test_migrations:
runs-on: ubuntu-latest
services:
auto_mariadb:
image: bitnami/mariadb:latest
ports:
- 3306:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
manual_mariadb:
image: bitnami/mariadb:latest
ports:
- 3300:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache-dependency-path: |
server/go.sum
- name: wait for db
run: sleep 20
- name: run manual migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "false"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- name: run auto migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "true"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3300)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- uses: ariga/setup-atlas@master
- name: export diff the migrations
run: atlas schema diff --from "maria://root:super_secret_passw0rd@localhost:3306/campus_db" --to "maria://root:super_secret_passw0rd@localhost:3300/campus_db" --format '{{ sql . " " }}'
build:
runs-on: ubuntu-latest
needs: [test, test_migrations]
needs: [test]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/test_migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI
on:
pull_request:
branches: [ main ]
jobs:
test_migrations:
runs-on: ubuntu-latest
services:
auto_mariadb:
image: bitnami/mariadb:latest
ports:
- 3306:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
manual_mariadb:
image: bitnami/mariadb:latest
ports:
- 3300:3306
env:
MARIADB_ROOT_PASSWORD: super_secret_passw0rd
MARIADB_DATABASE: campus_db
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache-dependency-path: |
server/go.sum
- name: wait for db
run: sleep 20
- name: run manual migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "false"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- name: run auto migrations
run: go run main.go
working-directory: ./server
env:
CI_EXIT_AFTER_MIGRATION: "true"
CI_AUTO_MIGRATION: "true"
DB_DSN: root:super_secret_passw0rd@tcp(localhost:3300)/campus_db?charset=utf8mb4&parseTime=True&loc=Local
ENVIRONMENT: dev
- uses: ariga/setup-atlas@master
- name: export diff the migrations
run: atlas schema diff --from "maria://root:super_secret_passw0rd@localhost:3306/campus_db" --to "maria://root:super_secret_passw0rd@localhost:3300/campus_db" --format '{{ sql . " " }}'
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: "${{ github.event.number }}"
body-includes: Found the following differences in the sql schema
comment-author: github-actions[bot]
- run: |
curl \
-X POST \
${{ github.event.pull_request.comments_url }} \
-H "Content-Type: application/json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
--data '{ "body": "Found the following differences in the sql schema: <details><summary>To get from local migrations to auto migration state one woud need to</summary> Block with all the details</details>" }'

0 comments on commit 18c1468

Please sign in to comment.