Skip to content

Refactor workflows for new typescript-bot triggers #57409

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
merged 11 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 50 additions & 32 deletions .github/workflows/create-cherry-pick-pr.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Create cherry pick PR

on:
repository_dispatch:
types: [create-cherry-pick-pr]
workflow_dispatch:
inputs:
pr:
Expand All @@ -13,10 +11,26 @@ on:
description: Target branch to cherry-pick to
required: true
type: string

# Inputs provided by the bot
distinct_id:
description: '(bot) A distinct ID'
required: false
default: ''
source_issue:
description: '(bot) The issue that triggered this workflow'
required: false
default: ''
requesting_user:
description: User who requested the cherry-pick
required: true
type: string
description: '(bot) The user who requested this workflow'
required: false
default: ''
status_comment:
description: '(bot) The comment to update with the status of this workflow'
required: false
default: ''

run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}

permissions:
contents: read
Expand All @@ -40,15 +54,27 @@ jobs:
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}

- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: open-pr
env:
PR: ${{ inputs.pr || github.event.client_payload.pr }}
TARGET_BRANCH: ${{ inputs.target_branch || github.event.client_payload.target_branch }}
REQUESTING_USER: ${{ inputs.requesting_user || github.event.client_payload.requesting_user }}
PR: ${{ inputs.pr }}
TARGET_BRANCH: ${{ inputs.target_branch }}
DISTINCT_ID: ${{ inputs.distinct_id }}
SOURCE_ISSUE: ${{ inputs.source_issue }}
REQUESTING_USER: ${{ inputs.requesting_user }}
STATUS_COMMENT: ${{ inputs.status_comment }}
with:
retries: 3
github-token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
result-encoding: string
script: |
const { PR, TARGET_BRANCH, REQUESTING_USER } = process.env;
const {
PR,
TARGET_BRANCH,
DISTINCT_ID,
SOURCE_ISSUE,
REQUESTING_USER,
STATUS_COMMENT,
} = process.env;

const pr = await github.rest.pulls.get({
owner: context.repo.owner,
Expand All @@ -75,6 +101,8 @@ jobs:
head: `${context.repo.owner}:${pickBranch}`,
});

let commentBody;

if (existingPulls.data.length === 0) {
console.log(`No existing PRs found for ${pickBranch}`);

Expand All @@ -91,12 +119,7 @@ jobs:
reviewers: ["DanielRosenwasser", REQUESTING_USER],
});

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: +PR,
body: `Hey @${REQUESTING_USER}, I've created #${newPr.data.number} for you.`,
});
commentBody = `I've created #${newPr.data.number} for you.`;
}
else {
const existing = existingPulls.data[0];
Expand All @@ -109,23 +132,18 @@ jobs:
title,
});

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: +PR,
body: `Hey @${REQUESTING_USER}, I've updated #${existing.number} for you.`,
});
commentBody = `I've updated #${existing.number} for you.`;
}

- run: |
MESSAGE="Hey @$REQUESTING_USER, I was unable to cherry-pick this PR."
MESSAGE+=$'\n\n'
MESSAGE+="Check the logs at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
return commentBody;

gh pr comment "$PR" --repo ${{ github.repository }} --body "$MESSAGE"
if: ${{ failure() }}
env:
PR: ${{ inputs.pr || github.event.client_payload.pr }}
TARGET_BRANCH: ${{ inputs.target_branch || github.event.client_payload.target_branch }}
REQUESTING_USER: ${{ inputs.requesting_user || github.event.client_payload.requesting_user }}
GH_TOKEN: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
if: ${{ !cancelled() && inputs.distinct_id }}
with:
success_comment: ${{ steps.open-pr.outputs.result }}
failure_comment: 'I was unable to cherry-pick this PR.'
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
distinct_id: ${{ inputs.distinct_id }}
source_issue: ${{ inputs.source_issue }}
requesting_user: ${{ inputs.requesting_user }}
status_comment: ${{ inputs.status_comment }}
63 changes: 53 additions & 10 deletions .github/workflows/new-release-branch.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
name: New Release Branch

on:
repository_dispatch:
types: [new-release-branch]
workflow_dispatch:
inputs:
branch_name:
description: Release branch name to create
required: true
type: number
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be string?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're totally right, copy paste error, blah

package_version:
description: Release package version
required: true
type: string
core_major_minor:
description: Release core major.minor version
required: true
type: string

# Inputs provided by the bot
distinct_id:
description: '(bot) A distinct ID'
required: false
default: ''
source_issue:
description: '(bot) The issue that triggered this workflow'
required: false
default: ''
requesting_user:
description: '(bot) The user who requested this workflow'
required: false
default: ''
status_comment:
description: '(bot) The comment to update with the status of this workflow'
required: false
default: ''

run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}

permissions:
contents: read
Expand Down Expand Up @@ -30,12 +62,12 @@ jobs:
npm install -g $(jq -r '.packageManager' < package.json)
npm --version
- run: |
git checkout -b ${{ github.event.client_payload.branch_name }}
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' src/compiler/corePublic.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ github.event.client_payload.package_version }}" as string;/g' src/compiler/corePublic.ts
git checkout -b ${{ inputs.branch_name }}
sed -i -e 's/"version": ".*"/"version": "${{ inputs.package_version }}"/g' package.json
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' src/compiler/corePublic.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ inputs.package_version }}" as string;/g' src/compiler/corePublic.ts
npm ci
npm install # update package-lock.json to ensure the version bump is included
npx hereby LKG
Expand All @@ -48,5 +80,16 @@ jobs:
git add --force ./lib
git config user.email "[email protected]"
git config user.name "TypeScript Bot"
git commit -m 'Bump version to ${{ github.event.client_payload.package_version }} and LKG'
git push --set-upstream origin ${{ github.event.client_payload.branch_name }}
git commit -m 'Bump version to ${{ inputs.package_version }} and LKG'
git push --set-upstream origin ${{ inputs.branch_name }}

- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
if: ${{ !cancelled() && inputs.distinct_id }}
with:
success_comment: "I've created ${{ inputs.branch_name }} with version ${{ inputs.package_version }} for you."
failure_comment: 'I was unable to create the new release branch.'
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
distinct_id: ${{ inputs.distinct_id }}
source_issue: ${{ inputs.source_issue }}
requesting_user: ${{ inputs.requesting_user }}
status_comment: ${{ inputs.status_comment }}
2 changes: 0 additions & 2 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
- cron: '0 7 * * *'
# enable users to manually trigger with workflow_dispatch
workflow_dispatch: {}
repository_dispatch:
types: [publish-nightly]

permissions:
contents: read
Expand Down
61 changes: 52 additions & 9 deletions .github/workflows/set-version.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
name: Set branch version

on:
repository_dispatch:
types: [set-version]
workflow_dispatch:
inputs:
branch_name:
description: Release branch name to create
required: true
type: number
Copy link
Member

Choose a reason for hiding this comment

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

Here, too.

package_version:
description: Release package version
required: true
type: string
core_major_minor:
description: Release core major.minor version
required: true
type: string

# Inputs provided by the bot
distinct_id:
description: '(bot) A distinct ID'
required: false
default: ''
source_issue:
description: '(bot) The issue that triggered this workflow'
required: false
default: ''
requesting_user:
description: '(bot) The user who requested this workflow'
required: false
default: ''
status_comment:
description: '(bot) The comment to update with the status of this workflow'
required: false
default: ''

run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}

permissions:
contents: read
Expand All @@ -19,7 +51,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.client_payload.branch_name }}
ref: ${{ inputs.branch_name }}
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
- run: |
Expand All @@ -35,11 +67,11 @@ jobs:
# package_version - the full version string (eg, `3.9.1-rc` or `3.9.2`)
# core_major_minor - the major.minor pair associated with the desired package_version (eg, `3.9` for `3.9.3`)
- run: |
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' src/compiler/corePublic.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ github.event.client_payload.package_version }}" as string;/g' src/compiler/corePublic.ts
sed -i -e 's/"version": ".*"/"version": "${{ inputs.package_version }}"/g' package.json
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' src/compiler/corePublic.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ inputs.package_version }}" as string;/g' src/compiler/corePublic.ts
npm ci
npm install # update package-lock.json to ensure the version bump is included
npx hereby LKG
Expand All @@ -52,5 +84,16 @@ jobs:
git add --force ./lib
git config user.email "[email protected]"
git config user.name "TypeScript Bot"
git commit -m 'Bump version to ${{ github.event.client_payload.package_version }} and LKG'
git commit -m 'Bump version to ${{ inputs.package_version }} and LKG'
git push

- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
if: ${{ !cancelled() && inputs.distinct_id }}
with:
success_comment: "I've set the version of ${{ inputs.branch_name }} to ${{ inputs.package_version }} for you."
failure_comment: 'I was unable set the version.'
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
distinct_id: ${{ inputs.distinct_id }}
source_issue: ${{ inputs.source_issue }}
requesting_user: ${{ inputs.requesting_user }}
status_comment: ${{ inputs.status_comment }}
38 changes: 34 additions & 4 deletions .github/workflows/sync-branch.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
name: Sync branch with master

on:
repository_dispatch:
types: [sync-branch]
workflow_dispatch:
inputs:
branch_name:
description: 'Target Branch Name'
description: Release branch name to create
required: true
type: number
Copy link
Member

Choose a reason for hiding this comment

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

Also here.


# Inputs provided by the bot
distinct_id:
description: '(bot) A distinct ID'
required: false
default: ''
source_issue:
description: '(bot) The issue that triggered this workflow'
required: false
default: ''
requesting_user:
description: '(bot) The user who requested this workflow'
required: false
default: ''
status_comment:
description: '(bot) The comment to update with the status of this workflow'
required: false
default: ''

run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}

permissions:
contents: read
Expand All @@ -26,7 +45,7 @@ jobs:
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.inputs.branch_name || github.event.client_payload.branch_name }}
ref: ${{ inputs.branch_name }}
filter: blob:none # https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/
fetch-depth: 0 # Default is 1; need to set to 0 to get the benefits of blob:none.
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
Expand All @@ -42,3 +61,14 @@ jobs:
git add --force ./lib
git commit -m 'Update LKG'
git push

- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
if: ${{ !cancelled() && inputs.distinct_id }}
with:
success_comment: "I've pulled main into ${{ inputs.branch_name }} for you."
failure_comment: 'I was unable merge main into ${{ inputs.branch_name }}.'
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
distinct_id: ${{ inputs.distinct_id }}
source_issue: ${{ inputs.source_issue }}
requesting_user: ${{ inputs.requesting_user }}
status_comment: ${{ inputs.status_comment }}
Loading