Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: infrastructure for managing planetscale branches inside of github… #1992

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cypress
node_modules
.github
.next
113 changes: 113 additions & 0 deletions .github/workflows/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Database
on: [pull_request]
jobs:
pscale:
runs-on: ubuntu-latest
env:
PLANETSCALE_SERVICE_TOKEN_NAME: ''
PLANETSCALE_SERVICE_TOKEN: ''
PLANETSCALE_ORG: ''
DATABASE_URL: ''
POSTMARK_CLIENT_ID: ''
JWT_SIGNING_KEY: ''
AUTH0_SECRET: ''
AUTH0_BASE_URL: ''
AUTH0_CLIENT_ID: ''
AUTH0_CLIENT_SECRET: ''
AUTH0_MANAGEMENT_CLIENT_ID: ''
AUTH0_MANAGEMENT_CLIENT_SECRET: ''
AUTH0_ISSUER_BASE_URL: ''

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16.11'

- name: Install tooling
run: |
sudo apt-get update
sudo apt-get install -y jq
docker pull planetscale/pscale:latest
npm install -g yarn

- name: Configure yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Point to yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install modules
run: yarn --frozen-lockfile

- name: Get branch and short sha
id: variables
shell: bash
run: |
echo "::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/})"
echo "::set-output name=sha_short::$(echo $(git rev-parse --short HEAD))"

- name: Create planetscale development branch
container: planetscale/pscale:latest
run: >
docker run \
-e PLANETSCALE_SERVICE_TOKEN_NAME=${{ env.PLANETSCALE_SERVICE_TOKEN_NAME }} \
-e PLANETSCALE_SERVICE_TOKEN=${{ env.PLANETSCALE_SERVICE_TOKEN }} \
-e PLANETSCALE_ORG=${{ env.PLANETSCALE_ORG }} \
planetscale/pscale:latest branch create \
brios-test-env-database \
${{ steps.variables.outputs.branch }}-${{ steps.variables.outputs.sha_short }}-${{ github.run_id }}

- name: Wait for planetscale db branch readiness
container: planetscale/pscale:latest
run: |
echo "Checking if the planetscale db branch is ready to accept connections...👀";
while true; do
echo $(docker run -e PLANETSCALE_SERVICE_TOKEN_NAME=${{ env.PLANETSCALE_SERVICE_TOKEN_NAME }} -e PLANETSCALE_SERVICE_TOKEN=${{ env.PLANETSCALE_SERVICE_TOKEN }} -e PLANETSCALE_ORG=${{ env.PLANETSCALE_ORG }} planetscale/pscale:latest branch list brios-test-env-database --format json | jq -c ".[] | select(.name == \"${{ steps.variables.outputs.branch }}-${{ steps.variables.outputs.sha_short }}-${{ github.run_id }}\") | .ready") > BRANCH_READINESS;
if [[ "$(cat BRANCH_READINESS)" == "false" ]]
then
echo "Branch not ready yet -- checking again in 5 seconds 🐝";
sleep 5;
else
echo "Branch is ready to accept connections! 🚀";
exit 0;
fi
done

- name: Connect to planetscale db branch
container: planetscale/pscale:latest
run: |
docker run \
-e PLANETSCALE_SERVICE_TOKEN_NAME=${{ env.PLANETSCALE_SERVICE_TOKEN_NAME }} \
-e PLANETSCALE_SERVICE_TOKEN=${{ env.PLANETSCALE_SERVICE_TOKEN }} \
-e PLANETSCALE_ORG=${{ env.PLANETSCALE_ORG }} \
-e PSCALE_ALLOW_NONINTERACTIVE_SHELL=true \
-p 3309:3309 \
-d \
planetscale/pscale:latest connect \
brios-test-env-database \
${{ steps.variables.outputs.branch }}-${{ steps.variables.outputs.sha_short }}-${{ github.run_id }} \
--port 3309

- name: Run integration tests
run: |
yarn dev &
sleep 5
yarn test
env:
- name: Delete planetscale db branch
uses: docker://planetscale/pscale:latest
with:
entrypoint: /usr/bin/pscale
args: |
branch delete brios-test-env-database ${{ steps.variables.outputs.branch }}-${{ steps.variables.outputs.sha_short }}-${{ github.run_id }} --force
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node_modules
yarn-error.log
.vercel
cors.json
src/data/local/*
src/data/local/*
tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.11
10 changes: 10 additions & 0 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ generates:
withComponent: false
reactApolloVersion: 3
preResolveTypes: true
./tests/generated/types.ts:
documents:
test/documents/**/*.graphql:
skipGraphQLImport: false
plugins:
- typescript
- typescript-operations
- typed-document-node
config:
enumsAsTypes: true
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts-esm',
testEnvironment: 'node',
globals: {
'ts-jest': {
useESM: true,
},
},
testTimeout: 10000,
}
1 change: 0 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"generate:watch": "graphql-codegen --watch 'src/graphql/**/*.ts'",
"postinstall": "yarn generate && prisma generate",
"db:dev": "pscale connect brianlovin dev --port 3309",
"db:prod": "pscale connect brianlovin main --port 3309"
"db:prod": "pscale connect brianlovin main --port 3309",
"test": "yarn node --experimental-vm-modules --experimental-modules $(yarn bin jest)"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -45,7 +46,7 @@
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"lru-cache": "^6.0.0",
"next": "12.0.0",
"next": "12.0.7",
"next-seo": "^4.28.1",
"postmark": "^2.7.8",
"react": "^17.0.2",
Expand All @@ -71,6 +72,7 @@
"remove-markdown": "^0.3.0",
"slugify": "^1.6.2",
"string-replace-to-array": "^2.1.0",
"ts-node": "^10.8.0",
"turndown": "^7.1.1",
"turndown-plugin-gfm": "^1.0.2",
"unified": "^10.1.0",
Expand All @@ -79,11 +81,14 @@
},
"devDependencies": {
"@ardatan/graphql-tools": "^4.1.0",
"@babel/preset-env": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@bahmutov/add-typescript-to-cypress": "^2.1.2",
"@cypress/webpack-preprocessor": "^4.1.5",
"@fullhuman/postcss-purgecss": "^4.0.3",
"@graphql-codegen/add": "^3.1.0",
"@graphql-codegen/cli": "^2.2.2",
"@graphql-codegen/typed-document-node": "^2.2.2",
"@graphql-codegen/typescript": "^2.3.1",
"@graphql-codegen/typescript-operations": "^2.1.8",
"@graphql-codegen/typescript-react-apollo": "^3.2.1",
Expand All @@ -94,11 +99,13 @@
"@types/jest": "^27.0.2",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.4",
"@types/node-fetch": "^3.0.3",
"@types/react": "^17.0.34",
"@types/webrtc": "^0.0.31",
"@typescript-eslint/parser": "^4.33.0",
"autoprefixer": "^10.3.7",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.4.5",
"cypress": "^8.6.0",
"eslint": "^7.32.0",
"eslint-config-next": "^12.0.3",
Expand All @@ -108,7 +115,9 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"got": "^12.0.0",
"husky": "^7.0.4",
"jest": "^27.4.5",
"lint-staged": "^11.2.4",
"now-env": "^3.2.0",
"postcss": "^8.3.11",
Expand All @@ -120,6 +129,7 @@
"prisma": "^3.4.1",
"stylelint-config-recommended": "^6.0.0",
"tailwindcss": "^2.2.19",
"ts-jest": "^27.1.2",
"typescript": "^4.4.4",
"typescript-eslint-parser": "^22.0.0",
"webpack": "^4.46.0"
Expand Down
Loading