mirror of https://github.com/jacekkow/keycloak-protocol-cas

Matthias Piepkorn
2018-12-19 c140cef674a426fba60d2b5439591ad982edd0ad
commit | author | age
9532f1 1 #!/bin/bash
MP 2 set -e
3
4 function docker_tag_exists() {
5     TOKEN=$(curl --silent -f "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$1:pull" | sed 's/.*"token":"\([^"]*\)".*/\1/')
6     REGISTRY_URL="https://registry-1.docker.io/v2/$1/manifests/$2"
7     curl -fsSLI -H "Authorization: Bearer $TOKEN" "$REGISTRY_URL" > /dev/null
8 }
9
10 setup_git() {
11     git config --global user.email "updater@travis-ci.org"
12     git config --global user.name "Updater Bot"
13     git remote add origin-auth https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git > /dev/null 2>&1
14 }
15
16 pull_request() {
17     curl -fsSL -H "Authorization: token ${GH_TOKEN}" -X POST -d "{\"head\":\"$1\",\"base\":\"master\",\"title\":\"$2\",\"body\":\"$3\"}" "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/pulls"
18 }
19
20
21 KEYCLOAK_VERSION=$(mvn versions:display-property-updates -DincludeProperties=keycloak.version | grep "keycloak.version" | sed -n "s/.*->\s*\(.*\)\.Final$/\1/p")
22 KEYCLOAK_VERSION_FULL=$KEYCLOAK_VERSION.Final
23 if [ -z "$KEYCLOAK_VERSION" ]; then
24     echo "No Keycloak update found."
25     exit
26 fi
27 echo "Keycloak version $KEYCLOAK_VERSION available; updating..."
28
29 BRANCH=feature/keycloak-update-$KEYCLOAK_VERSION
30 if git ls-remote -q --exit-code origin $BRANCH; then
31     echo "Branch $BRANCH already exists."
32     exit
33 fi
34
35 if ! docker_tag_exists jboss/keycloak $KEYCLOAK_VERSION_FULL; then
36     echo "Docker image for Keycloak $KEYCLOAK_VERSION_FULL not found, not updating."
37     exit
38 fi
39 echo "Found updated docker image, proceeding"
40
41 mvn versions:set -DnewVersion=$KEYCLOAK_VERSION -DgenerateBackupPoms=false
42 sed -i "s/KEYCLOAK_VERSION=.*/KEYCLOAK_VERSION=$KEYCLOAK_VERSION_FULL/" .travis.yml
43
44 setup_git
45 git checkout -b $BRANCH
46 git add pom.xml .travis.yml
47 git commit -m "Update to Keycloak $KEYCLOAK_VERSION_FULL"
48 git push --quiet --set-upstream origin-auth $BRANCH
49
50 PR_TITLE="Update to Keycloak $KEYCLOAK_VERSION_FULL"
51 PR_BODY="Updates Keycloak dependency, CI test image and project version for Keycloak release $KEYCLOAK_VERSION_FULL\\n\\n*(automated pull request after upstream release)*"
52 pull_request $BRANCH "$PR_TITLE" "$PR_BODY"
53 echo "Created pull request '$PR_TITLE'"