Skip to content

Commit 5675a02

Browse files
authored
feat(tac-operation-lifecycle): Setup types package 🦄 (#1352)
* feat(tac-operation-lifecycle): Setup types package * fix package.json * add types package to service-template * add types package build check to CI workflow
1 parent 7a5010f commit 5675a02

File tree

12 files changed

+334
-6
lines changed

12 files changed

+334
-6
lines changed

‎.github/workflows/_linting.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,41 @@ jobs:
2727
- name: cargo clippy
2828
run: cargo clippy --all --all-targets --all-features -- -D warnings
2929
working-directory: ${{ inputs.working-directory }}
30+
31+
check-types-build:
32+
runs-on: ubuntu-latest
33+
name: Check build of types package
34+
steps:
35+
- name: Checkout sources
36+
uses: actions/checkout@v4
37+
38+
- name: Check if types directory exists
39+
id: check-directory
40+
run: |
41+
if [ -d "${{ inputs.working-directory }}/types" ]; then
42+
echo "exists=true" >> $GITHUB_OUTPUT
43+
else
44+
echo "exists=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Setup Node.js
48+
if: steps.check-directory.outputs.exists == 'true'
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: '20.x'
52+
53+
- name: Install Protoc
54+
if: steps.check-directory.outputs.exists == 'true'
55+
uses: arduino/setup-protoc@v3
56+
57+
- name: Install dependencies
58+
if: steps.check-directory.outputs.exists == 'true'
59+
run: |
60+
cd ${{ inputs.working-directory }}/types
61+
npm ci || npm install
62+
63+
- name: Build types package
64+
if: steps.check-directory.outputs.exists == 'true'
65+
run: |
66+
cd ${{ inputs.working-directory }}/types
67+
npm run build

‎.github/workflows/npm-publisher.yml‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ on:
99
required: true
1010
project_name:
1111
description: Project name
12-
type: choice
13-
options:
14-
- blockscout-ens
15-
- stats
16-
- visualizer
12+
type: string
1713
required: true
1814
workflow_call:
1915
inputs:
@@ -55,7 +51,7 @@ jobs:
5551
- name: Build the package
5652
run: |
5753
cd ./${{ inputs.project_name }}/types
58-
npm install
54+
npm ci || npm install
5955
npm run build
6056
6157
- name: Publish to NPM registry

‎.github/workflows/tac-operation-lifecycle.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ jobs:
8484
ARM_RUNNER_HOSTNAME: ${{ secrets.ARM_RUNNER_HOSTNAME }}
8585
ARM_RUNNER_KEY: ${{ secrets.ARM_RUNNER_KEY }}
8686

87+
publish_types_package:
88+
name: Publish types package
89+
uses: './.github/workflows/npm-publisher.yml'
90+
needs: docker
91+
if: needs.docker.outputs.tag-value != ''
92+
secrets: inherit
93+
with:
94+
version: ${{ needs.docker.outputs.tag-value }}
95+
project_name: tac-operation-lifecycle
96+
8797
push-swagger:
8898
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
8999
uses: ./.github/workflows/_push_swagger.yml

‎service-template/.github/workflows/{{project-name}}.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@ jobs:
8484
uses: ./.github/workflows/_docker-build-push.yml
8585
with:
8686
service-name: {{project-name}}
87+
88+
{%- if types %}
89+
publish_types_package:
90+
name: Publish types package
91+
uses: './.github/workflows/npm-publisher.yml'
92+
needs: docker
93+
if: needs.docker.outputs.tag-value != ''
94+
secrets: inherit
95+
with:
96+
{% raw %}
97+
version: ${{ needs.docker.outputs.tag-value }}
98+
{% endraw %}
99+
project_name: {{project-name}}
100+
{%- endif %}

‎service-template/cargo-generate.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ default = true
5050
# prompt = "Write example service name to generating proto examples"
5151
# default = "TestService"
5252

53+
[placeholders.types]
54+
type = "bool"
55+
prompt = "Generate typescript definitions for resources"
56+
default = true
57+
58+
[conditional.'!types']
59+
ignore = ["types"]
60+
5361
[hooks]
5462
pre = [
5563
"pre-script.rhai"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@blockscout/{{project-name}}-types",
3+
"version": "0.0.1",
4+
"description": "TypeScript definitions for {{project-name-title}} microservice",
5+
"main": "./dist/{{project-name}}-proto/proto/{{project-name}}.js",
6+
"types": "./dist/{{project-name}}-proto/proto/{{project-name}}.d.ts",
7+
"scripts": {
8+
"build": "npm run compile:proto && npm run compile:ts",
9+
"compile:proto": "mkdir -p ./dist && protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=snakeToCamel=false --ts_proto_opt=stringEnums=true --ts_proto_opt=onlyTypes=true --ts_proto_opt=emitImportedFiles=false --proto_path=../ --proto_path=../../proto/ --ts_proto_out=./dist ../{{project-name}}-proto/proto/v1/{{project-name}}.proto",
10+
"compile:ts": "tsc --declaration ./dist/{{project-name}}-proto/proto/v1/{{project-name}}.ts"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/blockscout/blockscout-rs.git",
15+
"directory": "{{project-name}}/types"
16+
},
17+
"license": "MIT",
18+
"bugs": {
19+
"url": "https://github.com/blockscout/blockscout-rs/issues"
20+
},
21+
"homepage": "https://github.com/blockscout/blockscout-rs#readme",
22+
"devDependencies": {
23+
"ts-proto": "1.176.2",
24+
"typescript": "5.4.5"
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

0 commit comments

Comments
 (0)