-
Notifications
You must be signed in to change notification settings - Fork 176
169 lines (152 loc) · 6.17 KB
/
build.yml
File metadata and controls
169 lines (152 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: build
on:
workflow_dispatch:
workflow_call:
inputs:
arguments:
description: "build.sh に渡すコマンドライン引数"
default: ''
required: false
type: string
push:
branches:
- master
schedule:
# UTC 表記
# 日本時間 23:30
- cron: "30 14 * * *"
jobs:
build:
if: github.repository_owner == 'cpprefjp' || startsWith(inputs.arguments, '--pull ')
runs-on: ubuntu-latest
steps:
- id: vars
run: |
echo "base_repo=${{ startsWith(inputs.arguments, '--pull ') && github.event.pull_request.base.repo.full_name || github.event.repository.full_name }}" >> "$GITHUB_OUTPUT"
echo "head_repo=${{ startsWith(inputs.arguments, '--pull ') && github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}" >> "$GITHUB_OUTPUT"
echo "head_ref=${{ startsWith(inputs.arguments, '--pull ') && github.event.pull_request.head.ref || github.ref }}" >> "$GITHUB_OUTPUT"
# site_generator
- name: Check out cpprefjp/site_generator
uses: actions/checkout@v4
with:
repository: cpprefjp/site_generator
path: site_generator
- run: git submodule update --init
working-directory: site_generator
# kunai
- name: Check out cpprefjp/kunai
uses: actions/checkout@v4
with:
repository: cpprefjp/kunai
path: site_generator/kunai
- run: git submodule update --init
working-directory: site_generator/kunai
# site (typically cpprefjp/site)
- name: Check out ${{ steps.vars.outputs.head_repo }}
uses: actions/checkout@v4
with:
repository: ${{ steps.vars.outputs.head_repo }}
# atom 生成のために全履歴が必要
fetch-depth: 0
ref: ${{ steps.vars.outputs.head_ref }}
path: site_generator/cpprefjp/site
- run: git submodule update --init
working-directory: site_generator/cpprefjp/site
# image
- name: Check out cpprefjp/image
uses: actions/checkout@v4
with:
repository: cpprefjp/image
path: site_generator/cpprefjp/image
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
python-version: 3.11
# 3.12でUndefined symbolエラーがでた
# build.sh - base の build.sh を使う必要がある。もし PR head の
# build.sh を使うと、pull_request_target で呼び出された時に PR
# head の build.sh に悪意のあるコードが埋め込まれていると秘密鍵な
# ど盗まれてしまう。
- name: Check out build.sh
uses: actions/checkout@v4
with:
repository: ${{ steps.vars.outputs.base_repo }}
ref: master
sparse-checkout: .github
path: .trusted
# Deploy 用
- name: "(Deploy) Register SSH key"
if: inputs.arguments == ''
env:
CPPREFJP_GITHUB_IO_SECRETS: ${{ secrets.CPPREFJP_GITHUB_IO_SECRETS }}
run: |
mkdir -p $HOME/.ssh
echo "$CPPREFJP_GITHUB_IO_SECRETS" > $HOME/.ssh/id_ed25519
chmod 600 $HOME/.ssh/id_ed25519
# Deploy 用
- name: "(Deploy) Check out cpprefjp.github.io"
if: inputs.arguments == ''
uses: actions/checkout@v4
with:
repository: cpprefjp/cpprefjp.github.io
path: site_generator/cpprefjp/cpprefjp.github.io
# Preview 用
- name: "(Preview build) Check out gh-pages"
if: startsWith(inputs.arguments, '--pull ')
continue-on-error: true
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.base.repo.full_name }}
ref: gh-pages
path: site_generator/cpprefjp/gh-pages
- name: "(Preview build) Collect GitHub context"
id: preview_vars
if: startsWith(inputs.arguments, '--pull ')
uses: actions/github-script@v7
with:
script: |
const sha0 = context.payload.pull_request.base.sha;
const sha = context.payload.pull_request.head.sha;
const base_url = (() => {
const owner = context.payload.pull_request.base.repo.owner.login;
const repo = context.payload.pull_request.base.repo.name;
const pull = context.payload.number;
return `https://${owner}.github.io/${repo}/gen/pull/${pull}`;
})();
const repo_full = context.payload.pull_request.base.repo.full_name;
const branch = context.payload.pull_request.head.ref;
core.setOutput('sha0', sha0);
core.setOutput('sha', sha);
core.setOutput('base_url', base_url);
core.setOutput('repo_full', repo_full);
core.setOutput('ubranch', encodeURIComponent(branch));
# あとはスクリプトで頑張る
- name: Run script build.sh
run: ../.trusted/.github/workflows/script/build.sh ${{ inputs.arguments }}
env:
base_git_url: ${{ github.event.pull_request.base.repo.clone_url }}
base_git_ref: ${{ github.event.pull_request.base.ref }}
commit_base: ${{ steps.preview_vars.outputs.sha0 }}
commit_head: ${{ steps.preview_vars.outputs.sha }}
preview_base_url: ${{ steps.preview_vars.outputs.base_url }}
preview_repo_url: https://github.com/${{ steps.preview_vars.outputs.repo_full }}
preview_ubranch: ${{ steps.preview_vars.outputs.ubranch }}
working-directory: site_generator
# Preview 用
- name: "(Preview build) Publish result in gh-pages"
if: startsWith(inputs.arguments, '--pull ')
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site_generator/cpprefjp/gh-pages
user_name: 'github-actions[bot]'
user_email: '41898282+github-actions[bot]@users.noreply.github.com'
# Note: 以下のコミットメッセージは .github/workflows/preview_clear.yml
# で削除対象のコミットの特定に用いるので、変更する場合は preview_clear
# も一緒に更新すること。
commit_message: |
Preview PR ${{ github.event.number }}: ${{ github.event.pull_request.head.sha }} ←
enable_jekyll: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true