From bf5e15b71caa682a22d3b4a5ec03aa44bb9d877c Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Mon, 9 Sep 2024 17:17:34 -0700 Subject: [PATCH] Dependabot: Add missing /src/go directories This also updates the golang linting script to check for directories in `/src/go/` that isn't listed in the dependabot configs (but does not attempt to apply any fixes). Signed-off-by: Mark Yen --- .github/dependabot.yml | 24 ++++++++++++++++++++++++ scripts/lint-go.ts | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d2e3932657e..321e07d33d3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -82,6 +82,14 @@ updates: labels: ["component/dependencies"] reviewers: [ "mook-as" ] + - package-ecosystem: "gomod" + directory: "/src/go/guestagent" + schedule: + interval: "daily" + open-pull-requests-limit: 1 + labels: ["component/dependencies"] + reviewers: [ "Nino-K" ] + - package-ecosystem: "gomod" directory: "/src/go/mock-wsl" schedule: @@ -98,6 +106,22 @@ updates: labels: ["component/dependencies"] reviewers: [ "Nino-K" ] + - package-ecosystem: "gomod" + directory: "/src/go/nerdctl-stub/generate" + schedule: + interval: "daily" + open-pull-requests-limit: 1 + labels: ["component/dependencies"] + reviewers: [ "Nino-K" ] + + - package-ecosystem: "gomod" + directory: "/src/go/networking" + schedule: + interval: "daily" + open-pull-requests-limit: 1 + labels: ["component/dependencies"] + reviewers: [ "Nino-K" ] + - package-ecosystem: "gomod" directory: "/src/go/rdctl" schedule: diff --git a/scripts/lint-go.ts b/scripts/lint-go.ts index 2d01565e342..a19eba91e28 100644 --- a/scripts/lint-go.ts +++ b/scripts/lint-go.ts @@ -3,8 +3,11 @@ * * If any argument is `--fix`, then changes are automatically applied. */ +import fs from 'fs'; import path from 'path'; +import yaml from 'yaml'; + import { readDependencyVersions } from './lib/dependencies'; import { spawnFile } from '@pkg/utils/childProcess'; @@ -109,7 +112,37 @@ async function goLangCILint(fix: boolean): Promise { return success; } -Promise.all([format(fix), syncModules(fix), goLangCILint(fix)]).then((successes) => { +type dependabotConfig = { + version: 2, + updates: { + 'package-ecosystem': string; + directory: string; + schedule: { interval: 'daily' }; + 'open-pull-requests-limit': number; + labels: string[]; + ignore?: {'dependency-name': string; 'update-types'?: string[]; version?: string[] }[]; + reviewers?: string[]; + }[]; +}; + +async function checkDependabot(fix: boolean): Promise { + const configs: dependabotConfig = yaml.parse(await fs.promises.readFile('.github/dependabot.yml', 'utf8')); + const modules = (await getModules()).map(module => `/${ module }`); + const dependabotDirs = configs.updates.filter(x => x['package-ecosystem'] === 'gomod').map(x => x.directory); + const missing = modules.filter(x => !dependabotDirs.includes(x)); + + if (missing.length > 0) { + const message = ['\x1B[0;1;31m Go modules not listed in dependabot:\x1B[0m'].concat(missing); + + console.error(message.join('\n ')); + + return false; + } + + return true; +} + +Promise.all([format, syncModules, goLangCILint, checkDependabot].map(fn => fn(fix))).then((successes) => { if (!successes.every(x => x)) { process.exit(1); }