Skip to content

Commit

Permalink
ci: add create migration workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
  • Loading branch information
cre8ivejp committed Apr 10, 2024
1 parent 1c6bce1 commit 45bb3c1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/create-migration-file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Create a migration file
on:
push: # TODO: remove after testing
branches:
- ci-migration-file
workflow_dispatch:
inputs:
migration_name:
description: "Migration name"
type: string
required: true
default: "initialization"

env:

CLUSTER_NAME: dev
PROJECT_NAME: bucketeer-dev-srv
REGION: asia-northeast1

jobs:
create-migration-file:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- uses: actions/checkout@v4

- name: Authenticate to GCP
id: auth
uses: google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c # v2.1.2
with:
# service_account: ${{ secrets.DEV_GCP_GKE_SERVICE_ACCOUNT_MAIL_ADDRESS }}
# project_id: ${{ secrets.DEV_PROJECT_NAME }}
# workload_identity_provider: ${{ secrets.DEV_GCP_WORKLOAD_IDENTITY_PROVIDER }}
credentials_json: ${{ secrets.DEV_GCP_GKE_CLUSTER_SA }}

- name: Set up gcloud sdk
uses: google-github-actions/setup-gcloud@ee9693ff89cdf73862b8a13988f6a71070e8fc58 # v0.6.2

- name: Set up kubectl
env:
KUBECTL_VERSION: v1.21.14
uses: azure/setup-kubectl@7f7e5ba5ea3e491b92e6e8e5819963f8f3a1f076 # v3.0
with:
version: ${{ env.KUBECTL_VERSION }}

- name: Setup Atlas CLI
uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0

- name: Setup Docker
uses: crazy-max/ghaction-setup-docker@c2351bbd0bfab8cd65e684219ad8ea46a6d093f3 # v3.1.0

# make create-migration NAME=${{ github.event.inputs.migration_name }} MYSQL_USER=${{ secrets.DEV_MYSQL_USER }} MYSQL_PASS=${{ secrets.DEV_MYSQL_PASS }} MYSQL_HOST=${{ secrets.DEV_MYSQL_HOST }} MYSQL_PORT=${{ secrets.DEV_MYSQL_PORT }} MYSQL_DB=${{ secrets.DEV_MYSQL_DB }}
- name: Create the migration file
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials ${{ secrets.DEV_CLUSTER_NAME }} --project=${{ secrets.DEV_PROJECT_NAME }} --region=${{ secrets.DEV_REGION }}
echo "----------------------- ${{ github.event.inputs.migration_name }}"
atlas migrate diff initialization \
--dir file://migration/mysql \
--to mysql://${{ secrets.DEV_MYSQL_USER }}:${{ secrets.DEV_MYSQL_PASS }}@${{ secrets.DEV_MYSQL_HOST }}:${{ secrets.DEV_MYSQL_PORT }}/${{ secrets.DEV_MYSQL_DB }} \
--dev-url docker://mysql/8
ls -la ${{ github.workspace }}/migration/mysql
cat ${{ github.workspace }}/migration/mysql/*
# - name: Create the pull request
# id: create-docs-pull-request
# uses: peter-evans/create-pull-request@b1ddad2c994a25fbc81a28b3ec0e368bb2021c50 # v6.0.0
# with:
# token: ${{ secrets.ACTIONS_PAT }}
# committer: bucketeer-bot <[email protected]>
# author: bucketeer-bot <[email protected]>
# commit-message: "chore: create migration file for ${{ github.event.inputs.migration_name }}"
# title: "chore: create migration file for ${{ github.event.inputs.migration_name }}"
# branch: "chore-migration-pr"
# delete-branch: true
1 change: 1 addition & 0 deletions migration/mysql/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

0 comments on commit 45bb3c1

Please sign in to comment.