Skip to content

Commit

Permalink
core(workflows): プルリクエストに対し build を実行し "site/pull/番号" 以下にアップロード
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 11, 2025
1 parent 58047c4 commit 53c4183
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 65 deletions.
57 changes: 3 additions & 54 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Register SSH key
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
# site_generator
- uses: actions/checkout@v4
with:
repository: cpprefjp/site_generator
path: site_generator
- run: git submodule update -i
working-directory: site_generator

# kunai
- uses: actions/checkout@v4
with:
repository: cpprefjp/kunai
path: site_generator/kunai
- run: git submodule update -i
working-directory: site_generator/kunai

# cpprefjp.github.io
- uses: actions/checkout@v4
with:
repository: cpprefjp/cpprefjp.github.io
path: site_generator/cpprefjp/cpprefjp.github.io

# site
- uses: actions/checkout@v4
with:
repository: cpprefjp/site
path: site_generator/cpprefjp/site
# atom 生成のために全履歴が必要
fetch-depth: 0
- run: git submodule update -i
working-directory: site_generator/cpprefjp/site

# site
- uses: actions/checkout@v2
- name: cpprefjp-build
uses: ./.github/cpprefjp-build
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エラーがでた

# あとはスクリプトで頑張る
- run: ./cpprefjp/site/.github/workflows/script/build.sh
working-directory: site_generator
arguments:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ jobs:
path: ${{ env.REPO_DIR }}
- name: check
run: "! $BIN_DIR/rg -t md --vimgrep '[\u00ad\u200b]' $REPO_DIR"

build:
if: github.repository_owner == 'cpprefjp' && github.event_name == 'pull_request'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-pull-${{ github.event.number }}
cancel-in-progress: true
steps:
- name: cpprefjp-build
uses: ./.github/cpprefjp-build
with:
arguments: --pull ${{ github.event.number }}
61 changes: 61 additions & 0 deletions .github/workflows/cpprefjp-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: cpprefjp-build
description: "cpprefjp サイトをビルドするためのアクション"

runs:
using: composite
steps:
- name: Register SSH key
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
# site_generator
- uses: actions/checkout@v4
with:
repository: cpprefjp/site_generator
path: site_generator
- run: git submodule update -i
working-directory: site_generator

# kunai
- uses: actions/checkout@v4
with:
repository: cpprefjp/kunai
path: site_generator/kunai
- run: git submodule update -i
working-directory: site_generator/kunai

# cpprefjp.github.io
- uses: actions/checkout@v4
with:
repository: cpprefjp/cpprefjp.github.io
path: site_generator/cpprefjp/cpprefjp.github.io

# site
- uses: actions/checkout@v4
with:
repository: cpprefjp/site
path: site_generator/cpprefjp/site
# atom 生成のために全履歴が必要
fetch-depth: 0
- run: git submodule update -i
working-directory: site_generator/cpprefjp/site

# site
- uses: actions/checkout@v2
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エラーがでた

# あとはスクリプトで頑張る
- run: ./cpprefjp/site/.github/workflows/script/build.sh ${{ inputs.arguments }}
working-directory: site_generator
51 changes: 40 additions & 11 deletions .github/workflows/script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,43 @@ popd
pip3 install -r docker/requirements.txt
python3 run.py settings.cpprefjp --concurrency=`nproc`

# 生成されたサイトの中身を push
pushd cpprefjp/cpprefjp.github.io
# push するために ssh のリモートを追加する
git remote add origin2 [email protected]:cpprefjp/cpprefjp.github.io.git

git add ./ --all
git config --global user.email "[email protected]"
git config --global user.name "cpprefjp-autoupdate"
git commit -a -m "update automatically"
git push origin2 master
popd
if (($# == 0)); then
# 生成されたサイトの中身を push
pushd cpprefjp/cpprefjp.github.io
# push するために ssh のリモートを追加する
git remote add origin2 [email protected]:cpprefjp/cpprefjp.github.io.git

git add ./ --all
git config --global user.email "[email protected]"
git config --global user.name "cpprefjp-autoupdate"
git commit -a -m "update automatically"
git push origin2 master
popd

elif [[ $1 == --pull ]]; then
if [[ $2 ]]; then
printf '%s\n' "プルリクエスト番号が指定されていません" >&2
exit 2
fi

[email protected]:cpprefjp/site.git
working_directory=cpprefjp/cpprefjp.github.io-site

git remote add origin2 "$target_repository"
git clone --depth=1 [email protected]:cpprefjp/site.git -b gh-pages "$working_directory"
rm -rf "$working_directory/pull/$2"
mkdir -p "$working_directory/pull/$2"
cp -r cpprefjp/cpprefjp.github.io/* "$working_directory/pull/$2"/
pushd "$working_directory"
git add ./ --all
git config --global user.email "[email protected]"
git config --global user.name "cpprefjp-autoupdate"
git commit -a -m "update automatically"
git push origin2 gh-pages
popd

else
printf '%s\n' "コマンドライン引数が認識できません: $1" >&2
exit 2

fi

0 comments on commit 53c4183

Please sign in to comment.