Skip to content

Commit f4eeea0

Browse files
authored
Refactor workflows for new typescript-bot triggers (#57409)
1 parent 8ada4ef commit f4eeea0

File tree

6 files changed

+209
-62
lines changed

6 files changed

+209
-62
lines changed

.github/workflows/create-cherry-pick-pr.yml

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Create cherry pick PR
22

33
on:
4-
repository_dispatch:
5-
types: [create-cherry-pick-pr]
64
workflow_dispatch:
75
inputs:
86
pr:
@@ -13,10 +11,26 @@ on:
1311
description: Target branch to cherry-pick to
1412
required: true
1513
type: string
14+
15+
# Inputs provided by the bot
16+
distinct_id:
17+
description: '(bot) A distinct ID'
18+
required: false
19+
default: ''
20+
source_issue:
21+
description: '(bot) The issue that triggered this workflow'
22+
required: false
23+
default: ''
1624
requesting_user:
17-
description: User who requested the cherry-pick
18-
required: true
19-
type: string
25+
description: '(bot) The user who requested this workflow'
26+
required: false
27+
default: ''
28+
status_comment:
29+
description: '(bot) The comment to update with the status of this workflow'
30+
required: false
31+
default: ''
32+
33+
run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}
2034

2135
permissions:
2236
contents: read
@@ -40,15 +54,27 @@ jobs:
4054
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
4155

4256
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
57+
id: open-pr
4358
env:
44-
PR: ${{ inputs.pr || github.event.client_payload.pr }}
45-
TARGET_BRANCH: ${{ inputs.target_branch || github.event.client_payload.target_branch }}
46-
REQUESTING_USER: ${{ inputs.requesting_user || github.event.client_payload.requesting_user }}
59+
PR: ${{ inputs.pr }}
60+
TARGET_BRANCH: ${{ inputs.target_branch }}
61+
DISTINCT_ID: ${{ inputs.distinct_id }}
62+
SOURCE_ISSUE: ${{ inputs.source_issue }}
63+
REQUESTING_USER: ${{ inputs.requesting_user }}
64+
STATUS_COMMENT: ${{ inputs.status_comment }}
4765
with:
4866
retries: 3
4967
github-token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
68+
result-encoding: string
5069
script: |
51-
const { PR, TARGET_BRANCH, REQUESTING_USER } = process.env;
70+
const {
71+
PR,
72+
TARGET_BRANCH,
73+
DISTINCT_ID,
74+
SOURCE_ISSUE,
75+
REQUESTING_USER,
76+
STATUS_COMMENT,
77+
} = process.env;
5278
5379
const pr = await github.rest.pulls.get({
5480
owner: context.repo.owner,
@@ -75,6 +101,8 @@ jobs:
75101
head: `${context.repo.owner}:${pickBranch}`,
76102
});
77103
104+
let commentBody;
105+
78106
if (existingPulls.data.length === 0) {
79107
console.log(`No existing PRs found for ${pickBranch}`);
80108
@@ -91,12 +119,7 @@ jobs:
91119
reviewers: ["DanielRosenwasser", REQUESTING_USER],
92120
});
93121
94-
await github.rest.issues.createComment({
95-
owner: context.repo.owner,
96-
repo: context.repo.repo,
97-
issue_number: +PR,
98-
body: `Hey @${REQUESTING_USER}, I've created #${newPr.data.number} for you.`,
99-
});
122+
commentBody = `I've created #${newPr.data.number} for you.`;
100123
}
101124
else {
102125
const existing = existingPulls.data[0];
@@ -109,23 +132,18 @@ jobs:
109132
title,
110133
});
111134
112-
await github.rest.issues.createComment({
113-
owner: context.repo.owner,
114-
repo: context.repo.repo,
115-
issue_number: +PR,
116-
body: `Hey @${REQUESTING_USER}, I've updated #${existing.number} for you.`,
117-
});
135+
commentBody = `I've updated #${existing.number} for you.`;
118136
}
119137
120-
- run: |
121-
MESSAGE="Hey @$REQUESTING_USER, I was unable to cherry-pick this PR."
122-
MESSAGE+=$'\n\n'
123-
MESSAGE+="Check the logs at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
138+
return commentBody;
124139
125-
gh pr comment "$PR" --repo ${{ github.repository }} --body "$MESSAGE"
126-
if: ${{ failure() }}
127-
env:
128-
PR: ${{ inputs.pr || github.event.client_payload.pr }}
129-
TARGET_BRANCH: ${{ inputs.target_branch || github.event.client_payload.target_branch }}
130-
REQUESTING_USER: ${{ inputs.requesting_user || github.event.client_payload.requesting_user }}
131-
GH_TOKEN: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
140+
- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
141+
if: ${{ !cancelled() && inputs.distinct_id }}
142+
with:
143+
success_comment: ${{ steps.open-pr.outputs.result }}
144+
failure_comment: 'I was unable to cherry-pick this PR.'
145+
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
146+
distinct_id: ${{ inputs.distinct_id }}
147+
source_issue: ${{ inputs.source_issue }}
148+
requesting_user: ${{ inputs.requesting_user }}
149+
status_comment: ${{ inputs.status_comment }}

