Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandeep-baligeri authored Nov 15, 2024
0 parents commit 022dd05
Show file tree
Hide file tree
Showing 38 changed files with 17,511 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DEV_ORG=
USER_EMAIL=
41 changes: 41 additions & 0 deletions .github/templates/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "2"

name: %PRETTY_NAME%
description: %PRETTY_NAME%

service_account:
display_name: %PRETTY_NAME% Bot

functions:
- name: extraction
description: Extraction function for %PRETTY_NAME%
- name: install_initial_domain_mapping
description: Create blueprint and install initial domain mapping

keyring_types:
- id: example-connection
name: Example Connection
description: Example Connection
kind: "Secret"
is_subdomain: true
secret_config:
secret_transform: ".token" # a JQ query
fields:
- id: token
name: Token
description: Example API token
token_verification:
urL: https://app.devrev.ai/favicon.ico
method: GET

imports:
- slug: %PROJECT_NAME%-extractor
display_name: %PRETTY_NAME%
description: %PRETTY_NAME%
extractor_function: extraction
allowed_connection_types:
- example-connection

hooks:
- type: activate
function: install_initial_domain_mapping
59 changes: 59 additions & 0 deletions .github/workflows/setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Set up the repository
on:
push:
branches: [main]
jobs:
cleanup:
name: Set up the repository
runs-on: ubuntu-latest
if: github.event.repository.name != 'adaas-template'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Replace templates
run: |
shopt -s dotglob
export LC_CTYPE=C
export LANG=C
# Project name is lowercase repository name (used in configs)
PROJECT_NAME="${GITHUB_REPOSITORY,,}" # Of form owner/repo
PROJECT_NAME="${PROJECT_NAME##*/}" # Just the repo name
# Pretty name is how it's displayed in the README (spaces and starting case)
# Since it can contain spaces, it has to be escaped in the sed command
PRETTY_NAME="$(echo "$PROJECT_NAME" | sed 's/-/ /g; s/\b\(.\)/\u\1/g')"
ESCAPED_PRETTY_NAME="$(echo "$PRETTY_NAME" | sed 's/ /\\ /g')"
echo "Project name: '$PROJECT_NAME'"
echo "Pretty name: '$PRETTY_NAME'"
echo "Replacing pretty name: %PRETTY_NAME% -> '$PRETTY_NAME'"
find .github/templates -type f -exec sed -i "s/%PRETTY_NAME%/$ESCAPED_PRETTY_NAME/g" {} \;
echo "Replacing project name: %PROJECT_NAME% -> '$PROJECT_NAME'"
find .github/templates -type f -exec sed -i "s/%PROJECT_NAME%/$PROJECT_NAME/g" {} \;
echo "Moving template files to the root of the repository"
rm -rf manifest.yaml
mv -f .github/templates/* .
rm -rf .github
- name: Commit
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit --amend --no-edit
- name: Push
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
force: true
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# IDE-specific configs
/.vscode/*
.code-workspace
/.idea/*

# Allow run configurations / launch files
!/.idea/runConfigurations
!/.vscode/launch.json

build.tar.gz
nohup.out
.env
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include .env

# export values in .env to be used in the shell scripts
export $(shell sed 's/=.*//' .env)

default:
$(MAKE) build

deps:
cd code && npm ci
.PHONY: deps

build: deps
cd code && npm run build
.PHONY: build

auth:
devrev profiles authenticate --org $(DEV_ORG) --usr $(USER_EMAIL) --expiry 7 # days

.PHONY: auth

deploy: auth
./code/scripts/deploy.sh
.PHONY: deploy

# Removes the latest snap-in from the org. This is useful when you want to
# re-deploy the same snap-in to the same org.
uninstall:
./code/scripts/cleanup.sh
.PHONY: uninstall
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ADaaS Template

This GitHub repository provides a template with example code to implement an Airdrop as a Service (ADaaS) Snap-in .

## Prerequisites

1\. Install [DevRev CLI](https://developer.devrev.ai/snapin-development/references/cli-install) by following the instructions as per the Operating System.

2\. Install [jq](https://jqlang.github.io/jq/download/).

## Build, Deploy and Run

1\. Clone Repository:

- Either clone this repository or create a new repository from it by clicking the "Use this template" button above.
- Set the desired repository name for your own copy (e.g., `<organization>-<external system>-adaas`).

2\. Open the project in your IDE and set up project environment variables, by following these steps:

- Rename `.env.example` to `.env`.
- In `.env` set the slug of your organization, and your email.

4\. Build the Snap-in using the following command:

```bash
make build
```

5\. Deploy the Snap-in to the organization:

```bash
make deploy
```

NOTE: This process may take some time. Command authenticates you to the org using the DevRev CLI, creates a Snap-in package, its Snap-in version, and finally the Snap-in draft.

6\. After the Snap-in draft is created, install the Snap-in in the DevRev UI (`Settings` -> `Snap-ins` -> `Install snap-in`).

7\. Start the import (`Imports` -> `Start import` -> `<your Snap-in>`).

## Common Pitfalls

#### Q: `Conflict` error after the `Creating snap-in package...` output during `make deploy`.

A: Snap-in package with the same slug already exists. Override the `SNAP_IN_SLUG` variable by explicitly updating the variable in `scripts/vars.sh`.

#### Q: Snap-in version `build/deployment failed` after the `Waiting for snap-in version to be ready...` message

A: The snap-in version could not be built. Check the logs by running the DevRev CLI command `devrev snap_in_package logs`. For prettier UI, pipe the output to `jq`

### Q: `Token is expired` when deploying or cleaning up.

A: Authentication token to the `DEV_ORG` has expired. Run `make auth` to reconnect to the organization.
3 changes: 3 additions & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
1 change: 1 addition & 0 deletions code/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
1 change: 1 addition & 0 deletions code/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/**/*
15 changes: 15 additions & 0 deletions code/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxSingleQuote": false,
"arrowParens": "always",
"proseWrap": "never",
"htmlWhitespaceSensitivity": "strict",
"endOfLine": "lf",
"organizeImportsSkipDestructiveCodeActions": true
}
6 changes: 6 additions & 0 deletions code/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
4 changes: 4 additions & 0 deletions code/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
6 changes: 6 additions & 0 deletions code/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"execMap": {
"ts": "ts-node",
"watch": ["src"]
}
}
Loading

0 comments on commit 022dd05

Please sign in to comment.