From 2757c3c978e92d00cc1a3b365643c5886d885f93 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 22 Jan 2024 10:19:05 -0400 Subject: [PATCH 01/39] ci: add workflow to update discovery types --- .github/workflows/discovery.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/discovery.yaml diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml new file mode 100644 index 00000000..8980ea7d --- /dev/null +++ b/.github/workflows/discovery.yaml @@ -0,0 +1,25 @@ +on: + schedule: + - cron: '0 12 * * TUE' +name: Update Discovery Generated Types +jobs: + sync: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 14 + # Install all deps, including dev dependencies. + - run: npm install + # Generate types + - run: npm run types + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + add-paths: src/types.d.ts + commit-message: "chore: update types from Discovery" + title: "chore: update types from Discovery" + body: | + Automated pull-request to keep BigQuery Discovery types up-to-date. + From 3f39f50de77357bddf4dac13f84bd8df09f21a19 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 22 Jan 2024 10:32:42 -0400 Subject: [PATCH 02/39] ci: make discovery workflow temp trigger on PR --- .github/workflows/discovery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 8980ea7d..d6c5a31f 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,6 +1,7 @@ on: schedule: - cron: '0 12 * * TUE' + pull_request: name: Update Discovery Generated Types jobs: sync: From 02a1154ebfe4ec7002821f73fee60d4a27ff2998 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 22 Jan 2024 10:35:26 -0400 Subject: [PATCH 03/39] fix: use main branch as base --- .github/workflows/discovery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index d6c5a31f..66d4806b 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -18,6 +18,7 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v5 with: + base: main add-paths: src/types.d.ts commit-message: "chore: update types from Discovery" title: "chore: update types from Discovery" From 34cb456ed9ed3c02677cae3c84382f792d5f1e79 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 22 Jan 2024 11:02:23 -0400 Subject: [PATCH 04/39] fix: update types script to keep license header --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5bd1160c..726fa485 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "pretest": "npm run compile", "docs-test": "linkinator docs", "predocs-test": "npm run docs", - "types": "dtsd bigquery v2 > ./src/types.d.ts", + "types": "head -n 14 ./src/types.d.ts > /tmp/license && cat /tmp/license > ./src/types.d.ts && dtsd bigquery v2 >> ./src/types.d.ts", "prelint": "cd samples; npm link ../; npm install", "precompile": "gts clean" }, From 5162b72c69f652a1e890037aa6fca7db1a43effb Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 22 Jan 2024 11:06:39 -0400 Subject: [PATCH 05/39] ci: update branch name --- .github/workflows/discovery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 66d4806b..4da3405b 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -19,6 +19,7 @@ jobs: uses: peter-evans/create-pull-request@v5 with: base: main + branch: update-discovery/patch add-paths: src/types.d.ts commit-message: "chore: update types from Discovery" title: "chore: update types from Discovery" From af93438eb878c51464513615fc0fcb6d2ae02b79 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 14 May 2024 14:30:16 -0400 Subject: [PATCH 06/39] chore: update actions versions --- .github/workflows/discovery.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 4da3405b..b4c8d03b 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -7,16 +7,16 @@ jobs: sync: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 16 # Install all deps, including dev dependencies. - run: npm install # Generate types - run: npm run types - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 + uses: peter-evans/create-pull-request@v6 with: base: main branch: update-discovery/patch From 5edee9bb79cc56803d215df1fe27e8e0a7f44230 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Thu, 23 May 2024 16:34:32 -0400 Subject: [PATCH 07/39] ci: remove pr trigger --- .github/workflows/discovery.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index b4c8d03b..e141a230 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,7 +1,6 @@ on: schedule: - cron: '0 12 * * TUE' - pull_request: name: Update Discovery Generated Types jobs: sync: From 94ca295826ae9c655edf2fd52bfe20af859a55ae Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Fri, 24 May 2024 15:14:55 -0400 Subject: [PATCH 08/39] fix: remove package.json change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbdc4da9..c75e3130 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "prepare": "npm run compile", "pretest": "npm run compile", "docs-test": "linkinator docs", - "predocs-test": "npm run docs", + "predocs-test": "npm run docs", "types": "node scripts/gen-types.js", "prelint": "cd samples; npm link ../; npm install", "precompile": "gts clean" From 1e989ae92fb9dad36f620e33eec8b0fc4689135c Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Fri, 31 May 2024 15:36:39 -0400 Subject: [PATCH 09/39] ci: use commit hash on gha --- .github/workflows/discovery.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index e141a230..4c8b8811 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -6,8 +6,8 @@ jobs: sync: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: node-version: 16 # Install all deps, including dev dependencies. @@ -15,7 +15,7 @@ jobs: # Generate types - run: npm run types - name: Create Pull Request - uses: peter-evans/create-pull-request@v6 + uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 with: base: main branch: update-discovery/patch From 8ddc84906d5fb479c7dd571a783d8062274e688e Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 15:25:13 -0400 Subject: [PATCH 10/39] ci: change to run daily --- .github/workflows/discovery.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 4c8b8811..4b31d1b7 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,6 +1,6 @@ on: schedule: - - cron: '0 12 * * TUE' + - cron: '0 12 * * *' name: Update Discovery Generated Types jobs: sync: From 0ce8210a8ccbd887b4ad46411a82eb1e3c9e359d Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:14:17 -0400 Subject: [PATCH 11/39] ci: move away from external action to create PR --- .github/workflows/discovery.yaml | 15 ++---- package.json | 1 + scripts/submit-discovery-pr.js | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 scripts/submit-discovery-pr.js diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 4b31d1b7..c965ce17 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,6 +1,7 @@ on: schedule: - cron: '0 12 * * *' + workflow_dispatch: name: Update Discovery Generated Types jobs: sync: @@ -14,14 +15,8 @@ jobs: - run: npm install # Generate types - run: npm run types - - name: Create Pull Request - uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 - with: - base: main - branch: update-discovery/patch - add-paths: src/types.d.ts - commit-message: "chore: update types from Discovery" - title: "chore: update types from Discovery" - body: | - Automated pull-request to keep BigQuery Discovery types up-to-date. + # Submit pull request + - run: npm run submit-discovery-pr + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index b5545d1b..db0122d8 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "docs-test": "linkinator docs", "predocs-test": "npm run docs", "types": "node scripts/gen-types.js", + "submit-discovery-pr": "node scripts/submit-discovery-pr.js", "prelint": "cd samples; npm link ../; npm install", "precompile": "gts clean" }, diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js new file mode 100644 index 00000000..23e3bff3 --- /dev/null +++ b/scripts/submit-discovery-pr.js @@ -0,0 +1,83 @@ +// Copyright 2024 Google LLC +// +// 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 +// +// https://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. + +const execa = require('execa'); +const path = require('path'); +const fs = require('fs'); +const gaxios = require('gaxios'); + +const REPO = 'googleapis/bigquery-nodejs'; +const BRANCH = 'update-discovery/patch'; +const TRACK_PATHS = ['src/types.d.ts']; +const COMMIT_MESSAGE = 'chore: update types from Discovery'; +const COMMIT_BODY = + 'Automated pull-request to keep BigQuery Discovery types up-to-date.'; + +async function submitDiscoveryPR() { + const statusResult = await execa('git', ['status', '--porcelain']); + const status = statusResult.stdout; + const statusFiles = status.split('\n').map(x => x.slice(3)); + + const foundChanges = statusFiles.filter(f => { + return TRACK_PATHS.some(filename => f.startsWith(filename)); + }); + console.log(`Changes found in ${foundChanges.length} files`); + console.log(foundChanges.join('\n')); + + if (foundChanges.length === 0) { + console.log('No changes found'); + return; + } + + await execa('git', ['checkout', '-B', BRANCH]); + for (const filename of foundChanges) { + await execa('git', ['add', filename]); + } + await execa('git', ['commit', '-m', COMMIT_MESSAGE, '-m', COMMIT_BODY]); + await execa('git', ['push', 'origin', BRANCH, '--force']); + + + const githubToken = process.env.GITHUB_TOKEN; + if (!githubToken) { + throw new Error('please include a GITHUB_TOKEN'); + } + + if (process.env.GITHUB_ACTIONS) { + await execa('git', ['config', 'user.email', 'yoshi-automation@google.com']); + await execa('git', ['config', 'user.name', 'Yoshi Automation']); + } + + try { + // Open the pull request with the YOSHI_CODE_BOT_TOKEN + await gaxios.request({ + method: 'POST', + headers: { + Authorization: `token ${githubToken}`, + }, + url: `https://api.github.com/repos/${REPO}/pulls`, + data: { + title: COMMIT_MESSAGE, + head: BRANCH, + base: 'main', + body: COMMIT_BODY, + }, + }); + } catch (err) { + console.error('failed to submit Pull Request', err); + throw err; + } + await execa('git', ['checkout', 'main']); +} + +submitDiscoveryPR(); From 032b51c383f57dd9d8a9d1fe5e5ffde45831bb90 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:16:00 -0400 Subject: [PATCH 12/39] fix: lint issues --- scripts/submit-discovery-pr.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 23e3bff3..89e55775 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -47,7 +47,6 @@ async function submitDiscoveryPR() { await execa('git', ['commit', '-m', COMMIT_MESSAGE, '-m', COMMIT_BODY]); await execa('git', ['push', 'origin', BRANCH, '--force']); - const githubToken = process.env.GITHUB_TOKEN; if (!githubToken) { throw new Error('please include a GITHUB_TOKEN'); From 7966a792584e4570e1eefaa9e369be958d540678 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:23:30 -0400 Subject: [PATCH 13/39] ci: add dev deps --- package.json | 2 ++ scripts/submit-discovery-pr.js | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index db0122d8..e257af8d 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,9 @@ "arrify": "^2.0.1", "big.js": "^6.0.0", "duplexify": "^4.0.0", + "execa": "^9.1.0", "extend": "^3.0.2", + "gaxios": "^6.6.0", "is": "^3.3.0", "stream-events": "^1.0.5", "uuid": "^9.0.0" diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 89e55775..5668380d 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -13,8 +13,6 @@ // limitations under the License. const execa = require('execa'); -const path = require('path'); -const fs = require('fs'); const gaxios = require('gaxios'); const REPO = 'googleapis/bigquery-nodejs'; From 96a792c62f26da541c3943b53c019e4cbb7c26ed Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:26:03 -0400 Subject: [PATCH 14/39] ci: update deps to older version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e257af8d..08d8d1f7 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,9 @@ "arrify": "^2.0.1", "big.js": "^6.0.0", "duplexify": "^4.0.0", - "execa": "^9.1.0", + "execa": "^5.0.0", "extend": "^3.0.2", - "gaxios": "^6.6.0", + "gaxios": "^6.0.3", "is": "^3.3.0", "stream-events": "^1.0.5", "uuid": "^9.0.0" From f6abb6694d70243af48b11ffb37d7af0d39207a5 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:34:27 -0400 Subject: [PATCH 15/39] ci: temp enable to run on PR --- .github/workflows/discovery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index c965ce17..3d5523df 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,6 +1,7 @@ on: schedule: - cron: '0 12 * * *' + pull_request: workflow_dispatch: name: Update Discovery Generated Types jobs: From b0ce38cdd98893dadc2a2a8d7932ac91a9c03f5f Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:36:49 -0400 Subject: [PATCH 16/39] fix: set up git user ealier --- scripts/submit-discovery-pr.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 5668380d..e228bb37 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -38,6 +38,11 @@ async function submitDiscoveryPR() { return; } + if (process.env.GITHUB_ACTIONS) { + await execa('git', ['config', 'user.email', 'yoshi-automation@google.com']); + await execa('git', ['config', 'user.name', 'Yoshi Automation']); + } + await execa('git', ['checkout', '-B', BRANCH]); for (const filename of foundChanges) { await execa('git', ['add', filename]); @@ -50,11 +55,6 @@ async function submitDiscoveryPR() { throw new Error('please include a GITHUB_TOKEN'); } - if (process.env.GITHUB_ACTIONS) { - await execa('git', ['config', 'user.email', 'yoshi-automation@google.com']); - await execa('git', ['config', 'user.name', 'Yoshi Automation']); - } - try { // Open the pull request with the YOSHI_CODE_BOT_TOKEN await gaxios.request({ From b4997bddd1f1aa9d83210d2757ff28b9ce725b2a Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:45:04 -0400 Subject: [PATCH 17/39] test: set personal fork --- scripts/submit-discovery-pr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index e228bb37..4dafabed 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -15,7 +15,7 @@ const execa = require('execa'); const gaxios = require('gaxios'); -const REPO = 'googleapis/bigquery-nodejs'; +const REPO = 'alvarowolfx/nodejs-bigquery'; const BRANCH = 'update-discovery/patch'; const TRACK_PATHS = ['src/types.d.ts']; const COMMIT_MESSAGE = 'chore: update types from Discovery'; @@ -56,7 +56,7 @@ async function submitDiscoveryPR() { } try { - // Open the pull request with the YOSHI_CODE_BOT_TOKEN + // Open the pull request with the GITHUB_TOKEN await gaxios.request({ method: 'POST', headers: { From d39ccf0b7566b44e9b688277a5a582271ccb1efc Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:53:43 -0400 Subject: [PATCH 18/39] ci: validate that pr exists --- scripts/submit-discovery-pr.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 4dafabed..092224bc 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -71,8 +71,20 @@ async function submitDiscoveryPR() { }, }); } catch (err) { - console.error('failed to submit Pull Request', err); - throw err; + console.error('failed to submit Pull Request:', err); + if (err.response && err.response.data) { + if (err.response.data.errors) { + const errors = err.response.data.errors; + const exists = errors.some(err => + err.message.includes('already exists') + ); + if (!exists) { + throw err; + } + } + } else { + throw err; + } } await execa('git', ['checkout', 'main']); } From 53661f972f3423395efc26c71eee1a94d276f45f Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:55:26 -0400 Subject: [PATCH 19/39] fix: remove checkout main --- scripts/submit-discovery-pr.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 092224bc..d1f52917 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -81,6 +81,7 @@ async function submitDiscoveryPR() { if (!exists) { throw err; } + console.log('PR already exists'); } } else { throw err; From b094d54b775febef50496a27f75154176dacd4f6 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:55:49 -0400 Subject: [PATCH 20/39] fix: remove checkout main --- scripts/submit-discovery-pr.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index d1f52917..4017f53b 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -87,7 +87,6 @@ async function submitDiscoveryPR() { throw err; } } - await execa('git', ['checkout', 'main']); } submitDiscoveryPR(); From 5cf7d65effe529ebac96418d8ca235f8b7cf351b Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 3 Jun 2024 16:58:19 -0400 Subject: [PATCH 21/39] ci: set main repo --- scripts/submit-discovery-pr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 4017f53b..8d73cfa6 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -15,7 +15,7 @@ const execa = require('execa'); const gaxios = require('gaxios'); -const REPO = 'alvarowolfx/nodejs-bigquery'; +const REPO = 'googleapis/nodejs-bigquery'; const BRANCH = 'update-discovery/patch'; const TRACK_PATHS = ['src/types.d.ts']; const COMMIT_MESSAGE = 'chore: update types from Discovery'; From 7d54344d360e463af615f1f438f9158d2d82a9d9 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 11:28:58 -0400 Subject: [PATCH 22/39] ci: change to weekly sync --- .github/workflows/discovery.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 3d5523df..af9addde 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,6 +1,6 @@ on: schedule: - - cron: '0 12 * * *' + - cron: '0 12 * * TUE' pull_request: workflow_dispatch: name: Update Discovery Generated Types From ce7b21ae70c5e725898c65e3ab5071f2d07d7b3c Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 12:29:48 -0400 Subject: [PATCH 23/39] ci: change github token env --- .github/workflows/discovery.yaml | 2 +- scripts/submit-discovery-pr.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index af9addde..03add2aa 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -19,5 +19,5 @@ jobs: # Submit pull request - run: npm run submit-discovery-pr env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CODE_BOT_TOKEN: ${{ secrets.APIARY_GEN_SECRET }} diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 8d73cfa6..da1a6167 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -50,9 +50,9 @@ async function submitDiscoveryPR() { await execa('git', ['commit', '-m', COMMIT_MESSAGE, '-m', COMMIT_BODY]); await execa('git', ['push', 'origin', BRANCH, '--force']); - const githubToken = process.env.GITHUB_TOKEN; - if (!githubToken) { - throw new Error('please include a GITHUB_TOKEN'); + const codeBotToken = process.env.CODE_BOT_TOKEN; + if (!codeBotToken) { + throw new Error('please include a CODE_BOT_TOKEN'); } try { From 95d423965608aeac9c97fec7709050822b580dc5 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 12:32:44 -0400 Subject: [PATCH 24/39] ci: add comment on line to remove on workflow --- .github/workflows/discovery.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 03add2aa..ad057426 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,7 +1,7 @@ on: schedule: - cron: '0 12 * * TUE' - pull_request: + pull_request: # REMOVE BEFORE MERGING workflow_dispatch: name: Update Discovery Generated Types jobs: From 13b1da4fa47f1f9e3702a0eb13f08c7572eb1fdf Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 12:42:20 -0400 Subject: [PATCH 25/39] ci: add github token back --- .github/workflows/discovery.yaml | 1 + scripts/submit-discovery-pr.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index ad057426..d43ed498 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -19,5 +19,6 @@ jobs: # Submit pull request - run: npm run submit-discovery-pr env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CODE_BOT_TOKEN: ${{ secrets.APIARY_GEN_SECRET }} diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index da1a6167..e91b0241 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -50,6 +50,10 @@ async function submitDiscoveryPR() { await execa('git', ['commit', '-m', COMMIT_MESSAGE, '-m', COMMIT_BODY]); await execa('git', ['push', 'origin', BRANCH, '--force']); + const githubToken = process.env.GITHUB_TOKEN; + if (!githubToken) { + throw new Error('please include a GITHUB_TOKEN'); + } const codeBotToken = process.env.CODE_BOT_TOKEN; if (!codeBotToken) { throw new Error('please include a CODE_BOT_TOKEN'); From 11a7ea96346fb75b46a979333d9e1cb668dad3ef Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 13:16:26 -0400 Subject: [PATCH 26/39] fix: move execa/gaxios as dev deps --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 08d8d1f7..c59deb1a 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,7 @@ "arrify": "^2.0.1", "big.js": "^6.0.0", "duplexify": "^4.0.0", - "execa": "^5.0.0", "extend": "^3.0.2", - "gaxios": "^6.0.3", "is": "^3.3.0", "stream-events": "^1.0.5", "uuid": "^9.0.0" @@ -87,6 +85,8 @@ "prettier": "^3.0.0", "proxyquire": "^2.1.0", "sinon": "^18.0.0", - "typescript": "^5.1.6" + "typescript": "^5.1.6", + "gaxios": "^6.0.3", + "execa": "^5.0.0" } } From fa6f5ca46d0db65c733482547a72dc89bad6234a Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 14:04:02 -0400 Subject: [PATCH 27/39] ci: move to GITHUB_TOKEN --- scripts/submit-discovery-pr.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index e91b0241..8d73cfa6 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -54,10 +54,6 @@ async function submitDiscoveryPR() { if (!githubToken) { throw new Error('please include a GITHUB_TOKEN'); } - const codeBotToken = process.env.CODE_BOT_TOKEN; - if (!codeBotToken) { - throw new Error('please include a CODE_BOT_TOKEN'); - } try { // Open the pull request with the GITHUB_TOKEN From f8ba4620966075f7c0fd3b22aadfc21ec864bb90 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 14:09:38 -0400 Subject: [PATCH 28/39] ci: force set GITHUB_ACTION env --- .github/workflows/discovery.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index d43ed498..76e9d79b 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -2,7 +2,7 @@ on: schedule: - cron: '0 12 * * TUE' pull_request: # REMOVE BEFORE MERGING - workflow_dispatch: + workflow_dispatch: name: Update Discovery Generated Types jobs: sync: @@ -20,5 +20,4 @@ jobs: - run: npm run submit-discovery-pr env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CODE_BOT_TOKEN: ${{ secrets.APIARY_GEN_SECRET }} - + GITHUB_ACTIONS: true From 260b2f36a0a6cfaceb11512f64310fdb1d77c9cd Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 14:32:02 -0400 Subject: [PATCH 29/39] ci: submitted PR should use main as base branch --- scripts/submit-discovery-pr.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 8d73cfa6..930cec4b 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -17,6 +17,7 @@ const gaxios = require('gaxios'); const REPO = 'googleapis/nodejs-bigquery'; const BRANCH = 'update-discovery/patch'; +const BASE_BRANCH = 'main'; const TRACK_PATHS = ['src/types.d.ts']; const COMMIT_MESSAGE = 'chore: update types from Discovery'; const COMMIT_BODY = @@ -43,7 +44,7 @@ async function submitDiscoveryPR() { await execa('git', ['config', 'user.name', 'Yoshi Automation']); } - await execa('git', ['checkout', '-B', BRANCH]); + await execa('git', ['checkout', '-B', BRANCH, BASE_BRANCH]); for (const filename of foundChanges) { await execa('git', ['add', filename]); } @@ -56,7 +57,7 @@ async function submitDiscoveryPR() { } try { - // Open the pull request with the GITHUB_TOKEN + // Open the pull request await gaxios.request({ method: 'POST', headers: { @@ -66,7 +67,7 @@ async function submitDiscoveryPR() { data: { title: COMMIT_MESSAGE, head: BRANCH, - base: 'main', + base: BASE_BRANCH, body: COMMIT_BODY, }, }); From b325af38db4470af80088d84850a8a8b10d895f5 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 14:37:43 -0400 Subject: [PATCH 30/39] fix: use YOSHI_CODE_BOT_TOKEN token --- .github/workflows/discovery.yaml | 3 +-- scripts/submit-discovery-pr.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 76e9d79b..1646f84b 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -19,5 +19,4 @@ jobs: # Submit pull request - run: npm run submit-discovery-pr env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_ACTIONS: true + GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 930cec4b..99476b03 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -44,7 +44,7 @@ async function submitDiscoveryPR() { await execa('git', ['config', 'user.name', 'Yoshi Automation']); } - await execa('git', ['checkout', '-B', BRANCH, BASE_BRANCH]); + await execa('git', ['checkout', '-B', BRANCH]); for (const filename of foundChanges) { await execa('git', ['add', filename]); } From 9611cfc0b10d3ae715919277034ead9c8c12a5e1 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 14:50:29 -0400 Subject: [PATCH 31/39] fix: use bearer token --- scripts/submit-discovery-pr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js index 99476b03..032b77fb 100644 --- a/scripts/submit-discovery-pr.js +++ b/scripts/submit-discovery-pr.js @@ -61,7 +61,7 @@ async function submitDiscoveryPR() { await gaxios.request({ method: 'POST', headers: { - Authorization: `token ${githubToken}`, + Authorization: `Bearer ${githubToken}`, }, url: `https://api.github.com/repos/${REPO}/pulls`, data: { From 1911ac6db4a04a15db3f247da1d899909e3bb629 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 15:12:36 -0400 Subject: [PATCH 32/39] ci: move pr submission to in house code-suggester --- .github/workflows/discovery.yaml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 1646f84b..86718443 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,12 +1,13 @@ on: schedule: - cron: '0 12 * * TUE' - pull_request: # REMOVE BEFORE MERGING workflow_dispatch: name: Update Discovery Generated Types jobs: sync: runs-on: ubuntu-latest + env: + ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 @@ -17,6 +18,14 @@ jobs: # Generate types - run: npm run types # Submit pull request - - run: npm run submit-discovery-pr - env: - GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} + - uses: googleapis/code-suggester@v2 + with: + command: pr + upstream_owner: googleapis + upstream_repo: nodejs-bigquery + description: 'Automated pull-request to keep BigQuery Discovery types up-to-date.' + title: 'chore: update types from Discovery' + message: 'chore: update types from Discovery' + branch: update-discovery/patch + git_dir: '.' + fork: true From 1bf2e841a92539c350b406720701fca5e9806035 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 15:13:31 -0400 Subject: [PATCH 33/39] ci: temp enable to run on PR --- .github/workflows/discovery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 86718443..233283c9 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -2,6 +2,7 @@ on: schedule: - cron: '0 12 * * TUE' workflow_dispatch: + pull_request: # REMOVE BEFORE MERGING name: Update Discovery Generated Types jobs: sync: From b36d1d6d070e8327776bd2d0e3ae9bc9ed6c1564 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 15:34:57 -0400 Subject: [PATCH 34/39] ci: change branch name --- .github/workflows/discovery.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 233283c9..40463fe7 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -27,6 +27,6 @@ jobs: description: 'Automated pull-request to keep BigQuery Discovery types up-to-date.' title: 'chore: update types from Discovery' message: 'chore: update types from Discovery' - branch: update-discovery/patch + branch: update-discovery-patch git_dir: '.' fork: true From 55982cb4ace5613ac3e4364ca50d0c2c95f07f61 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 15:39:35 -0400 Subject: [PATCH 35/39] cleanup: remove unused submit pr code and PR trigger --- .github/workflows/discovery.yaml | 3 +- package.json | 5 +- scripts/submit-discovery-pr.js | 93 -------------------------------- 3 files changed, 2 insertions(+), 99 deletions(-) delete mode 100644 scripts/submit-discovery-pr.js diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 40463fe7..3f5fb392 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,8 +1,7 @@ on: schedule: - cron: '0 12 * * TUE' - workflow_dispatch: - pull_request: # REMOVE BEFORE MERGING + workflow_dispatch: name: Update Discovery Generated Types jobs: sync: diff --git a/package.json b/package.json index c59deb1a..b5545d1b 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "docs-test": "linkinator docs", "predocs-test": "npm run docs", "types": "node scripts/gen-types.js", - "submit-discovery-pr": "node scripts/submit-discovery-pr.js", "prelint": "cd samples; npm link ../; npm install", "precompile": "gts clean" }, @@ -85,8 +84,6 @@ "prettier": "^3.0.0", "proxyquire": "^2.1.0", "sinon": "^18.0.0", - "typescript": "^5.1.6", - "gaxios": "^6.0.3", - "execa": "^5.0.0" + "typescript": "^5.1.6" } } diff --git a/scripts/submit-discovery-pr.js b/scripts/submit-discovery-pr.js deleted file mode 100644 index 032b77fb..00000000 --- a/scripts/submit-discovery-pr.js +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2024 Google LLC -// -// 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 -// -// https://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. - -const execa = require('execa'); -const gaxios = require('gaxios'); - -const REPO = 'googleapis/nodejs-bigquery'; -const BRANCH = 'update-discovery/patch'; -const BASE_BRANCH = 'main'; -const TRACK_PATHS = ['src/types.d.ts']; -const COMMIT_MESSAGE = 'chore: update types from Discovery'; -const COMMIT_BODY = - 'Automated pull-request to keep BigQuery Discovery types up-to-date.'; - -async function submitDiscoveryPR() { - const statusResult = await execa('git', ['status', '--porcelain']); - const status = statusResult.stdout; - const statusFiles = status.split('\n').map(x => x.slice(3)); - - const foundChanges = statusFiles.filter(f => { - return TRACK_PATHS.some(filename => f.startsWith(filename)); - }); - console.log(`Changes found in ${foundChanges.length} files`); - console.log(foundChanges.join('\n')); - - if (foundChanges.length === 0) { - console.log('No changes found'); - return; - } - - if (process.env.GITHUB_ACTIONS) { - await execa('git', ['config', 'user.email', 'yoshi-automation@google.com']); - await execa('git', ['config', 'user.name', 'Yoshi Automation']); - } - - await execa('git', ['checkout', '-B', BRANCH]); - for (const filename of foundChanges) { - await execa('git', ['add', filename]); - } - await execa('git', ['commit', '-m', COMMIT_MESSAGE, '-m', COMMIT_BODY]); - await execa('git', ['push', 'origin', BRANCH, '--force']); - - const githubToken = process.env.GITHUB_TOKEN; - if (!githubToken) { - throw new Error('please include a GITHUB_TOKEN'); - } - - try { - // Open the pull request - await gaxios.request({ - method: 'POST', - headers: { - Authorization: `Bearer ${githubToken}`, - }, - url: `https://api.github.com/repos/${REPO}/pulls`, - data: { - title: COMMIT_MESSAGE, - head: BRANCH, - base: BASE_BRANCH, - body: COMMIT_BODY, - }, - }); - } catch (err) { - console.error('failed to submit Pull Request:', err); - if (err.response && err.response.data) { - if (err.response.data.errors) { - const errors = err.response.data.errors; - const exists = errors.some(err => - err.message.includes('already exists') - ); - if (!exists) { - throw err; - } - console.log('PR already exists'); - } - } else { - throw err; - } - } -} - -submitDiscoveryPR(); From 39c3cda7f2263da216cf56f00a1873992ae64471 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 16:10:27 -0400 Subject: [PATCH 36/39] fix: run linter after generating types --- .github/workflows/discovery.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 3f5fb392..0263f951 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -1,7 +1,8 @@ on: schedule: - cron: '0 12 * * TUE' - workflow_dispatch: + workflow_dispatch: + pull_request: name: Update Discovery Generated Types jobs: sync: @@ -17,6 +18,8 @@ jobs: - run: npm install # Generate types - run: npm run types + # Fix formatting + - run: npm run fix # Submit pull request - uses: googleapis/code-suggester@v2 with: From 30e117eac09c37760bb9ba1be33ab41c014fea08 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 16:19:27 -0400 Subject: [PATCH 37/39] ci: install samples deps --- .github/workflows/discovery.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 0263f951..82bffb97 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -2,7 +2,7 @@ on: schedule: - cron: '0 12 * * TUE' workflow_dispatch: - pull_request: + pull_request: name: Update Discovery Generated Types jobs: sync: @@ -18,6 +18,8 @@ jobs: - run: npm install # Generate types - run: npm run types + # Install samples deps + - run: cd samples/ && npm install && cd ../ # Fix formatting - run: npm run fix # Submit pull request From 95a62d57c9fdeb1b974b494e460dfab9ef732b3d Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 16:22:44 -0400 Subject: [PATCH 38/39] ci: force branch update --- .github/workflows/discovery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 82bffb97..8eae87e5 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -34,3 +34,4 @@ jobs: branch: update-discovery-patch git_dir: '.' fork: true + force: true From 82e089adf9740954d3947697ad8561760648b5fa Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 4 Jun 2024 16:26:50 -0400 Subject: [PATCH 39/39] cleanup: remove PR trigger --- .github/workflows/discovery.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/discovery.yaml b/.github/workflows/discovery.yaml index 8eae87e5..92a8e1cb 100644 --- a/.github/workflows/discovery.yaml +++ b/.github/workflows/discovery.yaml @@ -2,7 +2,6 @@ on: schedule: - cron: '0 12 * * TUE' workflow_dispatch: - pull_request: name: Update Discovery Generated Types jobs: sync: