Skip to content

Commit c6649ec

Browse files
committed
[ci skip] update script
1 parent 9efd423 commit c6649ec

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

.github/workflows/update-sshkeys.yml

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,27 @@ jobs:
1818
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
1919
with:
2020
script: |
21-
require("fs").writeFileSync(
22-
"root/.ssh/authorized_keys",
23-
[
24-
...(await Promise.all(
25-
await github.repos.listCollaborators(context.repo).then((resp) =>
26-
resp.data.map((c) =>
27-
github.users
28-
.getByUsername({ username: c.login })
29-
.then((resp) => ({
30-
...c,
31-
email: resp.data.email || `${c.login}@users.noreply.github.com`,
32-
}))
33-
.then((user) =>
34-
github.users
35-
.listPublicKeysForUser({ username: user.login })
36-
.then((resp) =>
37-
resp.data.map(({ key }) =>
38-
[
39-
Object.entries({
40-
GIT_AUTHOR_NAME: user.login,
41-
GIT_AUTHOR_EMAIL: user.email,
42-
})
43-
.map(([k, v]) => `environment="${k}=${v}"`)
44-
.join(","),
45-
key,
46-
].join(" ")
47-
)
48-
)
49-
)
50-
)
51-
)
52-
).then((users) => [].concat(...users))),
53-
"",
54-
].join("\n")
21+
const fs = require('fs');
22+
const collaborators = await github.rest.repos.listCollaborators({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
});
26+
const keys = await Promise.all(
27+
collaborators.data.map(async (collaborator) => {
28+
const user = await github.rest.users.getByUsername({
29+
username: collaborator.login,
30+
});
31+
const email = user.data.email || `${collaborator.login}@users.noreply.github.com`;
32+
const publicKeys = await github.rest.users.listPublicKeysForUser({
33+
username: collaborator.login,
34+
});
35+
return publicKeys.data.map(({ key }) => {
36+
const env = `environment="GIT_AUTHOR_NAME=${collaborator.login},GIT_AUTHOR_EMAIL=${email}"`;
37+
return `${env} ${key}`;
38+
});
39+
})
5540
);
41+
fs.writeFileSync('root/.ssh/authorized_keys', keys.flat().join('\n') + '\n');
5642
- name: add host keys
5743
run: cat files/pubkey/* >> root/.ssh/authorized_keys || true
5844
- name: config git

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
**add members**
1414

1515
- [ ] Invite your team members from https://github.com/$GITHUB_REPOSITORY/settings/access.
16-
- Run [Update SSH Keys](https://github.com/$GITHUB_REPOSITORY/actions?query=workflow%3A%22Update+SSH+Keys%22).
16+
- Run [Update SSH Keys](https://github.com/$GITHUB_REPOSITORY/actions/workflows/update-sshkeys.yml).
1717

1818
#### in each competition server
1919

0 commit comments

Comments
 (0)