@@ -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
0 commit comments