@@ -2,6 +2,13 @@ name: build
2
2
3
3
on :
4
4
workflow_dispatch :
5
+ workflow_call :
6
+ inputs :
7
+ arguments :
8
+ description : " build.sh に渡すコマンドライン引数"
9
+ default : ' '
10
+ required : false
11
+ type : string
5
12
push :
6
13
branches :
7
14
- master
@@ -14,13 +21,11 @@ jobs:
14
21
build :
15
22
runs-on : ubuntu-latest
16
23
steps :
17
- - name : Register SSH key
18
- env :
19
- CPPREFJP_GITHUB_IO_SECRETS : ${{ secrets.CPPREFJP_GITHUB_IO_SECRETS }}
24
+ - id : vars
20
25
run : |
21
- mkdir -p $HOME/.ssh
22
- echo "$CPPREFJP_GITHUB_IO_SECRETS " > $HOME/.ssh/id_ed25519
23
- chmod 600 $HOME/.ssh/id_ed25519
26
+ echo "base_repo=${{ startsWith(inputs.arguments, '--pull ') && github.event.pull_request.base.repo.full_name || github.event.repository.full_name }}" >> "$GITHUB_OUTPUT"
27
+ echo "head_repo=${{ startsWith(inputs.arguments, '--pull ') && github.event.pull_request.head.repo.full_name || github.event.repository.full_name }} " >> "$GITHUB_OUTPUT"
28
+ echo "head_ref=${{ startsWith(inputs.arguments, '--pull ') && github.event.pull_request.head.ref || github.ref }}" >> "$GITHUB_OUTPUT"
24
29
25
30
# site_generator
26
31
- uses : actions/checkout@v4
@@ -38,19 +43,14 @@ jobs:
38
43
- run : git submodule update -i
39
44
working-directory : site_generator/kunai
40
45
41
- # cpprefjp.github.io
42
- - uses : actions/checkout@v4
43
- with :
44
- repository : cpprefjp/cpprefjp.github.io
45
- path : site_generator/cpprefjp/cpprefjp.github.io
46
-
47
46
# site
48
47
- uses : actions/checkout@v4
49
48
with :
50
- repository : cpprefjp/site
51
- path : site_generator/cpprefjp/site
49
+ repository : ${{ steps.vars.outputs.head_repo }}
52
50
# atom 生成のために全履歴が必要
53
51
fetch-depth : 0
52
+ ref : ${{ steps.vars.outputs.head_ref }}
53
+ path : site_generator/cpprefjp/site
54
54
- run : git submodule update -i
55
55
working-directory : site_generator/cpprefjp/site
56
56
@@ -66,10 +66,61 @@ jobs:
66
66
python-version : 3.11
67
67
# 3.12でUndefined symbolエラーがでた
68
68
69
+ # build.sh - base の build.sh を使う必要がある。もし PR head の
70
+ # build.sh を使うと、pull_request_target で呼び出された時に PR
71
+ # head の build.sh に悪意のあるコードが埋め込まれていると秘密鍵な
72
+ # ど盗まれてしまう。
73
+ - name : Check out build.sh
74
+ uses : actions/checkout@v4
75
+ with :
76
+ repository : ${{ steps.vars.outputs.base_repo }}
77
+ ref : master
78
+ sparse-checkout : .github
79
+ path : .trusted
80
+
81
+ # Deploy 用
82
+ - name : " (Deploy) Register SSH key"
83
+ if : inputs.arguments == ''
84
+ env :
85
+ CPPREFJP_GITHUB_IO_SECRETS : ${{ secrets.CPPREFJP_GITHUB_IO_SECRETS }}
86
+ run : |
87
+ mkdir -p $HOME/.ssh
88
+ echo "$CPPREFJP_GITHUB_IO_SECRETS" > $HOME/.ssh/id_ed25519
89
+ chmod 600 $HOME/.ssh/id_ed25519
90
+
91
+ # Deploy 用
92
+ - name : " (Deploy) Check out cpprefjp.github.io"
93
+ if : inputs.arguments == ''
94
+ uses : actions/checkout@v4
95
+ with :
96
+ repository : cpprefjp/cpprefjp.github.io
97
+ path : site_generator/cpprefjp/cpprefjp.github.io
98
+
99
+ # Preview 用
100
+ - name : " (Preview build) Check out gh-pages"
101
+ if : startsWith(inputs.arguments, '--pull ')
102
+ continue-on-error : true
103
+ uses : actions/checkout@v4
104
+ with :
105
+ repository : ${{ github.event.pull_request.base.repo.full_name }}
106
+ ref : gh-pages
107
+ path : site_generator/cpprefjp/gh-pages
108
+
69
109
# あとはスクリプトで頑張る
70
- - run : ./cpprefjp/site/.github/workflows/script/build.sh
110
+ - name : Run script build.sh
111
+ run : ../.trusted/.github/workflows/script/build.sh ${{ inputs.arguments }}
71
112
working-directory : site_generator
72
113
114
+ # Preview 用
115
+ - name : " (Preview build) Publish result in gh-pages"
116
+ if : startsWith(inputs.arguments, '--pull ')
117
+ uses : peaceiris/actions-gh-pages@v4
118
+ with :
119
+ github_token : ${{ secrets.GITHUB_TOKEN }}
120
+ publish_dir : ./site_generator/cpprefjp/gh-pages
121
+ commit_message : |
122
+ Preview PR ${{ github.event.number }}: ${{ github.event.pull_request.head.sha }} <=
123
+
73
124
concurrency :
74
125
group : ${{ github.workflow }}-${{ github.ref }}
75
126
cancel-in-progress : true
0 commit comments