Skip to content

Commit 205b4c8

Browse files
rafaelcrASuciuX
andauthored
feat: migrate ordinals api to ordhook repo (#389)
* feat: add database migration cli commands * update cargo lock * chore: import first api files * test: cache first * test: cache * test: sats * test: inscription show * test: inscription transfers * test: inscriptions index * test: inscriptions complete * test: counts * test: status * test: block counts * test: brc20 activity * test: brc20 holders * ci: api tests * ci: update nvmrc path * ci: remove migration refs * ci: unused exports * ci: unused * ci: build publish * ci: monorepo * fix: timestamps * Update api/ordinals/docs/feature-guides/rate-limiting.md Co-authored-by: ASuciuX <151519329+ASuciuX@users.noreply.github.com> * Update api/ordinals/docs/feature-guides/rate-limiting.md Co-authored-by: ASuciuX <151519329+ASuciuX@users.noreply.github.com> * Update api/ordinals/docs/overview.md Co-authored-by: ASuciuX <151519329+ASuciuX@users.noreply.github.com> * Update api/ordinals/src/api/schemas.ts Co-authored-by: ASuciuX <151519329+ASuciuX@users.noreply.github.com> * Update api/ordinals/src/api/schemas.ts Co-authored-by: ASuciuX <151519329+ASuciuX@users.noreply.github.com> * fix: warnings --------- Co-authored-by: ASuciuX <151519329+ASuciuX@users.noreply.github.com>
1 parent fe842e2 commit 205b4c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+53691
-80
lines changed

.github/workflows/ci.yaml

+176-14
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,117 @@ concurrency:
1515
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
1616
cancel-in-progress: true
1717

18-
env:
19-
DOCKER_IMAGE: hirosystems/${{ github.event.repository.name }}
20-
2118
jobs:
19+
api-lint:
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
suite: [ordinals]
24+
runs-on: ubuntu-latest
25+
defaults:
26+
run:
27+
working-directory: ./api/${{ matrix.suite }}
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Use Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version-file: 'api/${{ matrix.suite }}/.nvmrc'
35+
36+
- name: Cache node modules
37+
uses: actions/cache@v4
38+
env:
39+
cache-name: cache-node-modules
40+
with:
41+
path: |
42+
~/.npm
43+
**/node_modules
44+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
45+
restore-keys: |
46+
${{ runner.os }}-build-${{ env.cache-name }}-
47+
${{ runner.os }}-build-
48+
${{ runner.os }}-
49+
50+
- name: Install deps
51+
run: npm ci --audit=false
52+
53+
- name: Lint ESLint
54+
run: npm run lint:eslint
55+
56+
- name: Lint Prettier
57+
run: npm run lint:prettier
58+
59+
- name: Lint Unused Exports
60+
run: npm run lint:unused-exports
61+
62+
api-test:
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
suite: [ordinals]
67+
defaults:
68+
run:
69+
working-directory: ./api/${{ matrix.suite }}
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
75+
76+
- name: Use Node.js
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version-file: 'api/${{ matrix.suite }}/.nvmrc'
80+
81+
- name: Cache node modules
82+
uses: actions/cache@v4
83+
env:
84+
cache-name: cache-node-modules
85+
with:
86+
path: |
87+
~/.npm
88+
**/node_modules
89+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
90+
restore-keys: |
91+
${{ runner.os }}-build-${{ env.cache-name }}-
92+
${{ runner.os }}-build-
93+
${{ runner.os }}-
94+
95+
- name: Install deps
96+
run: npm ci --audit=false
97+
98+
- name: Setup integration environment
99+
run: |
100+
sudo ufw disable
101+
npm run testenv:run -- -d
102+
npm run testenv:logs -- --no-color &> docker-compose-logs.txt &
103+
104+
- name: Run tests
105+
run: npm run test -- --coverage
106+
107+
- name: Upload coverage to Codecov
108+
uses: codecov/codecov-action@v4
109+
with:
110+
token: ${{ secrets.CODECOV_TOKEN }}
111+
112+
- name: Print integration environment logs
113+
run: cat docker-compose-logs.txt
114+
if: failure()
115+
116+
- name: Teardown integration environment
117+
run: npm run testenv:stop
118+
if: always()
119+
22120
test:
23121
strategy:
24122
fail-fast: false
25123
matrix:
26-
suite: [cli, core]
124+
suite: [ordhook-cli, ordhook-core]
27125
runs-on: ubuntu-latest
28126
defaults:
29127
run:
30-
working-directory: ./components/ordhook-${{ matrix.suite }}
128+
working-directory: ./components/${{ matrix.suite }}
31129
steps:
32130
- uses: actions/checkout@v4
33131
with:
@@ -73,11 +171,11 @@ jobs:
73171
run: docker compose -f ../../dockerfiles/docker-compose.dev.postgres.yml down -v -t 0
74172
if: always()
75173

76-
build-publish:
174+
semantic-release:
77175
runs-on: ubuntu-latest
78-
needs: test
176+
needs: [api-lint, api-test, test]
79177
outputs:
80-
docker_image_digest: ${{ steps.docker_push.outputs.digest }}
178+
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
81179
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
82180
steps:
83181
- uses: actions/checkout@v4
@@ -92,19 +190,31 @@ jobs:
92190
env:
93191
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94192
SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }}
193+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_CRATES_IO_API_KEY }}
95194
with:
96195
semantic_version: 19
97196
extra_plugins: |
98197
@semantic-release/changelog@6.0.3
99198
@semantic-release/git@10.0.1
199+
@semantic-release/exec@6.0.3
100200
conventional-changelog-conventionalcommits@6.1.0
101201
202+
build-publish:
203+
runs-on: ubuntu-latest
204+
needs: semantic-release
205+
outputs:
206+
docker_image_digest: ${{ steps.docker_push.outputs.digest }}
207+
steps:
208+
- uses: actions/checkout@v4
209+
with:
210+
persist-credentials: false
211+
102212
- name: Checkout tag
103-
if: steps.semantic.outputs.new_release_version != ''
213+
if: needs.semantic-release.outputs.new_release_version != ''
104214
uses: actions/checkout@v4
105215
with:
106216
persist-credentials: false
107-
ref: v${{ steps.semantic.outputs.new_release_version }}
217+
ref: v${{ needs.semantic-release.outputs.new_release_version }}
108218

