Skip to content

Commit

Permalink
Merge pull request #4 from soorajshankar/DDN-CLI-June-Updates
Browse files Browse the repository at this point in the history
DDN June changes
  • Loading branch information
robertjdominguez authored Jun 18, 2024
2 parents 2cfe285 + 12333fa commit 3be8dcd
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 14 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/DDN_Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install and Login to DDN CLI
uses: ./ # Uses an action in the root directory
with:
hasura-pat: ${{ secrets.HASURA_PAT }}

- name: Run a ddn command to check the
run: ddn project get --out json
93 changes: 87 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Automate Hasura DDN Deployments

This repository contains the code to automate the deployment of a Hasura v3 project on [Hasura DDN](https://hasura.io/ddn).
This repository provides everything you need to automate the deployment of a Hasura v3 project on[Hasura DDN](https://hasura.io/ddn). Using GitHub Actions, it simplifies the process of running DDN CLI commands, allowing you to efficiently deploy connectors and build and deploy your supergraph with ease.

## Prerequisites

Expand Down Expand Up @@ -40,27 +40,108 @@ jobs:
## Examples
### Automatic Builds on Every Commit on a branch
### Automatic Builds on Every Commit on a branch and PRs to main branch
Imagine you have a branch called `main` that you use to create a DDN build. You can use the following workflow:

```yaml
name: Automatic Builds from main branch
on:
push:
branches:
- main
- release/*
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy Hasura Project
- name: Checkout repository
uses: actions/checkout@v2
- name: Install and Login to DDN CLI
uses: hasura/[email protected]
with:
hasura-pat: ${{ secrets.HASURA_PAT }}
build_description: "This build was created using CI/CD"
- name: Deploy PG connector and update the connector link
run: ddn connector build create --connector app/connector/mypg/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link mypg --project ${{ secrets.HASURA_PROJECT }}
- name: Deploy mongodb connector and update the connector link
run: ddn connector build create --connector app/connector/my_mongo/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link my_mongo --project ${{ secrets.HASURA_PROJECT }}
- name: Build and deploy TS functions and update the connector link
run: ddn connector build create --connector app/connector/myts/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link myts --project ${{ secrets.HASURA_PROJECT }}
- name: Build and deploy TS functions and update the connector link
run: ddn supergraph build create --supergraph ./supergraph.cloud.yaml --project ${{ secrets.HASURA_PROJECT }} --description "Build for commit ${{ github.sha }}"
```

### Automatic deployments + comment with build details on the PR

![alt text](image.png)

```yaml
on:
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install and Login to DDN CLI
uses: hasura/[email protected]
with:
hasura-pat: ${{ secrets.HASURA_PAT }}
- name: Deploy PG connector and update the connector link
run: ddn connector build create --connector app/connector/mypg/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link mypg --project ${{ secrets.HASURA_PROJECT }}
- name: Deploy mongodb connector and update the connector link
run: ddn connector build create --connector app/connector/my_mongo/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link my_mongo --project ${{ secrets.HASURA_PROJECT }}
- name: Build and deploy TS functions and update the connector link
run: ddn connector build create --connector app/connector/myts/connector.cloud.yaml --target-supergraph supergraph.cloud.yaml --target-connector-link myts --project ${{ secrets.HASURA_PROJECT }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Build and deploy TS functions and update the connector link
run: ddn supergraph build create --supergraph ./supergraph.cloud.yaml --project ${{ secrets.HASURA_PROJECT }} --description "Build for commit ${{ github.sha }}" --out=json > build_output.json
- name: Extract URLs from JSON
id: extract_urls
run: |
BUILD_URL=$(jq -r '.build_url' build_output.json)
CONSOLE_URL=$(jq -r '.console_url' build_output.json)
echo "::set-output name=build_url::$BUILD_URL"
echo "::set-output name=console_url::$CONSOLE_URL"
- name: Add PR comment with build details
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const buildUrl = '${{ steps.extract_urls.outputs.build_url }}';
const consoleUrl = '${{ steps.extract_urls.outputs.console_url }}';
const prNumber = context.payload.pull_request.number;
const commitId = context.sha;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Supergraph build was successful! 🎉\n\n**Build URL:** [${buildUrl}](${buildUrl})\n**Console URL:** [${consoleUrl}](${consoleUrl})\n**Commit ID:** ${commitId}`
});
github-token: ${{ secrets.GITHUB_TOKEN }}
```
## Resources
Expand Down
11 changes: 3 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ inputs:
hasura-pat:
description: "Your PAT, preferably saved as a secret in your repository"
required: true
build_description:
description: "A description to alert other users that this build was created using CI/CD"
required: false
default: "CI/CD via ddn-deployment GitHub Action"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install ddn CLI
shell: bash
run: |
curl -L https://graphql-engine-cdn.hasura.io/ddn/cli/v1/get.sh | bash
curl -L https://graphql-engine-cdn.hasura.io/ddn/cli/v2/get.sh | bash
- name: Login to ddn
run: ddn login --pat ${{ inputs.hasura-pat }}
- name: Build supergraph manifest
run: ddn build supergraph-manifest
shell: bash
run: ddn auth login --pat ${{ inputs.hasura-pat }}
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3be8dcd

Please sign in to comment.