Skip to content

Commit 9b5d893

Browse files
committed
add port for github action
1 parent 5f867a4 commit 9b5d893

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

.github/workflows/example.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ jobs:
2222
- name: Use the output
2323
run: |
2424
echo "The host is ${{ steps.wait-for-branch.outputs.host }}"
25+
echo "The port is ${{ steps.wait-for-branch.outputs.port }}"
2526
echo "The username is ${{ steps.wait-for-branch.outputs.username }}"
2627
echo "The password is ${{ steps.wait-for-branch.outputs.password }}"
2728
outputs:
2829
username: ${{ steps.wait-for-branch.outputs.username }}
2930
host: ${{ steps.wait-for-branch.outputs.host }}
3031
password: ${{ steps.wait-for-branch.outputs.password }}
32+
port: ${{ steps.wait-for-branch.outputs.port }}
3133

3234
test:
3335
needs: setup
@@ -36,5 +38,6 @@ jobs:
3638
- name: Use the output
3739
run: |
3840
echo "The host is ${{ needs.setup.outputs.host }}"
39-
echo "The username is ${{ needs.setup.outputs.username }}"
40-
echo "The password is ${{ needs.setup.outputs.password }}"
41+
echo "The port is ${{ needs.setup.outputs.port }}"
42+
echo '::add-mask::${{ needs.setup.outputs.password }}'
43+
echo "The password is ${{ needs.setup.outputs.password }}"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The action provide the following outputs:
3232
- host - The host of the TiDB Cloud branch.
3333
- username - The username of the TiDB Cloud branch.
3434
- password - The password of the TiDB Cloud branch.
35+
- port - The port of the TiDB Cloud branch.
3536

3637
## Best practices
3738

@@ -52,6 +53,7 @@ steps:
5253
- name: Use the output
5354
run: |
5455
echo "The host is ${{ steps.wait-for-branch.outputs.host }}"
56+
echo "The port is ${{ steps.wait-for-branch.outputs.port }}"
5557
echo "The username is ${{ steps.wait-for-branch.outputs.username }}"
5658
echo "The password is ${{ steps.wait-for-branch.outputs.password }}"
5759
```
@@ -76,6 +78,7 @@ jobs:
7678
addMask: false
7779
outputs:
7880
username: ${{ steps.wait-for-branch.outputs.username }}
81+
port : ${{ steps.wait-for-branch.outputs.port }}
7982
host: ${{ steps.wait-for-branch.outputs.host }}
8083
password: ${{ steps.wait-for-branch.outputs.password }}
8184
@@ -86,6 +89,7 @@ jobs:
8689
- name: Use the output
8790
run: |
8891
echo "The host is ${{ needs.setup.outputs.host }}"
92+
echo "The port is ${{ needs.setup.outputs.port }}"
8993
echo "The username is ${{ needs.setup.outputs.username }}"
9094
echo '::add-mask::${{ needs.setup.outputs.password }}'
9195
echo "The password is ${{ needs.setup.outputs.password }}"

dist/index.js

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async function run(): Promise<void> {
6262
core.setOutput('host', sqlUser.host)
6363
core.setOutput('username', sqlUser.username)
6464
core.setOutput('password', sqlUser.password)
65+
core.setOutput('port', sqlUser.port)
6566
} catch (error) {
6667
if (error instanceof Error) core.setFailed(error.message)
6768
}

src/sqluser.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ export class SqlUser {
1111
host: string
1212
username: string
1313
password: string
14+
port: number
1415

15-
constructor(host: string, user: string, password: string) {
16+
constructor(host: string, port: number, user: string, password: string) {
1617
this.host = host
1718
this.username = user
1819
this.password = password
20+
this.port = port
1921
}
2022
}
2123

@@ -49,16 +51,34 @@ export async function sqluser(
4951
host = 'https://api.staging.tidbcloud.com'
5052
}
5153

52-
const url = `${host}/api/internal/projects/${projectID}/clusters/${clusterID}/branches/${branchName}/users`
53-
log(`request url to get sql user: ${url}`)
54-
5554
const client = new DigestFetch(publicKey, privateKey)
56-
const resp = await client.fetch(url, {method: 'POST'})
55+
56+
// get sql user
57+
const sqlUserUrl = `${host}/api/internal/projects/${projectID}/clusters/${clusterID}/branches/${branchName}/users`
58+
log(`request url to get sql user: ${sqlUserUrl}`)
59+
const resp = await client.fetch(sqlUserUrl, {method: 'POST'})
5760
const data = await resp.json()
5861
if (data['username'] === undefined || data['password'] === undefined) {
5962
throw new Error(
6063
`Can not get sql user with response: ${JSON.stringify(data)}`
6164
)
6265
}
63-
return new SqlUser('', data['username'], data['password'])
66+
67+
// get branch info
68+
const branchUrl = `${host}/api/internal/projects/${projectID}/clusters/${clusterID}/branches/${branchName}`
69+
log(`request url to get host and port: ${branchUrl}`)
70+
const resp2 = await client.fetch(branchUrl)
71+
const branch = await resp2.json()
72+
if (branch['host'] === undefined || branch['port'] === undefined) {
73+
throw new Error(
74+
`Can not get branch host and port with: ${JSON.stringify(branch)}`
75+
)
76+
}
77+
78+
return new SqlUser(
79+
branch['host'],
80+
branch['port'],
81+
data['username'],
82+
data['password']
83+
)
6484
}

0 commit comments

Comments
 (0)