This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
Add host #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update SSH Keys | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
paths: | |
- files/pubkey/* | |
jobs: | |
update-sshkeys: | |
name: update-sshkeys | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
- name: ensure ssh directory | |
run: mkdir -p root/.ssh | |
- name: replace ssh keys | |
uses: actions/github-script@v3 | |
with: | |
script: | | |
require("fs").writeFileSync( | |
"root/.ssh/authorized_keys", | |
[ | |
...(await Promise.all( | |
await github.repos.listCollaborators(context.repo).then((resp) => | |
resp.data.map((c) => | |
github.users | |
.getByUsername({ username: c.login }) | |
.then((resp) => ({ | |
...c, | |
email: resp.data.email || `${c.login}@users.noreply.github.com`, | |
})) | |
.then((user) => | |
github.users | |
.listPublicKeysForUser({ username: user.login }) | |
.then((resp) => | |
resp.data.map(({ key }) => | |
[ | |
Object.entries({ | |
GIT_AUTHOR_NAME: user.login, | |
GIT_AUTHOR_EMAIL: user.email, | |
}) | |
.map(([k, v]) => `environment="${k}=${v}"`) | |
.join(","), | |
key, | |
].join(" ") | |
) | |
) | |
) | |
) | |
) | |
).then((users) => [].concat(...users))), | |
"", | |
].join("\n") | |
); | |
- name: add host keys | |
run: cat files/pubkey/* >> root/.ssh/authorized_keys || true | |
- name: config git | |
run: | | |
git config user.name $GITHUB_ACTOR | |
git config user.email $GITHUB_ACTOR@users.noreply.github.com | |
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
git checkout master | |
- name: git commit | |
run: | | |
git add -f root/.ssh/authorized_keys | |
git commit -m 'Update ssh keys' | |
- name: git push | |
run: | | |
git pull origin master | |
git push origin master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |