jonico / pscale-workflow-helper-scripts

Workflows and helper scripts around the PlanetScale DB workflow to automate database branch creation, association, update and merge directly out of your pull/merge request or favourite CI/CD. This is just a passion project, no official repository from Planetscale.

Home Page:https://youtu.be/l3oe7srRUZw?t=610

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PlanetScale Workflow Helper scripts

📺 DevOpsPro Talk

📺 Recording from live demo at PlanetScale Happy-Half-Hour

📺Longer talk at WeAreDevelopers DevOps Day

This is a collection of GitHub Workflows and CI/CD helper scripts around PlanetScale's database branching workflows to:

IssueOps Example

image (example PR)

Installation

To test out the IssueOps commands and helper scripts, either work on a copy of this repo or run the following command in the root directory of your GitHub repo's workspace and follow the suggestions of the script:

curl https://raw.githubusercontent.com/jonico/pscale-workflow-helper-scripts/main/install.sh | bash

Issue-Ops based workflows

(GitHub Actions workflow source)

/ps-create: Create PlanetScale Deploy Request from your PR

You can create a database branch and deploy request in an already existing Pull Request using /ps-create: image

See configuration section for an explanation of the environment variables to set to specify a PlanetScale org and database different from the default settings.

/ps-attach: Attach existing PlanetScale branch or Deploy Request to your PR

If the PlanetScale deploy request or database branch and your pull request both exist already, you can use the /ps-attach command, followed by the PlanetScale URL to your branch/DR:

image

/ps-update: Refresh schema info in your PR from your attached Deploy Request

If you like to refresh the schema information of your branch or add additional DDL statements, use /ps-update:

image

/ps-approve: Approve Deploy Request from your PR

Approvals can be done using /ps-approve:

image

/ps-merge: Merge Deploy Request attached to your PR

Schema changes in attached deploy requests can then be applied to production by adding a /ps-merge comment to the pull request. This IssueOps command will also create GitHub deployment events, so that you could have other integrations and Action based workflows hook into the deployment lifecycle.

image

/ps-delete: Delete PlanetScale branch attached to your PR

Finally, you can delete the database branch associated with a Git branch using /ps-delete:

image

Stay tuned for updates and any feedbacks / PRs are welcome 😊

Zero-setup Action workflows included ✨

In case you like to see those helper scripts in action without any further manual configuration, just

  1. Create a copy of this repo by clicking on the green 'Use this template' button or just here. Both private and public repo visibility work.

image

  1. Create a PlanetScale account: If you have not done already, sign up here for a PlanetScale account, you can have one database for free. Do not create a database yet though, this step will be automated as part of the first Action workflow.

  2. Switch to the Actions tab in your repo

image

  1. Start the workflows manually, in the displayed order.

image

See configuration section for an explanation of the environment variables to set to specify a PlanetScale org and database different from the default settings.

  1. When you run the workflows, follow the output where it will ask you to authenticate to PlanetScale by clicking the displayed links.

image

If you start the "Create branch/PR for schema change" workflow, a pull request like this one will be created that is associated with a PlanetScale deploy request and the desired schema changes.

image

If you like to install the workflows in your own repository, follow the installation steps.

Configuration

All scripts and IssueOps command in this repo have been designed to run successfully even if zero configuration was provided. If the defaut values do not fit your you, or you do not like to always authorize every action with the Web UI, here are the environment variables you can override in your CI/CD or set as GitHub secrets for your GitHub Action workflows to override default behavior.

DB_NAME

DB_NAME is name of your PlanetScale database. Unless you attach a specific branch or deploy request to your PR, it defaults to example-db-<yourgithubaccount>. If you rather like to change the source for the default DB name, it would be this file.

ORG_NAME

ORG_NAME is name of your PlanetScale organization. Unless you attach a specific branch or deploy request to your PR, it defaults to the first PlanetScale org you joined with your account. If you rather like to change the source for the default DB name, it would be this file.

PLANETSCALE_SERVICE_TOKEN_ID and PLANETSCALE_SERVICE_TOKEN

If you do not like to authorize actions by clicking on authorization links in the browser, you can create a PlanetScale service token. Don't forget to set the proper scopes for the database operations you like to automate.

Note: While service tokens can be used to work with existing databases, there is currently no scope to create new databases. This is why the scripts / workflows to create entirely new databses will always prompt you to authenticate via the Web UI.

CI - Runnning in CI

GitHub Actions and many other CI/CD platforms set the CI variable to true when they run a script. The helper scripts in the .pscale/cli-helper-scripts/ directory will only prompt for interactive user input if the CI variable is not set. In CI mode, it will output additional workflow commands to standard out to enable communication between GitHub Action workflow steps. If you are using a different CI/CD platform than GitHub Actions, you can ignore all lines starting with "::".

Initial table

When you create a bew database from scratch, a default table called pixel_matrix will be created. If you like to change this behavior, modify this file.

About

Workflows and helper scripts around the PlanetScale DB workflow to automate database branch creation, association, update and merge directly out of your pull/merge request or favourite CI/CD. This is just a passion project, no official repository from Planetscale.

https://youtu.be/l3oe7srRUZw?t=610


Languages

Language:Shell 100.0%