-
Notifications
You must be signed in to change notification settings - Fork 69
feat(github-actions): add daily Gemini model update workflow and local action #3706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josephperrott
merged 3 commits into
angular:main
from
josephperrott:update-models-action
Jun 1, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
9133e16
feat(github-actions): add daily Gemini model update workflow and loca…
josephperrott 2158982
fixup! feat(github-actions): add daily Gemini model update workflow a…
josephperrott 081fce4
fixup! feat(github-actions): add daily Gemini model update workflow a…
josephperrott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| load("@devinfra_npm//:defs.bzl", "npm_link_all_packages") | ||
| load("//tools:defaults.bzl", "esbuild_checked_in", "ts_project") | ||
|
|
||
| package(default_visibility = ["//.github/local-actions/update-models:__subpackages__"]) | ||
|
|
||
| npm_link_all_packages() | ||
|
|
||
| ts_project( | ||
| name = "lib", | ||
| srcs = glob(["lib/*.ts"]), | ||
| tsconfig = "//.github/local-actions:tsconfig", | ||
| deps = [ | ||
| "//.github/local-actions/update-models:node_modules/@actions/core", | ||
| "//.github/local-actions/update-models:node_modules/@types/node", | ||
| "//.github/local-actions/update-models:node_modules/fast-glob", | ||
| ], | ||
| ) | ||
|
|
||
| esbuild_checked_in( | ||
| name = "main", | ||
| srcs = [ | ||
| ":lib", | ||
| ], | ||
| entry_point = "lib/main.ts", | ||
| format = "esm", | ||
| platform = "node", | ||
| target = "node24", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| name: 'Update Gemini Models' | ||
| description: 'Check Gemini deprecations page and auto-update references to recommended replacements' | ||
| runs: | ||
| using: 'node24' | ||
| main: 'main.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import * as core from '@actions/core'; | ||
| import {readFile, writeFile} from 'node:fs/promises'; | ||
| import glob from 'fast-glob'; | ||
|
|
||
| /** Parse the deprecations page to extract model replacements. */ | ||
| function parseDeprecations(html: string): Map<string, string> { | ||
| const replacements = new Map<string, string>(); | ||
| const tbodyRegex = /<tbody[^>]*>([\s\S]*?)<\/tbody>/gi; | ||
| let tbodyMatch; | ||
| while ((tbodyMatch = tbodyRegex.exec(html)) !== null) { | ||
| const tbodyContent = tbodyMatch[1]; | ||
| const trRegex = /<tr[^>]*>([\s\S]*?)<\/tr>/gi; | ||
| let trMatch; | ||
| while ((trMatch = trRegex.exec(tbodyContent)) !== null) { | ||
| const trContent = trMatch[1]; | ||
| if (!trContent) continue; | ||
| if (trContent.includes('colspan')) continue; | ||
|
|
||
| const tdRegex = /<td[^>]*>([\s\S]*?)<\/td>/gi; | ||
| const tds: string[] = []; | ||
| let tdMatch; | ||
| while ((tdMatch = tdRegex.exec(trContent)) !== null) { | ||
| tds.push(tdMatch[1].trim()); | ||
| } | ||
|
|
||
| if (tds.length >= 4) { | ||
| const modelMatch = tds[0].match(/<code[^>]*>([^<]+)<\/code>/); | ||
| const model = modelMatch ? modelMatch[1].trim() : tds[0]; | ||
|
|
||
| const replacementMatch = tds[3].match(/<code[^>]*>([^<]+)<\/code>/); | ||
| const replacement = replacementMatch | ||
| ? replacementMatch[1].trim() | ||
| : tds[3].replace(/<[^>]*>/g, '').trim(); | ||
|
|
||
| if (model && replacement && replacement.includes('gemini')) { | ||
| replacements.set(model, replacement); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return replacements; | ||
| } | ||
|
|
||
| async function run() { | ||
| core.info('Fetching Gemini deprecations page...'); | ||
| let html = ''; | ||
| try { | ||
| const response = await fetch('https://ai.google.dev/gemini-api/docs/deprecations'); | ||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch: ${response.statusText}`); | ||
| } | ||
| html = await response.text(); | ||
| } catch (error) { | ||
| core.setFailed(`Error fetching deprecations page: ${error}`); | ||
| return; | ||
| } | ||
|
|
||
| const replacements = parseDeprecations(html); | ||
| if (replacements.size === 0) { | ||
| core.warning('No model replacements found on the deprecations page.'); | ||
| return; | ||
| } | ||
|
|
||
| core.info(`Found ${replacements.size} model replacement(s) on the deprecations page.`); | ||
| for (const [oldModel, newModel] of replacements.entries()) { | ||
| core.info(` - ${oldModel} -> ${newModel}`); | ||
| } | ||
|
|
||
| // Find all .ts, .yml, .yaml files in the repository, ignoring node_modules/dist/.git | ||
| const files = await glob(['**/*.{ts,yml,yaml}'], { | ||
| ignore: ['**/node_modules/**', '**/dist/**', '**/.git/**'], | ||
| dot: true, | ||
| }); | ||
|
josephperrott marked this conversation as resolved.
|
||
|
|
||
| let totalUpdated = 0; | ||
|
|
||
| for (const file of files) { | ||
| try { | ||
| const content = await readFile(file, 'utf-8'); | ||
| let updatedContent = content; | ||
| let fileChanged = false; | ||
|
|
||
| for (const [oldModel, newModel] of replacements.entries()) { | ||
| const escapedOldModel = oldModel.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| const regex = new RegExp(`(?<![a-zA-Z0-9.-])${escapedOldModel}(?![a-zA-Z0-9.-])`, 'g'); | ||
| const newContent = updatedContent.replace(regex, newModel); | ||
| if (newContent !== updatedContent) { | ||
| updatedContent = newContent; | ||
| fileChanged = true; | ||
| core.info(`Found reference to deprecated model "${oldModel}" in ${file}.`); | ||
| } | ||
| } | ||
|
|
||
| if (fileChanged) { | ||
| await writeFile(file, updatedContent, 'utf-8'); | ||
|
josephperrott marked this conversation as resolved.
|
||
| core.info(`Updated ${file}`); | ||
| totalUpdated++; | ||
| } | ||
| } catch (err) { | ||
| core.error(`Failed to read/write file ${file}: ${err}`); | ||
| } | ||
| } | ||
|
|
||
| if (totalUpdated === 0) { | ||
| core.info('No deprecated model references found in the codebase. All up to date! 🎉'); | ||
| } else { | ||
| core.info(`Successfully updated ${totalUpdated} file(s).`); | ||
| } | ||
| } | ||
|
|
||
| run().catch((err) => { | ||
| core.setFailed(`Unhandled execution error: ${err}`); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.