From 4b8b4c8fb38ca157546d64b54e1408d7a85e76c6 Mon Sep 17 00:00:00 2001 From: Thomas Bonnin <233326+TBonnin@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:38:59 +0100 Subject: [PATCH] add github action to publish packages and backend apps --- .github/workflows/deploy-runners.yaml | 29 --------- .github/workflows/deploy.yaml | 79 +++++++++++++++++++++++++ .github/workflows/push-container.yaml | 34 +++++++++++ .github/workflows/release.yaml | 73 +++++++++++++++++++++++ VERSION | 1 + package-lock.json | 23 ++++++- packages/cli/docker/docker-compose.yaml | 2 +- packages/cli/package.json | 18 +++--- packages/cli/tsconfig.json | 2 +- packages/frontend/package.json | 6 +- packages/jobs/package.json | 4 +- packages/node-client/package.json | 7 ++- packages/node-client/tsconfig.json | 2 +- packages/runner/package.json | 4 +- packages/server/package.json | 4 +- packages/shared/package.json | 5 +- scripts/publish.sh | 47 +++++++++++++++ 17 files changed, 285 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/deploy-runners.yaml create mode 100644 .github/workflows/deploy.yaml create mode 100644 .github/workflows/push-container.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 VERSION create mode 100755 scripts/publish.sh diff --git a/.github/workflows/deploy-runners.yaml b/.github/workflows/deploy-runners.yaml deleted file mode 100644 index 4fa016d4744..00000000000 --- a/.github/workflows/deploy-runners.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Nango Deploy Runners - -on: - workflow_dispatch: - inputs: - environment: - type: choice - description: "Environment to deploy to, defaults to staging" - required: true - default: "staging" - options: - - staging - - production - -jobs: - deploy_runners: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Call deploy runners script - env: - API_KEY: ${{ secrets.RENDER_API_KEY }} - ENVIRONMENT: ${{ github.event.inputs.environment }} - RUNNER_OWNER_ID: ${{ secrets.RENDER_RUNNER_OWNER_ID }} - shell: bash - run: | - bash ./scripts/deploy/runners.bash - diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 00000000000..ecba322f019 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,79 @@ +name: Nango Deploy + +on: + workflow_dispatch: + inputs: + stage: + type: choice + description: "stage to deploy to, defaults to staging" + required: true + default: "staging" + options: + - staging + - production + service: + type: choice + description: "Service to deploy, defaults to server" + required: true + default: "server" + options: + - server + - jobs + - runner + +jobs: + deploy_server: + if: inputs.service == 'server' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Push tag + run: | + docker buildx imagetools create nangohq/nango-server:${{ inputs.stage }}-${{ github.sha }} --tag nangohq/nango-server:${{ inputs.stage }} + - name: Deploy server + run: | + SERVICE_ID=${{ fromJson('{ production: "srv-cfifsvha6gdq1k7u46a0", staging: "srv-ci1oqkm4dad20aa0cd9g" }')[inputs.stage] }} + curl --request POST "https://api.render.com/v1/services/$SERVICE_ID/deploys" --header "authorization: Bearer ${{ secrets.RENDER_API_KEY }}" + deploy_jobs: + if: inputs.service == 'jobs' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Push tag + run: | + docker buildx imagetools create nangohq/nango-jobs:${{ github.sha }} --tag nangohq/nango-jobs:${{ inputs.stage }} + - name: Deploy jobs + run: | + SERVICE_ID=${{ fromJson('{ production: "srv-clvvtdug1b2c73cklps0", staging: "srv-clthttda73kc73ejflg0" }')[inputs.stage] }} + curl --request POST "https://api.render.com/v1/services/$SERVICE_ID/deploys" --header "authorization: Bearer ${{ secrets.RENDER_API_KEY }}" + deploy_runners: + if: inputs.service == 'runner' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Push tag + run: | + docker buildx imagetools create nangohq/nango-runner:${{ github.sha }} --tag nangohq/nango-runner:${{ inputs.stage }} + - name: Deploy all runners + env: + API_KEY: ${{ secrets.RENDER_API_KEY }} + ENVIRONMENT: ${{ inputs.stage }} + RUNNER_OWNER_ID: ${{ secrets.RENDER_RUNNER_OWNER_ID }} + run: | + bash ./scripts/deploy/runners.bash + diff --git a/.github/workflows/push-container.yaml b/.github/workflows/push-container.yaml new file mode 100644 index 00000000000..0dd7ef0c81e --- /dev/null +++ b/.github/workflows/push-container.yaml @@ -0,0 +1,34 @@ +name: Push container + +on: + workflow_call: + inputs: + package: + required: true + type: string + run-cmd: + required: true + type: string + tags: + required: true + type: string + +jobs: + push-container: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - uses: actions/setup-node@v3 + with: + node-version: '18.x' + - uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push container + run: | + npm run i + npm run ${{ inputs.run-cmd }} + docker buildx build -f packages/${{ inputs.package }}/Dockerfile --platform linux/amd64 ${{ inputs.tags }} . --no-cache --output type=registry + diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000000..fc2a93b32cc --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,73 @@ +name: Nango Release +on: [push, pull_request] +concurrency: + group: pulls/${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +jobs: + npm-publish: + # if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_PAT }} + - uses: actions/setup-node@v3 + with: + node-version: '18.x' + registry-url: 'https://registry.npmjs.org' + - name: Publish npm packages + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + shell: bash + run: | + bash ./scripts/publish.sh + echo ">>>>" >> README.md + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Update npm packages version + # file_pattern: 'package*.json' + nango-jobs: + uses: ./.github/workflows/push-container.yaml + secrets: inherit + with: + package: jobs + run-cmd: ts-build + tags: -t nangohq/nango-jobs:${{ github.sha }} + nango-runner: + uses: ./.github/workflows/push-container.yaml + secrets: inherit + with: + package: runner + run-cmd: ts-build + tags: -t nangohq/nango-runner:${{ github.sha }} + nango-server-staging: + uses: ./.github/workflows/push-container.yaml + secrets: inherit + with: + package: server + run-cmd: build:staging + tags: -t nangohq/nango-server:staging-${{ github.sha }} + nango-server-prod: + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/push-container.yaml + secrets: inherit + with: + package: server + run-cmd: build:prod + tags: -t nangohq/nango-server:production-${{ github.sha }} + nango-server-self-hosted: + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/push-container.yaml + secrets: inherit + with: + package: server + run-cmd: build:hosted + tags: -t nangohq/nango-server:hosted -t nangohq/nango-server:hosted-${{ github.sha }} + nango-server-enterprise: + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/push-container.yaml + secrets: inherit + with: + package: server + run-cmd: build:enterprise + tags: -t nangohq/nango-server:enterprise -t nangohq/nango-server:enterprise-${{ github.sha }} diff --git a/VERSION b/VERSION new file mode 100644 index 00000000000..6746f23ce65 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.36.74 diff --git a/package-lock.json b/package-lock.json index 564dbcb22ae..268976ed2e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2780,6 +2780,7 @@ }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", + "dev": true, "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "0.3.9" @@ -2880,11 +2881,13 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], + "peer": true, "engines": { "node": ">=12" } @@ -5034,18 +5037,22 @@ }, "node_modules/@tsconfig/node10": { "version": "1.0.9", + "dev": true, "license": "MIT" }, "node_modules/@tsconfig/node12": { "version": "1.0.11", + "dev": true, "license": "MIT" }, "node_modules/@tsconfig/node14": { "version": "1.0.3", + "dev": true, "license": "MIT" }, "node_modules/@tsconfig/node16": { "version": "1.0.3", + "dev": true, "license": "MIT" }, "node_modules/@tsconfig/node18-strictest-esm": { @@ -5991,6 +5998,7 @@ }, "node_modules/acorn-walk": { "version": "8.2.0", + "dev": true, "license": "MIT", "engines": { "node": ">=0.4.0" @@ -6387,6 +6395,7 @@ }, "node_modules/arg": { "version": "4.1.3", + "dev": true, "license": "MIT" }, "node_modules/argparse": { @@ -7421,6 +7430,7 @@ }, "node_modules/create-require": { "version": "1.1.1", + "dev": true, "license": "MIT" }, "node_modules/cross-fetch": { @@ -7588,6 +7598,7 @@ }, "node_modules/diff": { "version": "4.0.2", + "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" @@ -7817,6 +7828,7 @@ }, "node_modules/esbuild": { "version": "0.17.19", + "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -10020,6 +10032,7 @@ }, "node_modules/make-error": { "version": "1.3.6", + "dev": true, "license": "ISC" }, "node_modules/marked": { @@ -12951,6 +12964,7 @@ }, "node_modules/ts-node": { "version": "10.9.1", + "dev": true, "license": "MIT", "dependencies": { "@cspotcode/source-map-support": "^0.8.0", @@ -13444,6 +13458,7 @@ }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", + "dev": true, "license": "MIT" }, "node_modules/validate-npm-package-name": { @@ -14093,6 +14108,7 @@ }, "node_modules/yn": { "version": "3.1.1", + "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -14139,7 +14155,6 @@ "copyfiles": "^2.4.1", "dotenv": "^16.0.3", "ejs": "^3.1.9", - "esbuild": "^0.17.19", "figlet": "^1.6.0", "js-yaml": "^4.1.0", "memfs": "^3.5.1", @@ -14147,8 +14162,6 @@ "ora": "^6.3.1", "promptly": "^3.2.0", "semver": "^7.5.2", - "ts-node": "^10.9.1", - "typescript": "^5.0.4", "vm": "^0.1.0" }, "bin": { @@ -14168,6 +14181,9 @@ "@types/npm-package-arg": "^6.1.1", "@types/promptly": "^3.0.2", "babel-loader": "^9.1.2", + "esbuild": "^0.17.19", + "ts-node": "^10.9.1", + "typescript": "^5.0.4", "webpack": "^5.85.1", "webpack-cli": "^5.1.3", "webpack-node-externals": "^3.0.0" @@ -14215,6 +14231,7 @@ }, "packages/cli/node_modules/typescript": { "version": "5.0.4", + "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", diff --git a/packages/cli/docker/docker-compose.yaml b/packages/cli/docker/docker-compose.yaml index 4ff86027ae4..8473c25e544 100644 --- a/packages/cli/docker/docker-compose.yaml +++ b/packages/cli/docker/docker-compose.yaml @@ -15,7 +15,7 @@ services: - nango nango-server: - image: nangohq/nango-server:0.36.77 + image: nangohq/nango-server container_name: nango-server environment: - TEMPORAL_ADDRESS=temporal:7233 diff --git a/packages/cli/package.json b/packages/cli/package.json index a2bd0d7b457..d1927d75373 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -4,21 +4,23 @@ "description": "Nango's CLI tool.", "type": "module", "main": "dist/index.js", - "bin": "./dist/index.js", + "bin": { + "nango": "dist/index.js" + }, "types": "dist/nango-sync.d.ts", "keywords": [], "author": "bastien@nango.dev", "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/cli" }, "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY", "scripts": { - "build": "tsc", + "build": "tsc && npm run copyfiles", "copyfiles": "copyfiles -u 1 lib/templates/* dist", - "postbuild": "npm run copyfiles", - "dev": "npm run copyfiles && tsc -w" + "dev": "npm run copyfiles && tsc -w", + "prepublishOnly": "npm install && npm run build" }, "dependencies": { "@babel/traverse": "^7.22.5", @@ -34,7 +36,6 @@ "copyfiles": "^2.4.1", "dotenv": "^16.0.3", "ejs": "^3.1.9", - "esbuild": "^0.17.19", "figlet": "^1.6.0", "js-yaml": "^4.1.0", "memfs": "^3.5.1", @@ -42,8 +43,6 @@ "ora": "^6.3.1", "promptly": "^3.2.0", "semver": "^7.5.2", - "ts-node": "^10.9.1", - "typescript": "^5.0.4", "vm": "^0.1.0" }, "devDependencies": { @@ -60,6 +59,9 @@ "@types/npm-package-arg": "^6.1.1", "@types/promptly": "^3.0.2", "babel-loader": "^9.1.2", + "esbuild": "^0.17.19", + "ts-node": "^10.9.1", + "typescript": "^5.0.4", "webpack": "^5.85.1", "webpack-cli": "^5.1.3", "webpack-node-externals": "^3.0.0" diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index fceecc91c2c..dd2652e614c 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -6,4 +6,4 @@ }, "references": [{ "path": "../shared" }], "include": ["lib/**/*"] -} +} \ No newline at end of file diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 8d84a80e66f..9b2ad500fee 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -9,10 +9,14 @@ "author": "bastien@nango.dev", "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/frontend" }, "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY", + "scripts": { + "build": "tsc", + "prepublishOnly": "npm install && npm run build" + }, "dependencies": {}, "files": [ "dist/**/*.js", diff --git a/packages/jobs/package.json b/packages/jobs/package.json index 04eee212e73..b8741372365 100644 --- a/packages/jobs/package.json +++ b/packages/jobs/package.json @@ -11,7 +11,7 @@ "keywords": [], "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/jobs" }, "dependencies": { @@ -49,4 +49,4 @@ "nodemon": "^3.0.1", "typescript": "^5.3.2" } -} \ No newline at end of file +} diff --git a/packages/node-client/package.json b/packages/node-client/package.json index 95cc6e0f938..08fb6ab4d39 100644 --- a/packages/node-client/package.json +++ b/packages/node-client/package.json @@ -6,7 +6,8 @@ "main": "dist/index.js", "module": "./dist/index.js", "scripts": { - "build": "tsup lib/index.ts --format cjs" + "build": "tsup lib/index.ts --format cjs", + "prepublishOnly": "npm install && npm run build && tsc" }, "exports": { ".": { @@ -19,7 +20,7 @@ "keywords": [], "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/node-client" }, "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY", @@ -37,4 +38,4 @@ "devDependencies": { "tsup": "^7.2.0" } -} +} \ No newline at end of file diff --git a/packages/node-client/tsconfig.json b/packages/node-client/tsconfig.json index 40518d51fa2..6e986e8dde7 100644 --- a/packages/node-client/tsconfig.json +++ b/packages/node-client/tsconfig.json @@ -5,4 +5,4 @@ "outDir": "dist" }, "include": ["lib/**/*"] -} +} \ No newline at end of file diff --git a/packages/runner/package.json b/packages/runner/package.json index 4e57d557463..0057b59077c 100644 --- a/packages/runner/package.json +++ b/packages/runner/package.json @@ -13,7 +13,7 @@ "keywords": [], "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/runner" }, "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY", @@ -32,4 +32,4 @@ "@types/node": "^18.7.6", "typescript": "^5.3.2" } -} \ No newline at end of file +} diff --git a/packages/server/package.json b/packages/server/package.json index 845d61c225c..881c3e4bcb8 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -12,7 +12,7 @@ "keywords": [], "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/server" }, "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY", @@ -74,4 +74,4 @@ "nodemon": "^3.0.1", "typescript": "^4.7.4" } -} \ No newline at end of file +} diff --git a/packages/shared/package.json b/packages/shared/package.json index 7418812851a..5886a0506f6 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -6,12 +6,13 @@ "main": "dist/lib/index.js", "typings": "dist/lib/index.d.ts", "scripts": { - "build": "rimraf dist && tsc" + "build": "rimraf dist && tsc", + "prepublishOnly": "npm install && npm run build" }, "keywords": [], "repository": { "type": "git", - "url": "https://github.com/NangoHQ/nango", + "url": "git+https://github.com/NangoHQ/nango.git", "directory": "packages/shared" }, "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY", diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 00000000000..452b315963e --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# exit when any command fails +set -e + +# function to bump and publish a package +# $1: package name +# $2: package version +function bump_and_npm_publish { + if npm view "$1@$2" > /dev/null 2>&1; then + echo "Package '$1@$2' already exists" + else + echo "Publishing '$1@$2'" + npm version "$2" -w "$1" + npm publish --access public -w "$1" + fi +} + +GIT_ROOT_DIR=$(git rev-parse --show-toplevel) + +# get version from VERSION file +VERSION=$(cat "$GIT_ROOT_DIR/VERSION") + +# ensure version is of format x.y.z +if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "VERSION '$VERSION' is not of format x.y.z" + exit 1 +fi + +npm install + +# Node client +bump_and_npm_publish "@nangohq/node" "$VERSION" +npm update @nangohq/node -w @nangohq/shared + +# Shared +node scripts/flows.js +bump_and_npm_publish "@nangohq/shared" "$VERSION" +npm update @nangohq/shared -w nango -w @nangohq/nango-server -w @nangohq/nango-jobs @nangohq/nango-runner + +# CLI +# exporting the NangoSync type +cp "$GIT_ROOT_DIR/packages/shared/dist/lib/sdk/sync.d.ts" "./packages/cli/dist/nango-sync.d.ts" && chmod +x "$GIT_ROOT_DIR/packages/cli/dist/index.js" +bump_and_npm_publish "nango" "$VERSION" + +# Frontend +bump_and_npm_publish "@nangohq/frontend" "$VERSION"