From 86543f71ef2bb432b7fde4f6bea42dbde507c861 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Sun, 30 Jun 2024 16:10:21 -0600 Subject: [PATCH] ci: attempt to add vercel --- .github/workflows/vercel.yml | 79 +++++++++++++++++++++++++++++++++ api/package.json | 3 ++ api/src/api/routes/addresses.ts | 7 +-- api/util/openapi-generator.ts | 9 ++-- vercel.json | 5 +++ 5 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/vercel.yml create mode 100644 vercel.json diff --git a/.github/workflows/vercel.yml b/.github/workflows/vercel.yml new file mode 100644 index 0000000..52c63bb --- /dev/null +++ b/.github/workflows/vercel.yml @@ -0,0 +1,79 @@ +name: Vercel + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +on: + push: + branches: + - main + - beta + - develop + pull_request: + release: + types: + - published + workflow_dispatch: + +jobs: + vercel: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./api + + environment: + name: ${{ github.ref_name == 'main' && 'Production' || 'Preview' }} + url: ${{ github.ref_name == 'main' && 'https://runes-api.vercel.app/' || 'https://runes-api-pbcblockstack-blockstack.vercel.app/' }} + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version-file: 'api/.nvmrc' + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: | + ~/.npm + **/node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install deps + run: npm ci --audit=false + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel environment information + run: vercel pull --yes --environment=${{ github.ref_name == 'main' && 'production' || 'preview' }} --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build project artifacts + run: vercel build ${{ github.ref_name == 'main' && '--prod' || '' }} --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy project artifacts to Vercel + id: deploy + run: vercel ${{ github.ref_name == 'main' && '--prod' || 'deploy' }} --prebuilt --token=${{ secrets.VERCEL_TOKEN }} | awk '{print "deployment_url="$1}' >> $GITHUB_OUTPUT + + - name: Trigger docs.hiro.so deployment + if: github.ref_name == 'main' + run: curl -X POST ${{ secrets.VERCEL_DOCS_DEPLOY_HOOK_URL }} + + - name: Add comment with Vercel deployment URL + if: ${{ github.event_name == 'pull_request' }} + uses: thollander/actions-comment-pull-request@v2 + with: + comment_tag: vercel + message: | + Vercel deployment URL: ${{ steps.deploy.outputs.deployment_url }} :rocket: diff --git a/api/package.json b/api/package.json index 43ab750..a366058 100644 --- a/api/package.json +++ b/api/package.json @@ -8,7 +8,10 @@ "start": "node dist/src/index.js", "start-ts": "ts-node ./src/index.ts", "test": "jest --runInBand", + "generate:openapi": "rimraf ./tmp && node -r ts-node/register ./util/openapi-generator.ts", + "generate:docs": "redoc-cli build --output ./tmp/index.html ./tmp/openapi.yaml", "generate:git-info": "rimraf .git-info && node_modules/.bin/api-toolkit-git-info", + "generate:vercel": "npm run generate:git-info && npm run generate:openapi && npm run generate:docs", "lint:eslint": "eslint . --ext .ts,.tsx -f unix", "lint:prettier": "prettier --check src/**/*.ts tests/**/*.ts", "lint:unused-exports": "ts-unused-exports tsconfig.json --showLineNumber --excludePathsFromReport=util/*" diff --git a/api/src/api/routes/addresses.ts b/api/src/api/routes/addresses.ts index 448550b..29f6870 100644 --- a/api/src/api/routes/addresses.ts +++ b/api/src/api/routes/addresses.ts @@ -2,12 +2,7 @@ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'; import { Type } from '@sinclair/typebox'; import { FastifyPluginCallback } from 'fastify'; import { Server } from 'http'; -import { - AddressSchema, - LimitSchema, - OffsetSchema, - BalanceResponseSchema, -} from '../schemas'; +import { AddressSchema, LimitSchema, OffsetSchema, BalanceResponseSchema } from '../schemas'; import { parseBalanceResponse } from '../util/helpers'; import { Optional, PaginatedResponse } from '@hirosystems/api-toolkit'; import { handleCache } from '../util/cache'; diff --git a/api/util/openapi-generator.ts b/api/util/openapi-generator.ts index 34da066..f955716 100644 --- a/api/util/openapi-generator.ts +++ b/api/util/openapi-generator.ts @@ -15,12 +15,14 @@ export const ApiGenerator: FastifyPluginAsync< TypeBoxTypeProvider > = async (fastify, options) => { await fastify.register(FastifySwagger, OpenApiSchemaOptions); - await fastify.register(Api, { prefix: '/ordinals/v1' }); + await fastify.register(Api, { prefix: '/runes/v1' }); if (!existsSync('./tmp')) { mkdirSync('./tmp'); } - writeFileSync('./tmp/openapi.yaml', fastify.swagger({ yaml: true })); - writeFileSync('./tmp/openapi.json', JSON.stringify(fastify.swagger(), null, 2)); + fastify.addHook('onReady', () => { + writeFileSync('./tmp/openapi.yaml', fastify.swagger({ yaml: true })); + writeFileSync('./tmp/openapi.json', JSON.stringify(fastify.swagger(), null, 2)); + }); }; const fastify = Fastify({ @@ -29,5 +31,6 @@ const fastify = Fastify({ }).withTypeProvider(); void fastify.register(ApiGenerator).then(async () => { + await fastify.ready(); await fastify.close(); }); diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..45c873b --- /dev/null +++ b/vercel.json @@ -0,0 +1,5 @@ +{ + "git": { + "deploymentEnabled": false + } +}