-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (123 loc) · 5.1 KB
/
check-branch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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}/" changelog > changelog.tmp1
UPDATE_DATE=$(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
git tag $MOZC_TAG_2 $OSS_COMMIT
git push origin $MOZC_TAG_2 --force
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 }}