Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Auto generate Kedge JSON Schema for every merge
Browse files Browse the repository at this point in the history
This commit configures Travis to run a script on every merge to
Kedge master branch which updates the JSON Schema residing in
https://github.com/kedgeproject/json-schema

Significantly improves #280
  • Loading branch information
concaf committed Jan 2, 2018
1 parent 71f58ac commit ef256a3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
matrix:
include:
- go: 1.7
env: BUILD_DOCS=yes
env: BUILD_DOCS=yes GENERATE_JSON_SCHEMA=yes
- go: 1.8
- go: 1.9

Expand Down Expand Up @@ -48,3 +48,4 @@ after_success:
- goveralls -coverprofile=gover.coverprofile -service=travis-ci
# sync the docs only if everything else was successful
- ./scripts/sync-docs.sh
- ./scripts/update-json-schema.sh
40 changes: 40 additions & 0 deletions scripts/update-json-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Ensures that we run on Travis
if [ "$TRAVIS_BRANCH" != "master" ] || [ "$GENERATE_JSON_SCHEMA" != "yes" ] || [ "$TRAVIS_SECURE_ENV_VARS" == "false" ] || [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
echo "Must be: a merged PR on the master branch, GENERATE_JSON_SCHEMA=yes, TRAVIS_SECURE_ENV_VARS=false"
exit 0
fi

KEDGE_REPO_NAME="kedge-json-schema"
GENERATOR_REPO="[email protected]:kedgeproject/json-schema.git"
DEPLOY_KEY="scripts/deploy_key"
KEDGE_JSON_SCHEMA_IMAGE="containscafeine/kedge-json-schema:latest"
GIT_USER="kedge-bot"
GIT_EMAIL="[email protected]"
OUTPUT_DIR="master"

# decrypt the private key
openssl aes-256-cbc -K $encrypted_91569b511922_key -iv $encrypted_91569b511922_iv -in "$DEPLOY_KEY.enc" -out "$DEPLOY_KEY" -d
chmod 600 "$DEPLOY_KEY"
eval `ssh-agent -s`
ssh-add "$DEPLOY_KEY"

# clone the JSON Schema Generator repo
git clone "$GENERATOR_REPO" "$KEDGE_REPO_NAME"
cd "$KEDGE_REPO_NAME"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
docker run --rm -v "$OUTPUT_DIR":/data:Z "$KEDGE_JSON_SCHEMA_IMAGE"

# add relevant user information
git config user.name "$GIT_USER"

# email assigned
git config user.email "$GIT_EMAIL"
git add "$OUTPUT_DIR"

# Check if anything changed, and if it's the case, push to origin/master.
if git commit -m 'Update JSON Schema' -m "Commit: https://github.com/kedgeproject/kedge/commit/$TRAVIS_COMMIT" -m "PR: https://github.com/kedgeproject/kedge/pull/$TRAVIS_PULL_REQUEST" ; then
git push
fi

0 comments on commit ef256a3

Please sign in to comment.