Skip to content

ci: add create migration workflow #20

ci: add create migration workflow

ci: add create migration workflow #20

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
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:
credentials_json: ${{ secrets.DEV_GCP_GKE_CLUSTER_SA }}
- name: Set up gcloud sdk
uses: google-github-actions/setup-gcloud@98ddc00a17442e89a24bbf282954a3b65ce6d200 # v2.1.0
- name: Set up kubectl
env:
KUBECTL_VERSION: "v1.27.1"
uses: azure/setup-kubectl@3e0aec4d80787158d308d7b364cb1b702e7feb7f # v4.0.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 }}
# TODO: remove `initialization`
- 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 }}
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