Skip to content

Commit

Permalink
バージョン更新を自動化するスクリプトを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed May 6, 2024
1 parent dc208b2 commit e19c261
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/version_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: version update
on:
schedule:
# 毎日 09:00 JST
- cron: "0 0 * * *"
jobs:
build-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run versipn_update.sh
# 自身のファイルがチェックアウトによって消えると困るので
# コピーして消されないようにする
cp ./scripts/version_update.sh _version_update.sh
./_version_update.sh
12 changes: 7 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,11 +1252,12 @@ def version_update(args):
# },
# ...
# ]
version_path = os.path.join(BASE_DIR, "VERSION")
for m in milestones:
milestone = m["milestone"]
branch = m["webrtc_branch"]
if args.target == f"m{milestone}":
version_file = read_version_file("VERSION")
version_file = read_version_file(version_path)
rmilestone, rbranch, rposition, rbuild = version_file["WEBRTC_BUILD_VERSION"].split(".")

commit, position = get_webrtc_branch_info(branch)
Expand All @@ -1267,10 +1268,11 @@ def version_update(args):
else:
build = 0

print(f"WEBRTC_BUILD_VERSION={milestone}.{branch}.{position}.{build}")
print(f"WEBRTC_VERSION={milestone}.{branch}.{position}")
print(f"WEBRTC_READABLE_VERSION=M{milestone}.{branch}@{{#{position}}}")
print(f"WEBRTC_COMMIT={commit}")
with open(version_path, "w") as f:
f.write(f"WEBRTC_BUILD_VERSION={milestone}.{branch}.{position}.{build}\n")
f.write(f"WEBRTC_VERSION={milestone}.{branch}.{position}\n")
f.write(f"WEBRTC_READABLE_VERSION=M{milestone}.{branch}@{{#{position}}}\n")
f.write(f"WEBRTC_COMMIT={commit}\n")
return
else:
raise Exception(f"Could not find milestone {args.target}")
Expand Down
46 changes: 46 additions & 0 deletions scripts/version_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -ex

cd $(dirname $0)

# VERSION ファイルを適切なバージョンに更新するスクリプト
# GitHub Actions から実行されることを想定している

if [ "$GITHUB_ACTIONS" == "true" ]; then
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
fi

git checkout master
REMOTE=$(git remote)

# run.py に version_list や version_update が存在しないブランチにチェックアウトしてしまう可能性があるので、
# master ブランチの run.py の内容をコピーして利用する
cp run.py _run.py

LINES=$(python3 _run.py version_list | head -n 1)
while read -r milestone branch position commit; do
echo "${milestone} ${branch} ${position} ${commit}"
STATUS=$(git branch -a | grep -q "remotes/${REMOTE}/feature/${milestone}.${branch}"; echo $?)
if [ "$STATUS" == "0" ]; then
git checkout "feature/${milestone}.${branch}"
else
git checkout -b "feature/${milestone}.${branch}"
fi

source VERSION
python3 _run.py version_update ${milestone}
STATUS=$(git diff --exit-code --quiet VERSION; echo $?)
if [ "$STATUS" == "1" ]; then
git add VERSION
git commit -m "[update] Update version m$WEBRTC_VERSION to ${milestone}.${branch}.${position}"
fi
done <<< "$LINES"

# GitHub Actions から実行する場合は push までやる
if [ "$GITHUB_ACTIONS" == "true" ]; then
git push origin --all
fi

git checkout master

0 comments on commit e19c261

Please sign in to comment.