-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pscale helper scripts and IssueOps workflows
- Loading branch information
Showing
30 changed files
with
2,321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: 02 - Add Operation Column & Index | ||
|
||
on: | ||
workflow_dispatch | ||
|
||
env: | ||
pscale_base_directory: .pscale | ||
|
||
jobs: | ||
|
||
add-operation-column-and-index: | ||
name: "Add operation - click here" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Add operation - if asked, please click on displayed link to authenticate | ||
timeout-minutes: 3 | ||
env: | ||
PLANETSCALE_SERVICE_TOKEN_NAME: ${{secrets.PLANETSCALE_SERVICE_TOKEN_NAME}} | ||
PLANETSCALE_SERVICE_TOKEN: ${{secrets.PLANETSCALE_SERVICE_TOKEN}} | ||
ORG_NAME: ${{secrets.ORG_NAME}} | ||
DB_NAME: ${{secrets.DB_NAME}} | ||
GITHUB_USER: ${{github.actor}} | ||
working-directory: ${{env.pscale_base_directory}}/cli-helper-scripts/ | ||
run: ./add-operation-column-and-index.sh | ||
- name: Please check out deployment request and branch connection string from step above | ||
run: | | ||
echo "Please check out deployment request and branch connection string from step above." | ||
sleep 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: 01 - Create Database | ||
|
||
on: | ||
workflow_dispatch | ||
|
||
env: | ||
pscale_base_directory: .pscale | ||
|
||
jobs: | ||
|
||
create-database: | ||
name: "Create database - click here" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create database - please click on displayed link to authenticate | ||
timeout-minutes: 3 | ||
env: | ||
PLANETSCALE_SERVICE_TOKEN_NAME: ${{secrets.PLANETSCALE_SERVICE_TOKEN_NAME}} | ||
ORG_NAME: ${{secrets.ORG_NAME}} | ||
DB_NAME: ${{secrets.DB_NAME}} | ||
GITHUB_USER: ${{github.actor}} | ||
working-directory: ${{env.pscale_base_directory}}/cli-helper-scripts/ | ||
run: ./create-database.sh | ||
- name: Please set MY_DB_URL with instructions from step above | ||
run: | | ||
echo "Have a look at the end of the output of the previous step to find your one-time link with instructions how to set the database repo secret ..." | ||
sleep 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
name: Create branch/PR for schema change | ||
|
||
env: | ||
pscale_base_directory: .pscale | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
branch: | ||
description: DB and PR branch name | ||
required: true | ||
default: "add-operation-column-and-index" | ||
ddl_statements: | ||
description: 'DDL statements to run in new branch' | ||
required: true | ||
default: 'alter table pixel_matrix add column operation varchar(10) default NULL; create index environment_operation on pixel_matrix(environment, operation);' | ||
|
||
jobs: | ||
create_branch_dr_and_pr: | ||
name: Create branch/PR/DR - click here | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
||
- name: Validate parameters | ||
id: validate_params | ||
uses: actions/github-script@v3 | ||
env: | ||
BRANCH_NAME: ${{ github.event.inputs.branch }} | ||
DDL_STATEMENTS: ${{ github.event.inputs.ddl_statements }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const branch_name = process.env.BRANCH_NAME; | ||
const ddl_statements = process.env.DDL_STATEMENTS; | ||
if (! /^[a-zA-Z0-9_-]+$/.test(branch_name)) { | ||
const error = `The branch name contains illegal characters: ${branch_name}`; | ||
core.error(error); | ||
core.setFailed(error); | ||
} | ||
if (! /^.*;$/.test(ddl_statements)) { | ||
const error = `The ddl statements do not end with an ;: ${ddl_statements}`; | ||
core.error(error); | ||
core.setFailed(error); | ||
} | ||
core.setOutput('branch_name', branch_name); | ||
core.setOutput('ddl_statements', ddl_statements); | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create DB branch and deploy request- if asked, please click on displayed link to authenticate | ||
id: create-db-branch-and-dr | ||
timeout-minutes: 3 | ||
env: | ||
PLANETSCALE_SERVICE_TOKEN_NAME: ${{secrets.PLANETSCALE_SERVICE_TOKEN_NAME}} | ||
PLANETSCALE_SERVICE_TOKEN: ${{secrets.PLANETSCALE_SERVICE_TOKEN}} | ||
ORG_NAME: ${{secrets.ORG_NAME}} | ||
DB_NAME: ${{secrets.DB_NAME}} | ||
GITHUB_USER: ${{github.actor}} | ||
DDL_STATEMENTS: ${{ steps.validate_params.outputs.ddl_statements }} | ||
BRANCH_NAME: ${{ steps.validate_params.outputs.branch_name }} | ||
working-directory: ${{env.pscale_base_directory}}/cli-helper-scripts/ | ||
run: | | ||
./create-db-branch-dr-and-connection.sh "$BRANCH_NAME" "$DDL_STATEMENTS" | ||
- name: Write information about associated PS database entities | ||
env: | ||
BRANCH_NAME: ${{ steps.create-db-branch-and-dr.outputs.BRANCH_NAME }} | ||
DB_NAME: ${{ steps.create-db-branch-and-dr.outputs.DB_NAME }} | ||
ORG_NAME: ${{ steps.create-db-branch-and-dr.outputs.ORG_NAME }} | ||
DEPLOY_REQUEST_NUMBER: ${{ steps.create-db-branch-and-dr.outputs.DEPLOY_REQUEST_NUMBER }} | ||
DEPLOY_REQUEST_URL: ${{ steps.create-db-branch-and-dr.outputs.DEPLOY_REQUEST_URL }} | ||
BRANCH_URL: ${{ steps.create-db-branch-and-dr.outputs.BRANCH_URL }} | ||
working-directory: ${{env.pscale_base_directory}}/cli-helper-scripts/ | ||
run: | | ||
mkdir -p ../env/ | ||
envsubst < ps-env-template.sh > ../env/ps-env-${BRANCH_NAME}.sh | ||
chmod a+x ../env/ps-env-${BRANCH_NAME}.sh | ||
- name: Create corresponding Git branch and Pull Request | ||
id: create_pr | ||
uses: peter-evans/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
branch: ${{ steps.validate_params.outputs.branch_name }} | ||
title: ${{ steps.validate_params.outputs.branch_name }} | ||
delete-branch: true | ||
commit-message: "DDL statements for DB branch ${{ steps.validate_params.outputs.branch_name }}" | ||
body: > | ||
This PR contains the code changes needed to go along with the following database changes: | ||
* :seedling: __DB-Branch__: [${{ steps.create-db-branch-and-dr.outputs.branch_name }}](${{ steps.create-db-branch-and-dr.outputs.BRANCH_URL }}) | ||
* :train2: __Deploy-Request URL__: ${{ steps.create-db-branch-and-dr.outputs.DEPLOY_REQUEST_URL }} | ||
* :lock: __Branch connection info__: [One-time link](${{ steps.create-db-branch-and-dr.outputs.CONNECTION_STRING_LINK }}) | ||
<details> | ||
<summary>:scroll: Proposed DDL-Statements:</summary> | ||
``` | ||
${{ steps.validate_params.outputs.ddl_statements }} | ||
``` | ||
</details> | ||
<details> | ||
<summary>📖 Calculated schema changes:</summary> | ||
``` | ||
${{ steps.create-db-branch-and-dr.outputs.BRANCH_DIFF }} | ||
``` | ||
</details> | ||
If you are ok with the schema changes and have carefully reviewed them, you can merge them with a `/ps-merge` comment | ||
- name: Please check out branch and deployment request / PR created | ||
run: | | ||
echo "::notice ::Please check out deployment request and branch in created PR: ${{ steps.create_pr.outputs.pull-request-url }}" | ||
sleep 10 |
Oops, something went wrong.