-
Notifications
You must be signed in to change notification settings - Fork 160
139 lines (123 loc) · 4.68 KB
/
build.yml
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
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 -i
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 -i
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 -i
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: Run script build.sh
run: ../.trusted/.github/workflows/script/build.sh ${{ inputs.arguments }}
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