-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: submodule が最新ではなかったら弾く ci を導入 (#108)
* ci: submodule が最新かどうかをチェックするスクリプトを用意 * chore: submodule が最新かどうかをチェックするスクリプトを make タスクに登録 * ci: submodule が最新かチェックする仕組みを ci に組み込む
- Loading branch information
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# github-comment の comment template | ||
# | ||
# リポジトリ: https://github.com/suzuki-shunsuke/github-comment | ||
# ドキュメント: https://suzuki-shunsuke.github.io/github-comment/ | ||
# | ||
# 概要 | ||
# - PR の GitHub Action で利用を想定 | ||
# - 失敗時に PR にコメントを残す | ||
# - 古いコメントを hide する | ||
# | ||
# 利用例 | ||
# | ||
# ``` | ||
# $ github-comment exec --config .github/github-comment.yaml -k default -- make xxxx | ||
# ``` | ||
# | ||
--- | ||
exec: | ||
default: | ||
- when: ExitCode != 0 | ||
template: | | ||
{{template "status" .}} {{template "link" .}} | ||
exit code: {{.ExitCode}} | ||
実行されたコマンド | ||
``` | ||
$ {{.Command}} | ||
``` | ||
<details> | ||
出力 | ||
<pre><code> | ||
{{.CombinedOutput | AvoidHTMLEscape}} | ||
</code></pre> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
|
||
name: Check for submodule updates | ||
|
||
# | ||
# 'on' にしている理由 | ||
# yamllintで怒られるため | ||
# | ||
# 参考: https://github.com/adrienverge/yamllint/issues/430 | ||
# | ||
'on': | ||
pull_request: | ||
|
||
jobs: | ||
check-for-submodule-updates: | ||
# | ||
# PR 元が renovate 起因の場合、 job skip | ||
# (renovate 起因の場合、ブランチ名は renovate/**) | ||
# | ||
if: ${{ !startsWith(github.head_ref, 'renovate/') }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: リポジトリのチェックアウト | ||
uses: actions/checkout@v3 | ||
- name: github-commentをインストール | ||
run: | | ||
curl -sSfL -o github-comment.tar.gz "https://github.com/suzuki-shunsuke/github-comment/releases/download/v${GITHUB_COMMENT_VERSION}/github-comment_${GITHUB_COMMENT_VERSION}_linux_amd64.tar.gz" | ||
echo 1da8cb9d52395018ec15f876347e204fe632c833baa1831ca36302dec1e0f97a github-comment.tar.gz | sha256sum -c | ||
sudo tar -C /usr/bin -xzf ./github-comment.tar.gz | ||
env: | ||
GITHUB_COMMENT_VERSION: 5.0.0 | ||
- name: github-comment のバージョン確認 | ||
run: github-comment -v | ||
- name: 古いコメントを削除 | ||
run: github-comment hide -condition 'Comment.Body contains "make git.check-for-submodule-updates"' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: submoduleが最新かどうかチェック | ||
run: github-comment exec --config .github/github-comment.yaml -- make git.check-for-submodule-updates | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
################################################################################ | ||
# Check for submodule updates | ||
################################################################################ | ||
# | ||
# 概要 | ||
# - submodule に更新があるかチェック | ||
# | ||
# exit code: 0 : 更新はない ( 最新状態である ) | ||
# exit code: 1 : 更新がある | ||
# | ||
|
||
GIT_SUBMODULE="akiyadego-openapi" | ||
readonly GIT_SUBMODULE | ||
|
||
# | ||
# submodule での作業内容を退避 | ||
# | ||
function stash_on_git_submodule() { | ||
cd "${GIT_SUBMODULE}" || exit 1 | ||
git stage . | ||
git stash -q -m "$(date +%Y-%m-%dT%H:%M:%S) : check-for-submodule-updates によって stash しました" > /dev/null | ||
cd - || exit 1 | ||
} | ||
|
||
# | ||
# 更新があるか確認 | ||
# | ||
function exist_diff_from_the_latest() { | ||
git submodule update --init --recursive --remote -- "${GIT_SUBMODULE}" > /dev/null | ||
git status --short ${GIT_SUBMODULE} | wc -l | grep -q 0 | ||
} | ||
|
||
# | ||
# Main | ||
# | ||
function main() { | ||
stash_on_git_submodule | ||
if exist_diff_from_the_latest; then | ||
echo "" | ||
echo "👍 Nothing submodule updates: ${GIT_SUBMODULE} submodule is latest." | ||
echo "" | ||
# 現在の branch の submodule の状態に戻す | ||
git submodule update -- "${GIT_SUBMODULE}" > /dev/null | ||
exit 0 | ||
else | ||
echo "" | ||
echo "🧐 Found submodule updates: ${GIT_SUBMODULE} submodule is up to date." >&2 | ||
echo "" | ||
# 現在の branch の submodule の状態に戻す | ||
git submodule update -- "${GIT_SUBMODULE}" > /dev/null | ||
exit 1 | ||
fi | ||
} | ||
|
||
main |