Skip to content

Commit 534d2e5

Browse files
committed
chore(workflows/preview_clear): 古いプレビューを削除するワークフローを追加
gh-pages に対して filter-branch を実行して force push します。
1 parent 82dd7b3 commit 534d2e5

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ jobs:
123123
with:
124124
github_token: ${{ secrets.GITHUB_TOKEN }}
125125
publish_dir: ./site_generator/cpprefjp/gh-pages
126+
127+
# Note: 以下のコミットメッセージは .github/workflows/preview_clear.yml
128+
# で削除対象のコミットの特定に用いるので、変更する場合は preview_clear
129+
# も一緒に更新すること。
126130
commit_message: |
127131
Preview PR ${{ github.event.number }}: ${{ github.event.pull_request.head.sha }} ←
128132
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: preview_clear
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
preview_clear:
7+
concurrency:
8+
group: cpprefjp.gh-pages.lock
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
ref: gh-pages
14+
fetch-depth: 0
15+
- name: filter-branch gh-pages
16+
env:
17+
GH_TOKEN: ${{ github.token }}
18+
run: |
19+
set -ex
20+
21+
# Note: 以下の 999 という数は適当な大きな数。もし open PR の数が 999
22+
# を超えるようならば、この数はもっと大きくする必要がある。
23+
PREVIEW_CLEAR_PR_LIST=$(gh pr list --limit=999 --json number -q '.[].number' | tr '\n' ' ')
24+
PREVIEW_CLEAR_PR_LIST=${PREVIEW_CLEAR_PR_LIST% }
25+
export PREVIEW_CLEAR_PR_LIST
26+
27+
git config --global user.name 'github-actions[bot]'
28+
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
29+
git filter-branch --commit-filter '
30+
pr=$(git log -n 1 --pretty=format:%s "$GIT_COMMIT" | sed -n '\''s/^Preview PR \([0-9]\{1,\}\).*/\1/p'\'')
31+
case " $PREVIEW_CLEAR_PR_LIST | " in
32+
(*" $pr "*)
33+
git commit-tree "$@" ;;
34+
(*)
35+
skip_commit "$@" ;;
36+
esac
37+
' HEAD
38+
39+
git push -f origin gh-pages

0 commit comments

Comments
 (0)