mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-08 05:52:55 +00:00
Add `neon-branch-create` / `neon-branch-delete` to allow using branches in tests. I have a couple of use cases in mind: - For destructive tests with a big DB, we can create the DB once in advance and then use branches without the need to recreate the DB itself after tests change it. - We can run tests in parallel (if there're compute-bound). Also migrate API v2 for `neon-project-create` / `neon-project-delete`
83 lines
2.6 KiB
YAML
83 lines
2.6 KiB
YAML
name: 'Create Neon Project'
|
|
description: 'Create Neon Project using API'
|
|
|
|
inputs:
|
|
api_key:
|
|
desctiption: 'Neon API key'
|
|
required: true
|
|
environment:
|
|
desctiption: 'dev (aka captest) or staging'
|
|
required: true
|
|
region_id:
|
|
desctiption: 'Region ID, if not set the project will be created in the default region'
|
|
required: false
|
|
outputs:
|
|
dsn:
|
|
description: 'Created Project DSN (for main database)'
|
|
value: ${{ steps.create-neon-project.outputs.dsn }}
|
|
project_id:
|
|
description: 'Created Project ID'
|
|
value: ${{ steps.create-neon-project.outputs.project_id }}
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Parse Input
|
|
id: parse-input
|
|
shell: bash -euxo pipefail {0}
|
|
run: |
|
|
case "${ENVIRONMENT}" in
|
|
dev)
|
|
API_HOST=console.dev.neon.tech
|
|
REGION_ID=${REGION_ID:-eu-west-1}
|
|
;;
|
|
staging)
|
|
API_HOST=console.stage.neon.tech
|
|
REGION_ID=${REGION_ID:-us-east-1}
|
|
;;
|
|
*)
|
|
echo 2>&1 "Unknown environment=${ENVIRONMENT}. Allowed 'dev' or 'staging' only"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo "api_host=${API_HOST}" >> $GITHUB_OUTPUT
|
|
echo "region_id=${REGION_ID}" >> $GITHUB_OUTPUT
|
|
env:
|
|
ENVIRONMENT: ${{ inputs.environment }}
|
|
REGION_ID: ${{ inputs.region_id }}
|
|
|
|
- name: Create Neon Project
|
|
id: create-neon-project
|
|
# A shell without `set -x` to not to expose password/dsn in logs
|
|
shell: bash -euo pipefail {0}
|
|
run: |
|
|
project=$(curl \
|
|
"https://${API_HOST}/api/v2/projects" \
|
|
--fail \
|
|
--header "Accept: application/json" \
|
|
--header "Content-Type: application/json" \
|
|
--header "Authorization: Bearer ${API_KEY}" \
|
|
--data "{
|
|
\"project\": {
|
|
\"name\": \"Created by actions/neon-project-create; GITHUB_RUN_ID=${GITHUB_RUN_ID}\",
|
|
\"platform_id\": \"aws\",
|
|
\"region_id\": \"${REGION_ID}\",
|
|
\"settings\": { }
|
|
}
|
|
}")
|
|
|
|
# Mask password
|
|
echo "::add-mask::$(echo $project | jq --raw-output '.roles[] | select(.name != "web_access") | .password')"
|
|
|
|
dsn=$(echo $project | jq --raw-output '.connection_uris[0].connection_uri')
|
|
echo "::add-mask::${dsn}"
|
|
echo "dsn=${dsn}" >> $GITHUB_OUTPUT
|
|
|
|
project_id=$(echo $project | jq --raw-output '.project.id')
|
|
echo "project_id=${project_id}" >> $GITHUB_OUTPUT
|
|
env:
|
|
API_KEY: ${{ inputs.api_key }}
|
|
API_HOST: ${{ steps.parse-input.outputs.api_host }}
|
|
REGION_ID: ${{ steps.parse-input.outputs.region_id }}
|