Skip to content

Check Master Branch #789

Check Master Branch

Check Master Branch #789

Workflow file for this run

name: Check Master Branch
on:
schedule:
- cron: '0 03-23/6 * * *'
workflow_dispatch:
env:
ORIGINAL_REPO: "phoepsilonix/mozc"
jobs:
sync-master:
runs-on: ubuntu-latest
outputs:
mozc_commit: ${{ steps.sync_mozc.outputs.mozc_commit }}
steps:
- name: Checkout
uses: actions/checkout@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "Masato TOYOSHIMA"
git config user.email [email protected]
git config --global push.gpgSign if-asked
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.PRIVATE_REPO_SSH_KEY }}
- name: Import bot's GPG key for signing commits
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }}
- name: Mozc commit check
id: sync_mozc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Fetch api of head commits from original repository..."
MOZC_COMMIT=$(curl -s https://api.github.com/repos/$ORIGINAL_REPO/commits/master|jq -r ".sha")
DEB_COMMIT=$(cat last_commit.txt)
echo $MOZC_COMMIT
echo $DEB_COMMIT
if [[ "$MOZC_COMMIT" == "$DEB_COMMIT" ]]; then
echo "No changes detected. Exiting."
echo "should_exit=true" >> $GITHUB_OUTPUT
exit 0
fi
- name: Mozc Version Check
id: check_mozc
if: ${{ steps.sync_mozc.outputs.should_exit != 'true' }}
run: |
echo "Changes detected."
echo
echo "Fetching from original repository..."
git fetch --filter=tree:0 https://github.com/$ORIGINAL_REPO.git master
MOZC_COMMIT=$(git log -1 --pretty=%H FETCH_HEAD)
DEB_COMMIT=$(cat last_commit.txt)
echo $MOZC_COMMIT
echo $DEB_COMMIT
echo $MOZC_COMMIT > last_commit.txt
git commit -m "last commit is $MOZC_COMMIT" last_commit.txt
echo "mozc_commit=$MOZC_COMMIT" >> $GITHUB_OUTPUT
# MOZC_VERSION CHECK
echo "Mozc version(tag) check"
MOZC_TAG_1="v""$(head -n1 debian/changelog|grep -Eo "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*")"
echo "Resetting local master to FETCH_HEAD..."
git checkout FETCH_HEAD
source <(grep = src/data/version/mozc_version_template.bzl| tr -d ' ')
MOZC_TAG_2=$(printf "v%s.%s.%s.%s" "$MAJOR" "$MINOR" "$BUILD_OSS" "$((REVISION+2))")
echo "$MOZC_TAG_1"
echo "$MOZC_TAG_2"
if [[ "$MOZC_TAG_1" != "$MOZC_TAG_2" ]];then
OSS_COMMIT=$(git log -G "BUILD_OSS [^ ]* $BUILD_OSS" -1 --pretty=%H)
[[ -z "$OSS_COMMIT" ]] && OSS_COMMIT=$(git log -G "$BUILD_OSS" -1 --pretty=%H)
if [[ -z "$OSS_COMMIT" ]]; then
echo "is BUILD_OSS updated? But COMMIT LOG is Nothing?"
OSS_COMMIT=$(git log -1 --pretty=%H)
fi
git checkout main
git checkout -- changelog
sed "s/MOZC_VER/${MOZC_TAG_2#v*}/" changelog > changelog.tmp1
UPDATE_DATE=$(TZ="Asia/Tokyo" LC_ALL=C date -R)
sed "s/UPDATE_DATE/${UPDATE_DATE}/" -i changelog.tmp1
cat changelog.tmp1 debian/changelog > changelog.tmp
mv changelog.tmp debian/changelog
rm -f changelog.tmp1
#git checkout -- changelog
git commit -m "chagelog: $MOZC_TAG_2 at $UPDATE_DATE" debian/changelog
fi
echo "Pushing changes to origin..."
git checkout main
echo "Fcitx5 patches updated."
git clone --filter=tree:0 --no-single-branch https://github.com/fcitx/mozc.git fcitx-mozc
cd fcitx-mozc
git diff origin/master..origin/fcitx --text --binary -- ':!scripts/icons/*' ':!.github/*' ':!.*' > ../debian/patches/0001-Support-fcitx.patch
git diff origin/master..origin/fcitx --text --binary -- 'scripts/icons/*' > ../debian/patches/0002-fcitx5-icon.patch
cd ..
git commit -m "Updated: Fcitx5-Mozc patches" -- debian/patches/ ||true
git push origin main --force
TAG=commit-$MOZC_COMMIT
git tag $TAG
git push origin $TAG --force
echo "mozc_tag=$TAG" >> $GITHUB_OUTPUT
if [[ "$MOZC_TAG_1" != "$MOZC_TAG_2" ]];then
echo $MOZC_TAG_2
echo $OSS_COMMIT
git tag $MOZC_TAG_2 HEAD ||true
git push origin $MOZC_TAG_2 --force||true
fi
- name: Trigger release workflow
if: ${{ steps.sync_mozc.outputs.should_exit != 'true' }}
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
event-type: new-tag-created
client-payload: |-
{
"repo": {
"name": "${{ github.repository }}",
"branch": "main",
"tag": "${{ steps.check_mozc.outputs.mozc_tag }}"
}
}
repository: ${{ github.repository }}