ci: Add automatic dependency update

This needs 2 special variables defined:

- GITLAB_API_TOKEN, which has write permissions to the gitlab API
  (create in your account settings for example)
- SSH_BOT_KEY, which is a private ssh key, that can be used to push to
  the repository.

After that you can schedule a pipeline on main to update dependencies
every week or so.
This commit is contained in:
Nicolas Werner 2020-10-29 18:29:44 +01:00
commit 66852f1b44
2 changed files with 69 additions and 0 deletions

View file

@ -235,3 +235,35 @@ snap:publish:
when: on_success
expire_in: 1 week
needs: []
update-dependencies:
stage: coverage
needs: []
tags:
- docker
only:
- schedules
variables:
HOST: ${CI_PROJECT_URL}
UPDATE_BRANCH: ci-bot/dependency-updates
PRIVATE_TOKEN: ${GITLAB_API_TOKEN}
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_BOT_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan "https://gitlab.com" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "bot@fluffy.chat"
- git config --global user.name "Dependency Update Bot"
- sudo apt-get update && sudo apt-get install -y curl
script:
- flutter pub get
- flutter pub pub run dapackages:dapackages.dart ./pubspec.yaml
- flutter pub get
- git remote set-url --push origin git@gitlab.com:$CI_PROJECT_PATH
- 'git diff --exit-code || (git checkout -B ${UPDATE_BRANCH} && git add . && git commit -m "chore: Update dependencies" && git push -f origin ${UPDATE_BRANCH} && ./scripts/open-mr.sh)'