109219
- name: Set up Docker Buildx
110220
uses: docker/setup-buildx-action@v3
@@ -114,12 +224,12 @@ jobs:
114224
uses: docker/metadata-action@v5
115225
with:
116226
images: |
117-
${{ env.DOCKER_IMAGE }}
227+
hirosystems/ordhook
118228
tags: |
119229
type=ref,event=branch
120230
type=ref,event=pr
121-
type=semver,pattern={{version}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }}
122-
type=semver,pattern={{major}}.{{minor}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }}
231+
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.new_release_version }},enable=${{ needs.semantic-release.outputs.new_release_version != '' }}
232+
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.new_release_version }},enable=${{ needs.semantic-release.outputs.new_release_version != '' }}
123233
type=raw,value=latest,enable={{is_default_branch}}
124234
125235
- name: Log in to DockerHub
@@ -141,7 +251,59 @@ jobs:
141251
cache-from: type=gha
142252
cache-to: type=gha,mode=max
143253
# Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks)
144-
push: ${{ (github.ref != 'refs/heads/main' || steps.semantic.outputs.new_release_version != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
254+
push: ${{ (github.ref != 'refs/heads/main' || needs.semantic-release.outputs.new_release_version != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
255+
256+
api-build-publish:
257+
strategy:
258+
fail-fast: false
259+
matrix:
260+
suite: [ordinals]
261+
runs-on: ubuntu-latest
262+
needs: semantic-release
263+
steps:
264+
- uses: actions/checkout@v4
265+
with:
266+
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
267+
fetch-depth: 0
268+
persist-credentials: false
269+
270+
- name: Checkout tag
271+
if: needs.semantic-release.outputs.new_release_version != ''
272+
uses: actions/checkout@v4
273+
with:
274+
persist-credentials: false
275+
ref: v${{ needs.semantic-release.outputs.new_release_version }}
276+
277+
- name: Set up Docker Buildx
278+
uses: docker/setup-buildx-action@v3
279+
280+
- name: Docker Meta
281+
id: meta
282+
uses: docker/metadata-action@v5
283+
with:
284+
images: |
285+
hirosystems/${{ matrix.suite }}
286+
tags: |
287+
type=ref,event=branch
288+
type=ref,event=pr
289+
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.new_release_version }},enable=${{ needs.semantic-release.outputs.new_release_version != '' }}
290+
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.new_release_version }},enable=${{ needs.semantic-release.outputs.new_release_version != '' }}
291+
292+
- name: Login to DockerHub
293+
uses: docker/login-action@v3
294+
with:
295+
username: ${{ secrets.DOCKERHUB_USERNAME }}
296+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
297+
298+
- name: Build/Tag/Push Image
299+
uses: docker/build-push-action@v5
300+
with:
301+
context: ./api/${{ matrix.suite }}
302+
file: ./api/${{ matrix.suite }}/Dockerfile
303+
tags: ${{ steps.meta.outputs.tags }}
304+
labels: ${{ steps.meta.outputs.labels }}
305+
# Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks)
306+
push: ${{ (github.ref != 'refs/heads/master' || needs.semantic-release.outputs.new_release_version != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
145307

146308
deploy-dev:
147309
runs-on: ubuntu-latest

.vscode/launch.json

+66-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,71 @@
6060
},
6161
"args": [],
6262
"cwd": "${workspaceFolder}"
63-
}
63+
},
64+
{
65+
"type": "node",
66+
"request": "launch",
67+
"name": "test: ordinals-api",
68+
"program": "${workspaceFolder}/api/ordinals/node_modules/jest/bin/jest",
69+
"cwd": "${workspaceFolder}/api/ordinals/",
70+
"args": [
71+
"--testTimeout=3600000",
72+
"--runInBand",
73+
"--no-cache"
74+
],
75+
"outputCapture": "std",
76+
"console": "integratedTerminal",
77+
"preLaunchTask": "npm: testenv:run",
78+
"postDebugTask": "npm: testenv:stop",
79+
"env": {
80+
"PGHOST": "localhost",
81+
"PGUSER": "postgres",
82+
"PGPASSWORD": "postgres",
83+
},
84+
},
85+
{
86+
"type": "node",
87+
"request": "launch",
88+
"name": "test: ordinals-api (api)",
89+
"program": "${workspaceFolder}/api/ordinals/node_modules/jest/bin/jest",
90+
"cwd": "${workspaceFolder}/api/ordinals/",
91+
"args": [
92+
"--testTimeout=3600000",
93+
"--runInBand",
94+
"--no-cache",
95+
"${workspaceFolder}/api/ordinals/tests/api/"
96+
],
97+
"outputCapture": "std",
98+
"console": "integratedTerminal",
99+
"preLaunchTask": "npm: testenv:run",
100+
"postDebugTask": "npm: testenv:stop",
101+
"env": {
102+
"PGHOST": "localhost",
103+
"PGUSER": "postgres",
104+
"PGPASSWORD": "postgres",
105+
},
106+
},
107+
{
108+
"type": "node",
109+
"request": "launch",
110+
"name": "test: ordinals-api (brc-20)",
111+
"program": "${workspaceFolder}/api/ordinals/node_modules/jest/bin/jest",
112+
"cwd": "${workspaceFolder}/api/ordinals/",
113+
"args": [
114+
"--testTimeout=3600000",
115+
"--runInBand",
116+
"--no-cache",
117+
"${workspaceFolder}/api/ordinals/tests/brc-20/"
118+
],
119+
"outputCapture": "std",
120+
"console": "integratedTerminal",
121+
"preLaunchTask": "npm: testenv:run",
122+
"postDebugTask": "npm: testenv:stop",
123+
"env": {
124+
"PGHOST": "localhost",
125+
"PGUSER": "postgres",
126+
"PGPASSWORD": "postgres",
127+
},
128+
},
64129
]
65130
}

