Skip to content
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

Add mergebot #1023

Merged
merged 16 commits into from
Jul 1, 2024
33 changes: 33 additions & 0 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Daily Open PR Sync

on:
workflow_dispatch: ~
schedule:
- cron: '37 */6 * * *'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '20.x'
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- run: pnpm install
- run: pnpm run build

# Go through all open PRs and run the bot over them
- run: node packages/mergebot/dist/run.js
env:
TYPESCRIPT_BOT_TOKEN: ${{ secrets.TYPESCRIPT_BOT_TOKEN }}

keepalive-job:
name: Keepalive Workflow
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: gautamkrishnar/keepalive-workflow@05456e7809058d586d96392e99217726ccc10076 # v2.0.5
81 changes: 81 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Deploy to Azure

on:
push:
branches:
- master
workflow_dispatch:

env:
NODE_VERSION: '18.x' # set this to the node version to use (supports 8.x, 10.x, 12.x)
RESOURCE_GROUP_NAME: dtmergebot3
FUNCTION_APP_NAME: dtmergebot3
STORAGE_ACCOUNT_NAME: dtmergebot3b1b7
STORAGE_CONTAINER_NAME: deployment
FUNCTION_ZIP_NAME: function.zip

defaults:
run:
shell: bash

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ env.NODE_VERSION }}

- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0

- name: Install and test
run: |
pnpm install
pnpm run --if-present build
pnpm run --if-present test
- name: Bundle
working-directory: packages/mergebot
run: pnpm run bundle

- name: Check bundle
run: TYPESCRIPT_BOT_TOKEN=secret node packages/mergebot/dist/functions/index.js

- name: Create zip
run: zip -r ${{ env.FUNCTION_ZIP_NAME }} packagaes/mergebot/dist packages/mergebot/host.json packages/mergebot/package.json
Copy link
Member

@jakebailey jakebailey Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to check this; the paths put into the zip may now be nested because we're using longer paths as the input. Better would be to consistently use working-directory, then output to ${{ env.GITHUB_WORKSPACE }}/${{ env.FUNCTION_ZIP_NAME }}.


- name: Upload artifact for deployment job
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: node-app
path: ${{ env.FUNCTION_ZIP_NAME }}

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
permissions:
id-token: write
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id-token: write
contents: read
id-token: write


steps:
- name: Download artifact from build job
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
name: node-app

- uses: azure/login@6c251865b4e6290e7b78be643ea2d005bc51f69a # v2.1.1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Upload blob
run: az storage blob upload -f ${{ env.FUNCTION_ZIP_NAME }} --account-name ${{ env.STORAGE_ACCOUNT_NAME }} -c ${{ env.STORAGE_CONTAINER_NAME }} -n ${{ env.FUNCTION_ZIP_NAME }} --overwrite true --auth-mode login

# - name: Set package path
# run: az functionapp config appsettings set -g ${{ env.RESOURCE_GROUP_NAME }} -n ${{ env.FUNCTION_APP_NAME }} --settings WEBSITE_RUN_FROM_PACKAGE="https://${{ env.STORAGE_ACCOUNT_NAME }}.blob.core.windows.net/${{ env.STORAGE_CONTAINER_NAME }}/${{ env.FUNCTION_ZIP_NAME }}"

- name: Restart app
run: az functionapp restart -g ${{ env.RESOURCE_GROUP_NAME }} -n ${{ env.FUNCTION_APP_NAME }}
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term I don't think we need this; we already have a workflow which does testing and should be doing these tests.

on: pull_request

