Skip to content

Commit

Permalink
feat: скрипт обновления base, который дополнительно обновляет конфиг …
Browse files Browse the repository at this point in the history
…renovate
  • Loading branch information
mxseev committed Nov 24, 2022
1 parent e6270e8 commit 6f8ea29
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/base-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Checkout new commits in base repository and check updates
id: base_check
run: |
Expand All @@ -28,6 +32,10 @@ jobs:
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
# tell git about current user
git config --global user.email ${{ github.actor }}@users.noreply.github.com
git config --global user.name ${{ github.actor }}
# fetch base repository changes
git fetch base main:chore/base-update
Expand All @@ -38,8 +46,13 @@ jobs:
export UNMERGED_COMMITS_LIST=$(git --no-pager log HEAD..chore/base-update --pretty=format:"- %h: %s")
echo ::set-output name=unmerged_commits_list::${UNMERGED_COMMITS_LIST//$'\n'/'%0A'}
# remove the main branch and use the branch from the base repository instead
# checkout to base branch and update renovate config
git checkout chore/base-update
# update renovate.json file
sh ./scripts/update_base.sh update_renovate
# remove the main branch and use the branch from the base repository instead
git branch -D main
git branch -m main
fi
Expand Down
6 changes: 1 addition & 5 deletions docs/guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,4 @@

В репозитории уже настроен Github Action, который раз в сутки (или по требованию) будет проверять состояние репозитория на актуальность base и автоматически создавать PR с обновлением.

Чтобы обновить base вручную, нужно:
1. Запустить команду для проверки: `pnpm run lint:base`
2. Произвести merge изменений: `git merge base/main`

Если при merge произошли конфликты, исправить их и закомитить. При большом количестве конфликтов в файле `pnpm-lock.yaml` можно просто запустить `pnpm install`, который автоматически их исправит.
Чтобы обновить base вручную, нужно запустить скрипт обновления base: `npm run base:update` (для проверки необходимости обновления есть команда `npm run base:check`). Если во время обновления произошли конфликты, исправить их и закомитить. При большом количестве конфликтов в файле `pnpm-lock.yaml` можно просто запустить `pnpm install`, который автоматически их исправит.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"license": "MIT",
"author": "Max Eliseev <mxseev@gmail.com>",
"scripts": {
"base:check": "sh ./scripts/check_base_update.sh",
"base:update": "sh ./scripts/update_base.sh",
"build": "tsc",
"commit": "git add . && cz",
"preinstall": "npx only-allow pnpm",
"postinstall": "sh ./scripts/add_base_remote.sh",
"lint": "concurrently -c green \"pnpm:lint:*\"",
"lint:base": "sh ./scripts/check_base_update.sh",
"lint:ts": "eslint --ext .ts,.tsx .",
"lint:typecheck": "tsc --noEmit --project tsconfig.json",
"start": "ts-node src/index.ts",
Expand Down
46 changes: 46 additions & 0 deletions scripts/update_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
set -e

# updates RenovateBot config, adding base dependencies to ignore
function update_renovate_config {
# read package.json from base
BASE_PACKAGE_JSON=$(git show base/main:package.json)

# get dependencies/devDependencies from there
BASE_DEPENDENCIES=$(echo $BASE_PACKAGE_JSON | jq -r -M "[.dependencies | keys[]] + [.devDependencies | keys[]]")

# put them into .ignoreDeps Renovate config
UDPATED_RENOVATE_FILE=$(cat renovate.json | jq -r --argjson deps "$BASE_DEPENDENCIES" ". + {ignoreDeps: \$deps}" )

echo "$UDPATED_RENOVATE_FILE" >| renovate.json
npx prettier -w renovate.json
}

function update_renovate {
# get actual base
git fetch base

# check repo status, exit if it dirty
if [[ $(git diff --stat) != '' ]]; then
echo "error: repository is dirty, commit your changes before updating base"
exit 42
fi

update_renovate_config

# commit renovate.json changes (if any)
git add renovate.json
git commit --no-verify -m "chore: update ignored deps in RenovateBot" || true
}

function main {
update_renovate

git merge base/main
}

# start main function by default
if [ -z "$@" ]; then
main
else
"$@"
fi

0 comments on commit 6f8ea29

Please sign in to comment.