Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
a-masterov committed Dec 5, 2024
1 parent 9e8a4bf commit 3ed9c0a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
55 changes: 55 additions & 0 deletions .github/actions/neon-attach-endpoint-to-branch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Attach an endpoint to the branch'
description: 'Attach an endpoint to the branch'

inputs:
api_key:
description: 'Neon API key'
required: true
project_id:
description: 'ID of the Project to create Branch in'
required: true
api_host:
description: 'Neon API host'
default: console-stage.neon.build
branch_id:
description: 'Branch ID'
required: true
endpoint_id:
description: 'EndPoint ID'
required: true

runs:
using: "composite"
steps:
- name: Attach an endpoint
shell: bash -euxo pipefail {0}
run: |
data=$(jq -nc "{endpoint:{branch_id: \"${BRANCH_ID}\"}}")
ENDPOINT_ID=$(echo ${ENDPOINT_ID} | tr -d \")
for i in {1 10}; do
res=$(curl -X PATCH \
"https://${API_HOST}/api/v2/projects/${PROJECT_ID}/endpoints/${ENDPOINT_ID}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${API_KEY}" \
--data ${data})
echo ${res}
endpoint_id=$(echo $res | jq '.endpoint.id')
if [ -z "${endpoint_id}" ] || [ "${endpoint_id}" == "null" ]; then
sleep 1
continue
fi
break
done
if [ -z "${endpoint_id}" ] || [ "${endpoint_id}" == "null" ]; then
echo Cannot bind endpoint id to branch
exit 1
fi
env:
API_HOST: ${{ inputs.api_host }}
API_KEY: ${{ inputs.api_key }}
PROJECT_ID: ${{ inputs.project_id }}
BRANCH_ID: ${{ inputs.branch_id }}
ENDPOINT_ID: ${{ inputs.endpoint_id }}
37 changes: 7 additions & 30 deletions .github/workflows/cloud-regress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,13 @@ jobs:
add_endpoint: false

- name: Attach the endpoint to the new branch
env:
PROJECT_ID: ${{inputs.project_id}}
ENDPOINT_ID: ${{steps.endpoint-id.outputs.id}}
BRANCH_ID: ${{steps.create-branch.outputs.branch_id}}
API_HOST: console-stage.neon.build
API_KEY: ${{ secrets.NEON_STAGING_API_KEY }}
run: |
data=$(jq -nc "{endpoint:{branch_id: \"${BRANCH_ID}\"}}")
ENDPOINT_ID=$(echo ${ENDPOINT_ID} | tr -d \")
for i in {1 10}; do
res=$(curl -X PATCH \
"https://${API_HOST}/api/v2/projects/${PROJECT_ID}/endpoints/${ENDPOINT_ID}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${API_KEY}" \
--data ${data})
endpoint_id=$(echo $res | jq '.endpoint.id')
if [ -z "${endpoint_id}" ] || [ "${endpoint_id}" == "null" ]; then
sleep 1
continue
fi
break
done
if [ -z "${endpoint_id}" ] || [ "${endpoint_id}" == "null" ]; then
echo Cannot bind endpoint id to branch
exit 1
fi
uses: ./github/actions/neon-get-endpoint
with:
api_key: ${{ secrets.NEON_STAGING_API_KEY }}
project_id: ${{inputs.project-id}}
endpoint_id: ${{steps.endpoint-id.outputs.id}}
branch_id: ${{steps.create-branch.outputs.branch_id}}


- name: Get the connection URI
id: connect-uri
Expand Down

0 comments on commit 3ed9c0a

Please sign in to comment.