Skip to content

Commit 8d8ae41

Browse files
authored
Merge pull request #871 from massongit/rm_dev-hato
forkしたリポジトリでもうまく動作するようにする・リポジトリ名を変数から取得するようにする
2 parents e935da6 + e3e5378 commit 8d8ae41

10 files changed

Lines changed: 87 additions & 23 deletions

.github/workflows/pr-copy-ci-hato-bot.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ jobs:
1616
with:
1717
fetch-depth: 0
1818
path: hato-bot
19+
- name: Set org name
20+
uses: actions/github-script@v6
21+
id: set_org_name
22+
with:
23+
github-token: ${{secrets.GITHUB_TOKEN}}
24+
result-encoding: string
25+
script:
26+
return process.env.GITHUB_REPOSITORY.split('/')[0]
1927
- uses: actions/checkout@v3
2028
with:
2129
fetch-depth: 0
22-
repository: dev-hato/sudden-death
30+
repository: ${{steps.set_org_name.outputs.result}}/sudden-death
2331
path: sudden-death
2432
- name: Copy CI
2533
run: |
@@ -54,7 +62,7 @@ jobs:
5462
git commit -m "鳩は唐揚げ!(hato-botのCIを反映するよ!)"
5563
echo "${{secrets.SUDDEN_DEATH_CI_PRIVATE_KEY}}" > deploy_key.pem
5664
chmod 600 deploy_key.pem
57-
REPO_URL="git@github.com:dev-hato/sudden-death.git"
65+
REPO_URL="git@github.com:${{steps.set_org_name.outputs.result}}/sudden-death.git"
5866
GITHUB_HEAD="HEAD:refs/heads/pr-copy-ci"
5967
GIT_SSH_COMMAND="ssh"
6068
GIT_SSH_COMMAND+=" -i deploy_key.pem"

.github/workflows/pr-docker-hato-bot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
COMPOSE_DOCKER_CLI_BUILD: 1
1919
permissions:
2020
packages: write
21+
if: github.repository == github.event.pull_request.head.repo.full_name
2122
steps:
2223
- uses: actions/checkout@v3
2324
with:
@@ -40,11 +41,12 @@ jobs:
4041
if: ${{ github.event_name == 'pull_request' }}
4142
- run: echo 'TAG_NAME=${{ github.event.release.tag_name }}' >> "$GITHUB_ENV"
4243
if: ${{ github.event_name == 'release' }}
44+
- run: echo "REPOSITORY=${{github.repository}}" >> "${GITHUB_ENV}"
4345
- name: Build docker image
4446
run: docker-compose build --build-arg BUILDKIT_INLINE_CACHE=1
4547
- run: docker-compose push
4648
- run: |
47-
image_name="ghcr.io/dev-hato/hato-bot/hato-bot"
49+
image_name="ghcr.io/${{env.REPOSITORY}}/hato-bot"
4850
latest_tag="${image_name}:latest"
4951
docker tag "${image_name}:${TAG_NAME}" "${latest_tag}"
5052
docker push "${latest_tag}"

