Skip to content

Commit

Permalink
Merge pull request #9 from oraichain/add/ci-cd
Browse files Browse the repository at this point in the history
Add/ci cd
  • Loading branch information
trungbach authored Aug 4, 2023
2 parents d6caf04 + 7daf548 commit 66bc1bb
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 59 deletions.
110 changes: 63 additions & 47 deletions .github/workflows/publish_package.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,80 @@

# This is a basic workflow to help you get started with Actions

name: publish_package

# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
publish_package:
runs-on: ubuntu-latest
# This workflow contains 2 jobs called "run-unit-test" "build"
run-unit-test:
uses: ./.github/workflows/reuseable-test.yaml

build:
needs:
- run-unit-test
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [">=16.0.0"]

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.10.0
with:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Configure CI Git User
run: |
git config --global user.name '@phutxorai'
git config --global user.email '[email protected]'
git remote set-url origin https://$GITHUB_ACTOR:[email protected]/oraichain/oraidex-sdk
env:
GITHUB_PAT: ${{ secrets.GIT_PAT }}
- name: Install Yarn
run: npm install -g yarn
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "**/node_modules"
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Authenticate with Registry
run: |
yarn logout
echo "registry=http://registry.npmjs.org/" >> .npmrc
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
npm whoami
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish package
run: lerna publish from-package --yes
env:
GH_TOKEN: ${{ secrets.GIT_PAT }}
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
./node_modules/
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Build
run: yarn build packages/contracts-sdk && yarn build packages/oraidex-sync && yarn --cwd packages/oraidex-server/ build
- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Publish
id: publish
continue-on-error: true
run: yarn deploy packages/oraidex-server
env:
CI: false
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install latest version
id: install
if: steps.publish.outcome != 'failure'
continue-on-error: true
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DOCKER_SWARM_MANAGER_ONE }}
username: root
key: ${{ secrets.DOCKER_SWARM_MANAGER_ONE_KEY }}
script: docker exec ${{ secrets.DOCKER_SWARM_MANAGER_ONE_NODE_16_ID}} sh -c 'yarn global add @oraichain/oraidex-server@latest --ignore-scripts'

- name: send result via discord
uses: appleboy/discord-action@master
with:
webhook_id: ${{ secrets.WEBHOOK_ID }}
webhook_token: ${{ secrets.WEBHOOK_TOKEN }}
username: "GitBot"
message: "Repo oraidex-sdk has just published oraidex-server. result: ${{ steps.publish.outcome }}. install result: ${{ steps.install.outcome }}"
31 changes: 31 additions & 0 deletions .github/workflows/reuseable-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Call run unit test

on:
workflow_call:

jobs:
triage:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [">=16.0.0"]

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

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
yarn
- name: Build dependency oraidex-sync
run: yarn build packages/contracts-sdk && yarn build packages/oraidex-sync

- name: Run unit test
run: |
yarn test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ typings/

.npmrc
build
*oraidex-sync-data*
*oraidex-sync-data*

dist
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "jest",
"docs": "typedoc --entryPointStrategy expand --name 'Oraidex SDK' --readme none --tsconfig packages/contracts-sdk/tsconfig.json packages/contracts-sdk/src",
"build": "tsc -p",
"deploy": "yarn publish --access public --patch",
"deploy": "yarn publish --access public",
"start:server": "yarn build packages/oraidex-sync/ && npx ts-node packages/oraidex-server/src/index.ts"
},
"workspaces": [
Expand Down
21 changes: 11 additions & 10 deletions packages/oraidex-server/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
"name": "@oraichain/oraidex-server",
"version": "1.0.0",
"main": "build/index.js",
"version": "1.0.4",
"main": "dist/index.js",
"bin": "dist/index.js",
"license": "MIT",
"files": [
"build/"
"dist/"
],
"scripts": {
"start": "npx ts-node src/index.ts"
"start": "npx ts-node src/index.ts",
"build": "ncc build src/index.ts --no-source-map-register -t -m"
},
"dependencies": {
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@cosmjs/cosmwasm-stargate": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@oraichain/common-contracts-sdk": "1.0.13",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@oraichain/oraidex-sync": "1.0.0",
"cors": "^2.8.5",
"express": "^4.18.2"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17"
"express": "^4.18.2",
"@vercel/ncc": "=0.34.0"
}
}
14 changes: 14 additions & 0 deletions packages/oraidex-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env -S node --no-warnings

import * as dotenv from "dotenv";
import express, { Request } from "express";
import {
Expand All @@ -19,6 +21,8 @@ import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { OraiswapRouterQueryClient } from "@oraichain/oraidex-contracts-sdk";
import { getDate24hBeforeNow, getSpecificDateBeforeNow, pairToString, parseSymbolsToTickerId } from "./helper";
import { GetCandlesQuery } from "@oraichain/oraidex-sync";
import fs from "fs";
import path from "path";

dotenv.config();

Expand All @@ -31,6 +35,16 @@ const port = parseInt(process.env.PORT) || 2024;
const hostname = process.env.HOSTNAME || "0.0.0.0";
const rpcUrl = process.env.RPC_URL || "https://rpc.orai.io";

app.get("/version", async (req, res) => {
try {
const packageContent = fs.readFileSync(path.join(__dirname, "../package.json"), { encoding: "utf-8" });
const packageJson = JSON.parse(packageContent);
res.status(200).send(packageJson.version);
} catch (error) {
res.status(500).send(error.message);
}
});

app.get("/pairs", async (req, res) => {
try {
const pairInfos = await duckDb.queryPairInfos();
Expand Down

0 comments on commit 66bc1bb

Please sign in to comment.