.github/workflows/new-release-branch.yaml

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
name: New Release Branch
22

33
on:
4-
repository_dispatch:
5-
types: [new-release-branch]
4+
workflow_dispatch:
5+
inputs:
6+
branch_name:
7+
description: Release branch name to create
8+
required: true
9+
type: number
10+
package_version:
11+
description: Release package version
12+
required: true
13+
type: string
14+
core_major_minor:
15+
description: Release core major.minor version
16+
required: true
17+
type: string
18+
19+
# Inputs provided by the bot
20+
distinct_id:
21+
description: '(bot) A distinct ID'
22+
required: false
23+
default: ''
24+
source_issue:
25+
description: '(bot) The issue that triggered this workflow'
26+
required: false
27+
default: ''
28+
requesting_user:
29+
description: '(bot) The user who requested this workflow'
30+
required: false
31+
default: ''
32+
status_comment:
33+
description: '(bot) The comment to update with the status of this workflow'
34+
required: false
35+
default: ''
36+
37+
run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}
638

739
permissions:
840
contents: read
@@ -30,12 +62,12 @@ jobs:
3062
npm install -g $(jq -r '.packageManager' < package.json)
3163
npm --version
3264
- run: |
33-
git checkout -b ${{ github.event.client_payload.branch_name }}
34-
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
35-
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' src/compiler/corePublic.ts
36-
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
37-
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
38-
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ github.event.client_payload.package_version }}" as string;/g' src/compiler/corePublic.ts
65+
git checkout -b ${{ inputs.branch_name }}
66+
sed -i -e 's/"version": ".*"/"version": "${{ inputs.package_version }}"/g' package.json
67+
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' src/compiler/corePublic.ts
68+
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
69+
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
70+
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ inputs.package_version }}" as string;/g' src/compiler/corePublic.ts
3971
npm ci
4072
npm install # update package-lock.json to ensure the version bump is included
4173
npx hereby LKG
@@ -48,5 +80,16 @@ jobs:
4880
git add --force ./lib
4981
git config user.email "[email protected]"
5082
git config user.name "TypeScript Bot"
51-
git commit -m 'Bump version to ${{ github.event.client_payload.package_version }} and LKG'
52-
git push --set-upstream origin ${{ github.event.client_payload.branch_name }}
83+
git commit -m 'Bump version to ${{ inputs.package_version }} and LKG'
84+
git push --set-upstream origin ${{ inputs.branch_name }}
85+
86+
- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
87+
if: ${{ !cancelled() && inputs.distinct_id }}
88+
with:
89+
success_comment: "I've created ${{ inputs.branch_name }} with version ${{ inputs.package_version }} for you."
90+
failure_comment: 'I was unable to create the new release branch.'
91+
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
92+
distinct_id: ${{ inputs.distinct_id }}
93+
source_issue: ${{ inputs.source_issue }}
94+
requesting_user: ${{ inputs.requesting_user }}
95+
status_comment: ${{ inputs.status_comment }}

.github/workflows/nightly.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
- cron: '0 7 * * *'
66
# enable users to manually trigger with workflow_dispatch
77
workflow_dispatch: {}
8-
repository_dispatch:
9-
types: [publish-nightly]
108

119
permissions:
1210
contents: read

.github/workflows/set-version.yaml

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
name: Set branch version
22

33
on:
4-
repository_dispatch:
5-
types: [set-version]
4+
workflow_dispatch:
5+
inputs:
6+
branch_name:
7+
description: Release branch name to create
8+
required: true
9+
type: number
10+
package_version:
11+
description: Release package version
12+
required: true
13+
type: string
14+
core_major_minor:
15+
description: Release core major.minor version
16+
required: true
17+
type: string
18+
19+
# Inputs provided by the bot
20+
distinct_id:
21+
description: '(bot) A distinct ID'
22+
required: false
23+
default: ''
24+
source_issue:
25+
description: '(bot) The issue that triggered this workflow'
26+
required: false
27+
default: ''
28+
requesting_user:
29+
description: '(bot) The user who requested this workflow'
30+
required: false
31+
default: ''
32+
status_comment:
33+
description: '(bot) The comment to update with the status of this workflow'
34+
required: false
35+
default: ''
36+
37+
run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}
638

