auto merge upstream #58
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
name: auto merge upstream | |
on: | |
workflow_dispatch: # allows manual triggering | |
schedule: | |
- cron: "0 17 * * 5" # runs weekly on Saturday at 02:00 (JST) | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
auto-merge-upstream: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: andstor/file-existence-action@v3 | |
id: check_lockfile | |
with: | |
files: "lazy-lock.json" | |
- name: Merge upstream | |
id: merge-upstream | |
continue-on-error: true | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git remote add upstream https://github.com/ayamir/nvimdots.git | |
git fetch upstream | |
remote_update=$(git merge upstream/main --allow-unrelated-histories --no-commit --no-ff) | |
echo "remote_update=${remote_update}" >> $GITHUB_OUTPUT | |
- name: Fix conflict | |
id: fix-conflict | |
if: steps.merge-upstream.outputs.remote_update != 'Already up to date.' | |
run: | | |
git reset HEAD lazy-lock.json | |
git checkout lazy-lock.json | |
git commit --no-edit | |
- uses: rhysd/action-setup-vim@v1 | |
if: steps.check_lockfile.outputs.files_exists == 'true' | |
with: | |
neovim: true | |
- name: Run lockfile-autoupdate | |
if: steps.check_lockfile.outputs.files_exists == 'true' | |
timeout-minutes: 5 | |
run: | | |
# obsidianのプラグインを強制的に読み込ませる | |
mkdir -p ${HOME}/Documents/memopad | |
NVIMDIR=${HOME}/.config/nvim | |
mkdir -p ${NVIMDIR} | |
cp -r ./lua ${NVIMDIR}/lua | |
cp init.lua ${NVIMDIR}/init.lua | |
nvim --headless "+Lazy! update" +qa | |
cp -pv "${NVIMDIR}/lazy-lock.json" lazy-lock.new.json | |
curl -L https://raw.githubusercontent.com/ayamir/nvimdots/main/lazy-lock.json -o lazy-lock.upstream.json | |
# refer to the upstream lazy-lock.json and merge common plugins with priority given to the upstream version. | |
jq -s '.[0] as $x | .[1] as $y | $x | to_entries | map(.key as $k | if ($y | has($k)) then {($k): $y[$k]} else {($k): .value} end) | add' lazy-lock.new.json lazy-lock.upstream.json > lazy-lock.json | |
rm lazy-lock.upstream.json lazy-lock.new.json | |
- uses: stefanzweifel/git-auto-commit-action@v5 | |
if: steps.check_lockfile.outputs.files_exists == 'true' || contains(fromJSON('["success", "skipped"]'), steps.fix-conflict.outcome) | |
with: | |
file_pattern: "lazy-lock.json" | |
commit_message: "chore: auto merge upstream and update lazy-lock.json" | |
commit_user_name: "github-actions[bot]" | |
commit_user_email: "41898282+github-actions[bot]@users.noreply.github.com" | |
commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" |