Skip to content

build

build #4495

Workflow file for this run

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
# 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