.vscode/tasks.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "npm: testenv:run",
6+
"type": "shell",
7+
"command": "npm run testenv:run -- -d",
8+
"isBackground": true,
9+
"options": {
10+
"cwd": "${workspaceFolder}/api/ordinals/",
11+
},
12+
"problemMatcher": {
13+
"pattern": {
14+
"regexp": ".",
15+
"file": 1,
16+
"location": 2,
17+
"message": 3
18+
},
19+
"background": {
20+
"activeOnStart": true,
21+
"beginsPattern": ".",
22+
"endsPattern": "."
23+
}
24+
}
25+
},
26+
{
27+
"label": "npm: testenv:stop",
28+
"type": "shell",
29+
"command": "npm run testenv:stop",
30+
"options": {
31+
"cwd": "${workspaceFolder}/api/ordinals/",
32+
},
33+
"presentation": {
34+
"echo": true,
35+
"reveal": "silent",
36+
"focus": false,
37+
"panel": "shared",
38+
"showReuseMessage": true,
39+
"clear": false
40+
}
41+
}
42+
]
43+
}

api/ordinals/.commitlintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@commitlint/config-conventional"]
3+
}

api/ordinals/.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/node_modules
2+
**/tmp

api/ordinals/.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
[{*.ts,*.json}]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 2

api/ordinals/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# See src/env.ts for environment variable documentation.

api/ordinals/.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.eslintrc.js

0 commit comments

Comments
 (0)