defaults:
run:
shell: bash

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '20.x'
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- run: pnpm install
- run: pnpm run lint
- run: npx knip
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '20.x'
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
- run: pnpm install
- run: pnpm run build
- run: pnpm test
- working-directory: packages/mergebot
run: pnpm run bundle
- run: TYPESCRIPT_BOT_TOKEN=secret node packages/mergebot/dist/functions/index.js
2 changes: 1 addition & 1 deletion .knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"ignoreDependencies": ["@qiwi/npm-types"]
},
"packages/mergebot": {
"entry": ["src/index.ts"],
"entry": ["src/functions/index.ts"],
"project": "**/*.ts"
}
},
Expand Down
13 changes: 7 additions & 6 deletions packages/mergebot/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "dt-mergebot",
"version": "3.0.0",
"name": "@definitelytyped/mergebot",
"private": true,
"version": "0.1.12",
"description": "The bot that manages DefinitelyTyped PRs.",
"author": "DT Maintainers",
"homepage": "https://github.com/DefinitelyTyped/dt-mergebot#readme",
"homepage": "https://github.com/microsoft/definitelytyped-tools#readme",
"main": "dist/functions/index.js",
"repository": {
"type": "git",
"url": "https://github.com/DefinitelyTyped/dt-mergebot.git"
"url": "https://github.com/microsoft/definitelytyped-tools.git"
sandersn marked this conversation as resolved.
Show resolved Hide resolved
},
"bugs": {
"url": "https://github.com/DefinitelyTyped/dt-mergebot/issues"
"url": "https://github.com/microsoft/definitelytyped-tools/issues"
},
"license": "MIT",
"engines": {
Expand All @@ -20,7 +21,7 @@
"@apollo/client": "^3.10.3",
"@azure/functions": "^4.4.0",
"@definitelytyped/old-header-parser": "npm:@definitelytyped/[email protected]",
sandersn marked this conversation as resolved.
Show resolved Hide resolved
"@definitelytyped/utils": "workspace:",
"@definitelytyped/utils": "workspace:*",
"@octokit/webhooks-methods": "^4.1.0",
"dayjs": "^1.11.11",
"fast-json-patch": "^3.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/mergebot/src/_tests/fixturedActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/* You can use the following command to add/update fixtures with an existing PR
*
* BOT_AUTH_TOKEN=XYZ pnpm run create-fixture -- 43164
* TYPESCRIPT_BOT_TOKEN=XYZ pnpm run create-fixture -- 43164
*/

async function testFixture(dir: string) {
Expand All @@ -29,7 +29,7 @@
const resultPath = join(dir, "result.json");
const mutationsPath = join(dir, "mutations.json");

const JSONString = (value: any) => scrubDiagnosticDetails(JSON.stringify(value, null, " ") + "\n");

Check failure on line 32 in packages/mergebot/src/_tests/fixturedActions.test.ts

View workflow job for this annotation

GitHub Actions / lint

Variable name `JSONString` must match one of the following formats: camelCase

Check failure on line 32 in packages/mergebot/src/_tests/fixturedActions.test.ts

View workflow job for this annotation

GitHub Actions / build and test (ubuntu-latest)

Variable name `JSONString` must match one of the following formats: camelCase

Check failure on line 32 in packages/mergebot/src/_tests/fixturedActions.test.ts

View workflow job for this annotation

GitHub Actions / build and test (windows-latest)

Variable name `JSONString` must match one of the following formats: camelCase

const response: ApolloQueryResult<PR> = readJsonSync(responsePath);
const files = readJsonSync(filesPath);
Expand Down
2 changes: 1 addition & 1 deletion packages/mergebot/src/execute-pr-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function doRestCall(call: RestMutation): Promise<void> {
const url = `https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/${call.op}`;
const headers = {
"accept": "application/vnd.github.v3+json",
"authorization": `token ${process.env.BOT_AUTH_TOKEN}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not recommend changing any of the token names; we have these set in the function app. If anything I would rather us become consistent and just do GITHUB_TOKEN like most other tools.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, right. I got confused between the variables available to workflows vs functions.

"authorization": `token ${process.env.TYPESCRIPT_BOT_TOKEN}`,
"user-agent": "dt-mergebot"
};
return new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/mergebot/src/graphql-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export function createMutation<T>(name: keyof schema.Mutation, input: T, subquer
function getAuthToken() {
if (process.env.JEST_WORKER_ID) return "FAKE_TOKEN";

const result = process.env["BOT_AUTH_TOKEN"] || process.env["AUTH_TOKEN"] || process.env["DT_BOT_AUTH_TOKEN"];
const result = process.env["BOT_AUTH_TOKEN"] || process.env["AUTH_TOKEN"] || process.env["DT_BOT_AUTH_TOKEN"] || process.env["TYPESCRIPT_BOT_TOKEN"];
if (typeof result !== "string") {
throw new Error("Set either BOT_AUTH_TOKEN or AUTH_TOKEN to a valid auth token");
throw new Error("Set either BOT_AUTH_TOKEN or TYPESCRIPT_BOT_TOKEN to a valid auth token");
}
return result.trim();
}
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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

Loading