diff --git a/.github/workflows/create-migration-file.yaml b/.github/workflows/create-migration-file.yaml new file mode 100644 index 0000000000..8ff0bcb2f0 --- /dev/null +++ b/.github/workflows/create-migration-file.yaml @@ -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 + # author: bucketeer-bot + # 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 diff --git a/migration/mysql/test.txt b/migration/mysql/test.txt new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/migration/mysql/test.txt @@ -0,0 +1 @@ +test