739
permissions:
840
contents: read
@@ -19,7 +51,7 @@ jobs:
1951
steps:
2052
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2153
with:
22-
ref: ${{ github.event.client_payload.branch_name }}
54+
ref: ${{ inputs.branch_name }}
2355
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
2456
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
2557
- run: |
@@ -35,11 +67,11 @@ jobs:
3567
# package_version - the full version string (eg, `3.9.1-rc` or `3.9.2`)
3668
# core_major_minor - the major.minor pair associated with the desired package_version (eg, `3.9` for `3.9.3`)
3769
- run: |
38-
sed -i -e 's/"version": ".*"/"version": "${{ github.event.client_payload.package_version }}"/g' package.json
39-
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' src/compiler/corePublic.ts
40-
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
41-
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ github.event.client_payload.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
42-
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ github.event.client_payload.package_version }}" as string;/g' src/compiler/corePublic.ts
70+
sed -i -e 's/"version": ".*"/"version": "${{ inputs.package_version }}"/g' package.json
71+
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' src/compiler/corePublic.ts
72+
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/typescript.d.ts
73+
sed -i -e 's/const versionMajorMinor = ".*"/const versionMajorMinor = "${{ inputs.core_major_minor }}"/g' tests/baselines/reference/api/tsserverlibrary.d.ts
74+
sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${{ inputs.package_version }}" as string;/g' src/compiler/corePublic.ts
4375
npm ci
4476
npm install # update package-lock.json to ensure the version bump is included
4577
npx hereby LKG
@@ -52,5 +84,16 @@ jobs:
5284
git add --force ./lib
5385
git config user.email "[email protected]"
5486
git config user.name "TypeScript Bot"
55-
git commit -m 'Bump version to ${{ github.event.client_payload.package_version }} and LKG'
87+
git commit -m 'Bump version to ${{ inputs.package_version }} and LKG'
5688
git push
89+
90+
- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
91+
if: ${{ !cancelled() && inputs.distinct_id }}
92+
with:
93+
success_comment: "I've set the version of ${{ inputs.branch_name }} to ${{ inputs.package_version }} for you."
94+
failure_comment: 'I was unable set the version.'
95+
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
96+
distinct_id: ${{ inputs.distinct_id }}
97+
source_issue: ${{ inputs.source_issue }}
98+
requesting_user: ${{ inputs.requesting_user }}
99+
status_comment: ${{ inputs.status_comment }}

.github/workflows/sync-branch.yaml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
name: Sync branch with master
22

33
on:
4-
repository_dispatch:
5-
types: [sync-branch]
64
workflow_dispatch:
75
inputs:
86
branch_name:
9-
description: 'Target Branch Name'
7+
description: Release branch name to create
108
required: true
9+
type: number
10+
11+
# Inputs provided by the bot
12+
distinct_id:
13+
description: '(bot) A distinct ID'
14+
required: false
15+
default: ''
16+
source_issue:
17+
description: '(bot) The issue that triggered this workflow'
18+
required: false
19+
default: ''
20+
requesting_user:
21+
description: '(bot) The user who requested this workflow'
22+
required: false
23+
default: ''
24+
status_comment:
25+
description: '(bot) The comment to update with the status of this workflow'
26+
required: false
27+
default: ''
28+
29+
run-name: ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}
1130

1231
permissions:
1332
contents: read
@@ -26,7 +45,7 @@ jobs:
2645
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
2746
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2847
with:
29-
ref: ${{ github.event.inputs.branch_name || github.event.client_payload.branch_name }}
48+
ref: ${{ inputs.branch_name }}
3049
filter: blob:none # https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/
3150
fetch-depth: 0 # Default is 1; need to set to 0 to get the benefits of blob:none.
3251
token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
@@ -42,3 +61,14 @@ jobs:
4261
git add --force ./lib
4362
git commit -m 'Update LKG'
4463
git push
64+
65+
- uses: microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
66+
if: ${{ !cancelled() && inputs.distinct_id }}
67+
with:
68+
success_comment: "I've pulled main into ${{ inputs.branch_name }} for you."
69+
failure_comment: 'I was unable merge main into ${{ inputs.branch_name }}.'
70+
github_token: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
71+
distinct_id: ${{ inputs.distinct_id }}
72+
source_issue: ${{ inputs.source_issue }}
73+
requesting_user: ${{ inputs.requesting_user }}
74+
status_comment: ${{ inputs.status_comment }}

0 commit comments

Comments
 (0)