Skip to content

Commit 012fb27

Browse files
authored
Merge pull request #25 from Goryudyuma/master
update
2 parents 34ed47a + 0785017 commit 012fb27

File tree

4 files changed

+113
-121
lines changed

4 files changed

+113
-121
lines changed

.github/workflows/on-created.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ name: On Created
22
on:
33
push:
44
branches:
5-
- master
5+
- master
66
jobs:
77
on-created:
88
name: on-created
99
runs-on: ubuntu-latest
1010
if: ${{ github.repository != 'dbgofy/isucon-boilerplate' }}
1111
steps:
12-
- uses: actions/checkout@v1
13-
- name: config git
14-
run: |
15-
git config user.name $GITHUB_ACTOR
16-
git config user.email $GITHUB_ACTOR@users.noreply.github.com
17-
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
18-
git checkout master
19-
- name: replace
20-
run: |
21-
sed -i "s/ isucon-boilerplate/ ${GITHUB_REPOSITORY#*/}/" README.md
22-
sed -i "s!\\\$GITHUB_REPOSITORY!${GITHUB_REPOSITORY}!" README.md
23-
sed -i 's/create a new repository/~\0~ already done/' README.md
24-
- name: commit
25-
run: git commit -am 'Replace $GITHUB_REPOSITORY'
26-
- name: delete this script
27-
run: |
28-
rm -f .github/workflows/on-created.yml
29-
git commit -am 'Delete on-created workflow'
30-
- name: push
31-
run: git push -f origin master
12+
- uses: actions/checkout@v4
13+
- name: config git
14+
run: |
15+
git config user.name $GITHUB_ACTOR
16+
git config user.email $GITHUB_ACTOR@users.noreply.github.com
17+
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
18+
git checkout master
19+
- name: replace
20+
run: |
21+
sed -i "s/ isucon-boilerplate/ ${GITHUB_REPOSITORY#*/}/" README.md
22+
sed -i "s!\\\$GITHUB_REPOSITORY!${GITHUB_REPOSITORY}!" README.md
23+
sed -i 's/^\- \[ \] Create a new repository/- [x] Create a new repository/' README.md
24+
- name: commit
25+
run: git commit -am 'Replace $GITHUB_REPOSITORY'
26+
- name: delete this script
27+
run: |
28+
rm -f .github/workflows/on-created.yml
29+
git commit -am 'Delete on-created workflow'
30+
- name: push
31+
run: git push -f origin master
3232
env:
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/update-hosts.yml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,48 @@ on:
33
workflow_dispatch:
44
push:
55
branches:
6-
- master
6+
- master
77
paths:
8-
- files/hosts/*
8+
- files/hosts/*
99
jobs:
1010
update-hosts:
1111
name: update-hosts
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v1
15-
- name: generate config for prometheus
16-
run: |
17-
jq -sR '
18-
[
19-
.
20-
| split("\n")[]
21-
| split(" ")
22-
| select(length == 2)
23-
| {
24-
targets: [
25-
"\(.[1]):9100",
26-
"\(.[1]):9256"
27-
],
28-
labels: {
29-
hostname: .[0],
30-
ip: .[1]
14+
- uses: actions/checkout@v4
15+
- name: generate config for prometheus
16+
run: |
17+
jq -sR '
18+
[
19+
.
20+
| split("\n")[]
21+
| split(" ")
22+
| select(length == 2)
23+
| {
24+
targets: [
25+
"\(.[1]):9100",
26+
"\(.[1]):9256"
27+
],
28+
labels: {
29+
hostname: .[0],
30+
ip: .[1]
31+
}
3132
}
32-
}
33-
]
34-
' files/hosts/* > etc/prometheus/hosts.json
35-
- name: config git
36-
run: |
37-
git config user.name $GITHUB_ACTOR
38-
git config user.email $GITHUB_ACTOR@users.noreply.github.com
39-
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
40-
git checkout master
41-
- name: git commit
42-
run: |
43-
git add -f etc/prometheus/hosts.json
44-
git commit -m 'Update config for prometheus'
45-
- name: git push
46-
run: |
47-
git pull origin master
48-
git push origin master
33+
]
34+
' files/hosts/* > etc/prometheus/hosts.json
35+
- name: config git
36+
run: |
37+
git config user.name $GITHUB_ACTOR
38+
git config user.email $GITHUB_ACTOR@users.noreply.github.com
39+
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
40+
git checkout master
41+
- name: git commit
42+
run: |
43+
git add -f etc/prometheus/hosts.json
44+
git commit -m 'Update config for prometheus'
45+
- name: git push
46+
run: |
47+
git pull origin master
48+
git push origin master
4949
env:
5050
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/update-sshkeys.yml

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,63 @@ on:
33
workflow_dispatch:
44
push:
55
branches:
6-
- master
6+
- master
77
paths:
8-
- files/pubkey/*
8+
- files/pubkey/*
99
jobs:
1010
update-sshkeys:
1111
name: update-sshkeys
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v1
15-
- name: ensure ssh directory
16-
run: mkdir -p root/.ssh
17-
- name: replace ssh keys
18-
uses: actions/github-script@v3
19-
with:
20-
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")
55-
);
56-
- name: add host keys
57-
run: cat files/pubkey/* >> root/.ssh/authorized_keys || true
58-
- name: config git
59-
run: |
60-
git config user.name $GITHUB_ACTOR
61-
git config user.email $GITHUB_ACTOR@users.noreply.github.com
62-
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
63-
git checkout master
64-
- name: git commit
65-
run: |
66-
git add -f root/.ssh/authorized_keys
67-
git commit -m 'Update ssh keys'
68-
- name: git push
69-
run: |
70-
git pull origin master
71-
git push origin master
14+
- uses: actions/checkout@v4
15+
- name: ensure ssh directory
16+
run: mkdir -p root/.ssh
17+
- name: replace ssh keys
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
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+
})
40+
);
41+
fs.writeFileSync('root/.ssh/authorized_keys', keys.flat().join('\n') + '\n');
42+
- name: add host keys
43+
run: cat files/pubkey/* >> root/.ssh/authorized_keys || true
44+
- name: config git
45+
run: |
46+
git config user.name $GITHUB_ACTOR
47+
git config user.email $GITHUB_ACTOR@users.noreply.github.com
48+
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
49+
git checkout master
50+
- name: git commit
51+
run: |
52+
git add -f root/.ssh/authorized_keys
53+
git commit -m 'Update ssh keys'
54+
- name: replace
55+
run: |
56+
if grep -qE '^- \[ \] Invite your team members from' README.md; then
57+
sed -i 's/^- \[ \] Invite your team members from/- [x] Invite your team members from/' README.md
58+
git commit -am 'Replace "Invite your team members from"'
59+
fi
60+
- name: git push
61+
run: |
62+
git pull origin master
63+
git push origin master
7264
env:
7365
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
**create a new repository**
1010

11-
Create a new repository from https://github.com/bgpat/isucon-boilerplate/generate.
11+
- [ ] Create a new repository from https://github.com/dbgofy/isucon-boilerplate/generate.
1212

1313
**add members**
1414

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

1818
#### in each competition server
1919

@@ -58,6 +58,6 @@ vim /etc/nginx/nginx.conf
5858
### track source files by git
5959

6060
```bash
61+
cd /home/isucon
6162
git add -f *.go
6263
```
63-

0 commit comments

Comments
 (0)