ci: Add automatic dependency update

This commit is contained in:
Nicolas Werner 2020-11-18 13:54:04 +00:00 committed by Sorunome
parent 01cc650454
commit ed8f0f9b53
3 changed files with 79 additions and 2 deletions

View File

@ -144,3 +144,41 @@ pages:
# - /opt/ort/bin/ort analyze -i $CI_PROJECT_DIR -o $CI_PROJECT_DIR/ --allow-dynamic-versions
# - /opt/ort/bin/ort scan -i $CI_PROJECT_DIR/analyzer-result.yml -o $CI_PROJECT_DIR/ || true
# - /opt/ort/bin/ort report -f GitLabLicenseModel -i $CI_PROJECT_DIR/scan-result.yml -o $CI_PROJECT_DIR/
update-dependencies:
stage: coverage
image: debian:testing
needs: []
tags:
- docker
only:
- schedules
variables:
HOST: ${CI_PROJECT_URL}
UPDATE_BRANCH: ci-bot/dependency-updates
PRIVATE_TOKEN: ${GITLAB_API_TOKEN}
before_script:
- apt-get update && apt-get install -y curl git gnupg2 openssh-client python3
- curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list
- apt-get update && apt-get install -y dart
- ln -s /usr/lib/dart/bin/pub /usr/bin/
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_BOT_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "info@famedly.com"
- git config --global user.name "Famedly Bot"
script:
- pub get
- pub run dapackages:dapackages.dart ./pubspec.yaml
- 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)'

View File

@ -15,7 +15,7 @@ dependencies:
html_unescape: ^1.0.1+3
moor: ^3.0.2
random_string: ^2.0.1
encrypt: ^4.0.2
encrypt: 4.0.2
crypto: ^2.1.4
base58check: ^1.0.1
password_hash: ^2.0.0
@ -29,6 +29,8 @@ dev_dependencies:
test_coverage: ^0.4.3
moor_generator: ^3.0.0
build_runner: ^1.5.2
pedantic: ^1.9.0
pedantic: ^1.9.2
dapackages: ^1.4.0
#flutter_test:
# sdk: flutter

37
scripts/open-mr.sh Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# source: https://about.gitlab.com/blog/2017/09/05/how-to-automatically-create-a-new-mr-on-gitlab-with-gitlab-ci/
# Extract the host where the server is running, and add the URL to the APIs
[[ $HOST =~ ^https?://[^/]+ ]] && HOST="${BASH_REMATCH[0]}/api/v4/projects/"
# Look which is the default branch
TARGET_BRANCH=`curl --silent "${HOST}${CI_PROJECT_ID}" --header "PRIVATE-TOKEN:${PRIVATE_TOKEN}" | python3 -c "import sys, json; print(json.load(sys.stdin)['default_branch'])"`;
# The description of our new MR, we want to remove the branch after the MR has
# been closed
BODY="{
\"id\": ${CI_PROJECT_ID},
\"source_branch\": \"${UPDATE_BRANCH}\",
\"target_branch\": \"${TARGET_BRANCH}\",
\"remove_source_branch\": true,
\"title\": \"chore: automated dependency update\"
}";
# Require a list of all the merge request and take a look if there is already
# one with the same source branch
LISTMR=`curl --silent "${HOST}${CI_PROJECT_ID}/merge_requests?state=opened" --header "PRIVATE-TOKEN:${PRIVATE_TOKEN}"`;
COUNTBRANCHES=`echo ${LISTMR} | grep -o "\"source_branch\":\"${UPDATE_BRANCH}\"" | wc -l`;
# No MR found, let's create a new one
if [ ${COUNTBRANCHES} -eq "0" ]; then
curl -X POST "${HOST}${CI_PROJECT_ID}/merge_requests" \
--header "PRIVATE-TOKEN:${PRIVATE_TOKEN}" \
--header "Content-Type: application/json" \
--data "${BODY}";
echo "Opened a new dependency update MR."
exit;
fi
echo "No new merge request opened.";