From 2d56a9b0cac83cd25adaed9a4a2a50d1900d2548 Mon Sep 17 00:00:00 2001 From: Pranas Ziaukas Date: Wed, 12 Jun 2024 10:18:27 +0300 Subject: [PATCH] Add `dbt-project` type mapping This change introduces a new `dbt-project` repository type mapping, desgined specifically for dbt (data build tool) projects. All dbt projects require a standard `dbt_project.yml` configuration file at a minimum, which is used in this script. For reference, see https://docs.getdbt.com/docs/build/projects Change-type: minor Signed-off-by: Pranas Ziaukas --- .../dbt-project/dependencies.yml | 1 + .../dbt-project/versionist.conf.js | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 lib/repo-type-mappings/dbt-project/dependencies.yml create mode 100644 lib/repo-type-mappings/dbt-project/versionist.conf.js diff --git a/lib/repo-type-mappings/dbt-project/dependencies.yml b/lib/repo-type-mappings/dbt-project/dependencies.yml new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/lib/repo-type-mappings/dbt-project/dependencies.yml @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/lib/repo-type-mappings/dbt-project/versionist.conf.js b/lib/repo-type-mappings/dbt-project/versionist.conf.js new file mode 100644 index 0000000..6ed7e78 --- /dev/null +++ b/lib/repo-type-mappings/dbt-project/versionist.conf.js @@ -0,0 +1,49 @@ +/* + * Copyright 2024 Balena Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; +const exec = require('child_process').exec; +const path = require('path'); + +// Update version info in `dbt_project.yml` by +// replacing the first `version: "..."` occurrence in the file +const updateDbtProjectVersion = (cwd, version, callback) => { + const dbtProjectYml = path.join(cwd, 'dbt_project.yml'); + return exec(`sed -i '/^version:/ s/version: .*/version: "${version}"/' ${dbtProjectYml}`, + { + encoding: 'utf8', + }, callback); +}; + +module.exports = { + updateVersion: updateDbtProjectVersion, + + transformTemplateDataAsync: { + preset: 'nested-changelogs', + upstream: [ + {{#upstream}} + { + pattern: '{{{pattern}}}', + repo: '{{repo}}', + owner: '{{owner}}', + ref: '{{ref}}' + }, + {{/upstream}} + ] + }, + + template: 'default' +};