Skip to content

Commit

Permalink
RSDK-5362 generate protos from pinned versions (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpertsov authored Oct 18, 2023
1 parent 8d9bcb7 commit c2b11a5
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = {
* is causing eslint to choke. Investigate workspaces as a solution
*/
'examples',
// TODO(RSDK-5406): setup custom linting rules for standalone JS scripts.
'scripts',
],
parserOptions: {
project: ['./tsconfig.json', './tsconfig.node.json'],
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ update-buf: $(node_modules)

.PHONY: build-buf
build-buf: $(node_modules) clean-buf
$(buf) generate buf.build/googleapis/googleapis
# TODO(RSDK-5362): remove hardcoded pin and create a sane way to pin protos
# See this thread for more details: https://viaminc.slack.com/archives/C039G724TKP/p1697119526822429
$(buf) generate buf.build/viamrobotics/api:2109757288234ffc8248121f60437cdd --path common,component,robot,service,app
$(buf) generate buf.build/erdaniels/gostream
$(buf) generate buf.build/viamrobotics/goutils
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/googleapis/googleapis)
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/viamrobotics/api) --path common,component,robot,service,app
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/erdaniels/gostream)
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/viamrobotics/goutils)

# js targets

Expand Down
13 changes: 9 additions & 4 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: erdaniels
repository: gostream
commit: ae00de34a29e41ed96578beb4a84ae9e
digest: shake256:98cdbd37fd64db3f5b2e463863b1231af2653f155931de0655687758a0b312f8d60314060cd3caa8232f37e69fbb38de93057e6905aa29ee6aed4aca8b575421
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 62f35d8aed1149c291d606d958a7ce32
digest: shake256:c5f5c2401cf70b7c9719834954f31000a978397fdfebda861419bb4ab90fa8efae92710fddab0820533908a1e25ed692a8e119432b7b260c895087a4975b32f3
commit: 28151c0d0a1641bf938a7672c500e01d
digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de
- remote: buf.build
owner: viamrobotics
repository: api
commit: d7164997b0af45e1bceb246a9cd44020
digest: shake256:ed4a0f4e3e9a4df0a8d3413ab214190f187ee25b9954aa789143c35e47d74dbce20770b0d84a6a6eda60e8985f57f6f68218cf80cfab2e1ab3244a93d0d4d2d0
commit: 2109757288234ffc8248121f60437cdd
digest: shake256:18027527c16555ead747df632f73fecce3e2e489da437a35c175826d89472cce8323f32b9fa74261ca322e58e81aedcfce4d7cdc776b65eceb57dacacfe4822d
- remote: buf.build
owner: viamrobotics
repository: goutils
Expand Down
4 changes: 3 additions & 1 deletion buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ lint:
use:
- DEFAULT
deps:
- buf.build/viamrobotics/goutils
- buf.build/googleapis/googleapis
- buf.build/viamrobotics/api
- buf.build/erdaniels/gostream
- buf.build/viamrobotics/goutils
8 changes: 7 additions & 1 deletion doc/dependency_decisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
:versions: []
:when: 2023-05-01 18:19:05.224492180 Z
- - :license
- '@viamrobotics/typescript-config'
- "@viamrobotics/typescript-config"
- Apache 2.0
- :who:
:why: 'TODO(RSDK-583): why is license finder unable to detect this license automatically?'
Expand All @@ -89,3 +89,9 @@
:license_links: https://github.com/yinzara/protoc-gen-js/blob/master/LICENSE
:versions: []
:when: 2023-05-12 14:28:29.173104997 Z
- - :permit
- ISC
- :who:
:why:
:versions: []
:when: 2023-10-18 20:31:08.255446206 Z
34 changes: 26 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"typedoc": "^0.24.1",
"typescript": "^5.0.3",
"vite": "^4.2.1",
"vitest": "^0.28.4"
"vitest": "^0.28.4",
"yaml": "^2.3.3"
}
}
39 changes: 39 additions & 0 deletions scripts/get-buf-lock-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node

/**
* RSDK-5362: This script gets the pinned version of a buf proto from the
* buf.lock file. We need this to generate pinned versions of our protos.
*
* If we find a way to make `buf generate` build proto apis using the versions
* stored in buf.lock directly then we can retire this script.
*
* See this thread for more details:
* https://viaminc.slack.com/archives/C039G724TKP/p1697119526822429
*/

'use strict';

const fs = require('node:fs');
const YAML = require('yaml');

const buflockPath = './buf.lock';

const input = process.argv[2];
if (!input) {
throw new Error('Please specify a buf proto');
}

const [remote, owner, repository] = input.split('/');

const buflock = fs.readFileSync(buflockPath, 'utf8');
const parsed = YAML.parse(buflock);

const { commit } = parsed.deps.find(
(dep) =>
dep.remote === remote &&
dep.owner === owner &&
dep.repository === repository
);
const pinnedDep = `${remote}/${owner}/${repository}:${commit}`;

console.log(pinnedDep);
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"noEmit": true
},
"include": ["./vite.config.ts", "./*.cjs", "./.*.cjs"],
"exclude": ["**/src/**", "**/examples/**"]
"exclude": ["**/src/**", "**/examples/**", "**/scripts/**"]
}

0 comments on commit c2b11a5

Please sign in to comment.