.github/workflows/pr-format.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ jobs:
9292
REPO_URL+="${{github.repository}}.git"
9393
GITHUB_HEAD="HEAD:refs/heads/fix-format-${HEAD_REF}"
9494
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
95+
- name: Set org name
96+
uses: actions/github-script@v6
97+
if: env.REPO_NAME == github.repository
98+
id: set_org_name
99+
with:
100+
github-token: ${{secrets.GITHUB_TOKEN}}
101+
result-encoding: string
102+
script:
103+
return process.env.GITHUB_REPOSITORY.split('/')[0]
95104
- name: Get PullRequests
96105
uses: actions/github-script@v6
97106
env:
@@ -107,7 +116,7 @@ jobs:
107116
const pulls_list_params = {
108117
owner: context.repo.owner,
109118
repo: context.repo.repo,
110-
head: "dev-hato:fix-format-" + HEAD_REF,
119+
head: "${{steps.set_org_name.outputs.result}}:fix-format-" + HEAD_REF,
111120
base: HEAD_REF,
112121
state: "open"
113122
}
@@ -135,7 +144,7 @@ jobs:
135144
const pulls_create_params = {
136145
owner: context.repo.owner,
137146
repo: context.repo.repo,
138-
head: "dev-hato:fix-format-" + HEAD_REF,
147+
head: "${{steps.set_org_name.outputs.result}}:fix-format-" + HEAD_REF,
139148
base: HEAD_REF,
140149
title,
141150
body: "鳩の唐揚げおいしい!😋😋😋 " + number
@@ -182,7 +191,7 @@ jobs:
182191
repo: context.repo.repo
183192
}
184193
const pulls_list_params = {
185-
head: "dev-hato:" + head_name,
194+
head: "${{steps.set_org_name.outputs.result}}:" + head_name,
186195
base: HEAD_REF,
187196
state: "open",
188197
...common_params

.github/workflows/pr-merge-develop-hato-bot.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ jobs:
1616
- uses: actions/checkout@v3
1717
with:
1818
fetch-depth: 0
19+
- name: Set org name
20+
uses: actions/github-script@v6
21+
id: set_org_name
22+
with:
23+
github-token: ${{secrets.GITHUB_TOKEN}}
24+
result-encoding: string
25+
script:
26+
return process.env.GITHUB_REPOSITORY.split('/')[0]
1927
- name: Get PullRequests
2028
uses: actions/github-script@v6
2129
id: get_pull_requests
@@ -25,7 +33,7 @@ jobs:
2533
const pulls_list_params = {
2634
owner: context.repo.owner,
2735
repo: context.repo.repo,
28-
head: "dev-hato:master",
36+
head: "${{steps.set_org_name.outputs.result}}:master",
2937
base: "develop",
3038
state: "open"
3139
}
@@ -44,7 +52,7 @@ jobs:
4452
repo: context.repo.repo
4553
}
4654
const pulls_create_params = {
47-
head: "dev-hato:master",
55+
head: "${{steps.set_org_name.outputs.result}}:master",
4856
base: "develop",
4957
title: "master -> develop",
5058
body: "鳩の歴史は同期される\ndevelopに新たなコミットがpushされる前にマージしてね!",

.github/workflows/pr-release-hato-bot.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
result="${result//$'\n'/'%0A'}"
2424
result="${result//$'\r'/'%0D'}"
2525
echo "::set-output name=result::${result}"
26+
- name: Set org name
27+
uses: actions/github-script@v6
28+
id: set_org_name
29+
with:
30+
github-token: ${{secrets.GITHUB_TOKEN}}
31+
result-encoding: string
32+
script:
33+
return process.env.GITHUB_REPOSITORY.split('/')[0]
2634
- name: Get PullRequests
2735
uses: actions/github-script@v6
2836
if: ${{ steps.get_diff.outputs.result != '' }}
@@ -33,7 +41,7 @@ jobs:
3341
const pulls_list_params = {
3442
owner: context.repo.owner,
3543
repo: context.repo.repo,
36-
head: "dev-hato:develop",
44+
head: "${{steps.set_org_name.outputs.result}}:develop",
3745
base: "master",
3846
state: "open"
3947
}
@@ -53,7 +61,7 @@ jobs:
5361
repo: context.repo.repo
5462
}
5563
const pulls_create_params = {
56-
head: "dev-hato:develop",
64+
head: "${{steps.set_org_name.outputs.result}}:develop",
5765
base: "master",
5866
title: "リリース",
5967
body: "鳩は唐揚げになるため、片栗粉へ飛び込む",

.github/workflows/pr-test-hato-bot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ jobs:
7777
- name: Set up Docker Buildx
7878
id: buildx
7979
uses: docker/setup-buildx-action@v1
80-
- run: echo "TAG_NAME=latest" >> "$GITHUB_ENV"
80+
- run: |
81+
echo "TAG_NAME=latest" >> "$GITHUB_ENV"
82+
echo "REPOSITORY=${{github.repository}}" >> "${GITHUB_ENV}"
8183
- name: Build docker image
8284
run: docker-compose build --build-arg BUILDKIT_INLINE_CACHE=1
8385
- name: Start docker

.github/workflows/pr-update-pre-commit-config-hato-bot.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ jobs:
7676
REPO_URL+="${{github.repository}}.git"
7777
GITHUB_HEAD="HEAD:refs/heads/fix-version-pre-commit-config-${HEAD_REF}"
7878
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
79+
- name: Set org name
80+
uses: actions/github-script@v6
81+
if: env.REPO_NAME == github.repository
82+
id: set_org_name
83+
with:
84+
github-token: ${{secrets.GITHUB_TOKEN}}
85+
result-encoding: string
86+
script:
87+
return process.env.GITHUB_REPOSITORY.split('/')[0]
7988
- name: Get PullRequests
8089
uses: actions/github-script@v6
8190
env:
@@ -90,7 +99,7 @@ jobs:
9099
const pulls_list_params = {
91100
owner: context.repo.owner,
92101
repo: context.repo.repo,
93-
head: "dev-hato:fix-version-pre-commit-config-" + HEAD_REF,
102+
head: "${{steps.set_org_name.outputs.result}}:fix-version-pre-commit-config-" + HEAD_REF,
94103
base: HEAD_REF,
95104
state: "open"
96105
}
@@ -117,7 +126,7 @@ jobs:
117126
const pulls_create_params = {
118127
owner: context.repo.owner,
119128
repo: context.repo.repo,
120-
head: "dev-hato:fix-version-pre-commit-config-" + HEAD_REF,
129+
head: "${{steps.set_org_name.outputs.result}}:fix-version-pre-commit-config-" + HEAD_REF,
121130
base: HEAD_REF,
122131
title,
123132
body: "鳩の唐揚げおいしい!😋😋😋 " + number
@@ -162,7 +171,7 @@ jobs:
162171
repo: context.repo.repo
163172
}
164173
const pulls_list_params = {
165-
head: "dev-hato:" + head_name,
174+
head: "${{steps.set_org_name.outputs.result}}:" + head_name,
166175
base: HEAD_REF,
167176
state: "open",
168177
...common_params

.github/workflows/update_python-hato-bot.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ jobs:
5757
REPO_URL+="${{github.repository}}.git"
5858
GITHUB_HEAD="HEAD:refs/heads/fix-version-${HEAD_REF}-python-version"
5959
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
60+
- name: Set org name
61+
uses: actions/github-script@v6
62+
if: env.REPO_NAME == github.repository
63+
id: set_org_name
64+
with:
65+
github-token: ${{secrets.GITHUB_TOKEN}}
66+
result-encoding: string
67+
script:
68+
return process.env.GITHUB_REPOSITORY.split('/')[0]
6069
- name: Get PullRequests
6170
uses: actions/github-script@v5
6271
env:
@@ -71,7 +80,7 @@ jobs:
7180
const pulls_list_params = {
7281
owner: context.repo.owner,
7382
repo: context.repo.repo,
74-
head: "dev-hato:fix-version-" + HEAD_REF + "-python-version",
83+
head: "${{steps.set_org_name.outputs.result}}:fix-version-" + HEAD_REF + "-python-version",
7584
base: HEAD_REF,
7685
state: "open"
7786
}
@@ -98,7 +107,7 @@ jobs:
98107
const pulls_create_params = {
99108
owner: context.repo.owner,
100109
repo: context.repo.repo,
101-
head: "dev-hato:fix-version-" + HEAD_REF + "-python-version",
110+
head: "${{steps.set_org_name.outputs.result}}:fix-version-" + HEAD_REF + "-python-version",
102111
base: HEAD_REF,
103112
title,
104113
body: "鳩の唐揚げおいしい!😋😋😋 " + number
@@ -143,7 +152,7 @@ jobs:
143152
repo: context.repo.repo
144153
}
145154
const pulls_list_params = {
146-
head: "dev-hato:" + head_name,
155+
head: "${{steps.set_org_name.outputs.result}}:" + head_name,
147156
base: HEAD_REF,
148157
state: "open",
149158
...common_params

.github/workflows/update_python.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ jobs:
4242
REPO_URL+="${{github.repository}}.git"
4343
GITHUB_HEAD="HEAD:refs/heads/fix-version-${HEAD_REF}-pipfile"
4444
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
45+
- name: Set org name
46+
uses: actions/github-script@v6
47+
if: env.REPO_NAME == github.repository
48+
id: set_org_name
49+
with:
50+
github-token: ${{secrets.GITHUB_TOKEN}}
51+
result-encoding: string
52+
script:
53+
return process.env.GITHUB_REPOSITORY.split('/')[0]
4554
- name: Get PullRequests
4655
uses: actions/github-script@v5
4756
env:
@@ -56,7 +65,7 @@ jobs:
5665
const pulls_list_params = {
5766
owner: context.repo.owner,
5867
repo: context.repo.repo,
59-
head: "dev-hato:fix-version-" + HEAD_REF + '-pipfile',
68+
head: "${{steps.set_org_name.outputs.result}}:fix-version-" + HEAD_REF + '-pipfile',
6069
base: HEAD_REF,
6170
state: "open"
6271
}
@@ -83,7 +92,7 @@ jobs:
8392
const pulls_create_params = {
8493
owner: context.repo.owner,
8594
repo: context.repo.repo,
86-
head: "dev-hato:fix-version-" + HEAD_REF + '-pipfile',
95+
head: "${{steps.set_org_name.outputs.result}}:fix-version-" + HEAD_REF + '-pipfile',
8796
base: HEAD_REF,
8897
title,
8998
body: "鳩の唐揚げおいしい!😋😋😋 " + number
@@ -128,7 +137,7 @@ jobs:
128137
repo: context.repo.repo
129138
}
130139
const pulls_list_params = {
131-
head: "dev-hato:" + head_name,
140+
head: "${{steps.set_org_name.outputs.result}}:" + head_name,
132141
base: HEAD_REF,
133142
state: "open",
134143
...common_params

setup/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ services:
1919
dockerfile: ./Dockerfile
2020
context: ../
2121
cache_from:
22-
- ghcr.io/dev-hato/hato-bot/hato-bot:${TAG_NAME}
23-
- ghcr.io/dev-hato/hato-bot/hato-bot
24-
image: ghcr.io/dev-hato/hato-bot/hato-bot:${TAG_NAME}
22+
- ghcr.io/${REPOSITORY:-dev-hato/hato-bot}/hato-bot:${TAG_NAME}
23+
- ghcr.io/${REPOSITORY:-dev-hato/hato-bot}/hato-bot
24+
image: ghcr.io/${REPOSITORY:-dev-hato/hato-bot}/hato-bot:${TAG_NAME}
2525
platform: linux/amd64
2626
env_file:
2727
- ../.env

0 commit comments

Comments
 (0)