Skip to content

Auto cherry-pick Keiyoushi #968

Auto cherry-pick Keiyoushi

Auto cherry-pick Keiyoushi #968

name: Auto cherry-pick Keiyoushi
on:
schedule:
- cron: "0 0 * * *"
- cron: "0 6 * * *"
- cron: "0 12 * * *"
- cron: "0 18 * * *"
workflow_dispatch: # Manual dispatch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
auto-merge:
name: Auto cherry-pick Keiyoushi
if: github.repository == 'komikku-repo/komikku-extensions'
runs-on: ubuntu-latest
steps:
- name: Clone master
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
ref: master
path: master
fetch-depth: 100
token: ${{ secrets.BOT_PAT }}
- name: Cherry-picking
run: |
cd master
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git fetch origin keiyoushi
git checkout keiyoushi
echo "Last commit: `git log -1 --oneline`"
git remote add keiyoushi-upstream https://github.com/keiyoushi/extensions-source
git fetch keiyoushi-upstream
echo "Last commit: `git log -1 --oneline keiyoushi-upstream/main`"
echo "Incoming commits:"
echo "`git log keiyoushi..keiyoushi-upstream/main --oneline`"
upcoming_changes=`git log keiyoushi..keiyoushi-upstream/main --pretty="%h"`
# Read the upcoming changes' hash into an array
upcoming_changes_hash=()
while read -r line; do
upcoming_changes_hash+=("$line")
done <<< "$upcoming_changes"
git checkout master
echo "Last commit: `git log -1 --oneline`"
# Loop through indices in reverse order
for (( i=${#upcoming_changes_hash[@]}; i>=0; i-- )); do
if [ ! -z "${upcoming_changes_hash[i]}" -a "${upcoming_changes_hash[i]}" != " " ]; then
echo "[$i]: Cherry picking '${upcoming_changes_hash[i]}'"
git cherry-pick --allow-empty "${upcoming_changes_hash[i]}"
latest_hash=${upcoming_changes_hash[i]}
else
echo "[$i]: skip '${upcoming_changes_hash[i]}'"
fi
done
echo "Last commit: `git log -1 --oneline`"
echo "LATEST_HASH=${latest_hash}" >> $GITHUB_ENV
- name: Merging keiyoushi-upstream to keiyoushi
run: |
cd master
git checkout keiyoushi
echo "Last commit: `git log -1 --oneline`"
latest_commit_hash=${{ env.LATEST_HASH }}
if [ ! -z "$latest_commit_hash" -a "$latest_commit_hash" != " " ]; then
echo "Merging commit '$latest_commit_hash' from 'keiyoushi-upstream' into keiyoushi"
git merge "$latest_commit_hash" --no-ff -m "Merge branch 'keiyoushi-upstream' into keiyoushi"
fi
echo "Last commit: `git log -1 --oneline`"
# - name: Merging master to merge-keiyoushi
# run: |
# cd master
# git fetch origin merge-keiyoushi
# git checkout merge-keiyoushi
# echo "Last commit: `git log -1 --oneline`"
# echo "Merging 'master' into merge-keiyoushi"
# git merge --no-edit master
# echo "Last commit: `git log -1 --oneline`"
# - name: Merging keiyoushi-upstream to merge-keiyoushi
# run: |
# cd master
# echo "Merging 'keiyoushi-upstream/main' into merge-keiyoushi"
# git merge --no-edit keiyoushi-upstream/main
# echo "Last commit: `git log -1 --oneline`"
- name: Pushing to repo
run: |
cd master
git checkout master
echo "Last commit: `git log -1 --oneline`"
echo "Pushing 'master' to repo"
git push
git checkout keiyoushi
echo "Last commit: `git log -1 --oneline`"
echo "Pushing 'keiyoushi' to repo"
git push
# git checkout merge-keiyoushi
# echo "Last commit: `git log -1 --oneline`"
# echo "Pushing 'merge-keiyoushi' to repo"
# git push