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

Commit

Permalink
Fix check oas spec
Browse files Browse the repository at this point in the history
  • Loading branch information
minchao committed Jul 20, 2019
1 parent 12b4701 commit f2ad9b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install:
- go mod download

script:
- if [[ $TRAVIS_BRANCH == "check-spec" ]]; then
- if [[ $TRAVIS_BRANCH == "check-oas-spec" ]]; then
make spec;
make generate;
fi
Expand All @@ -45,7 +45,7 @@ script:
deploy:
- provider: script
skip_cleanup: true
script: bash ${TRAVIS_BUILD_DIR}/scripts/check-spec.sh
script: bash ${TRAVIS_BUILD_DIR}/scripts/check-oas-spec.sh
on:
branch: check-spec
branch: check-oas-spec
condition: $DEPLOY = true
35 changes: 22 additions & 13 deletions scripts/check-spec.sh → scripts/check-oas-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -eo pipefail

owner="minchao"
repo="go-ptx"
isSpecChanged=false

function setup() {
if [[ "${TRAVIS}" == "true" ]]; then
Expand All @@ -17,30 +18,38 @@ function setup() {
fi
}

function git_diff() {
local specs
specs=$(find . -maxdepth 1 -type f -name "oas.*")
for spec in ${specs}
function check_oas_spec() {
for spec in ./oas.*.*.json
do
IFS='.' read -r -a substrings <<< "${spec}"
target_folders="${target_folders} ${substrings[2]}"
done
target_folders="$(echo -e "${target_folders}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
export target_folders

output=$(git diff origin/master -- ${target_folders} README.md)
export output
local output
output=$(git diff origin/master -- ${target_folders})
if [[ -n "${output}" ]]; then
isSpecChanged=true
fi
}

function git_push() {
new_branch="spec-changes-on-$(date +"%Y%m%d")"
message="OAS spec changes on the $(date +"%Y%m%d")"
local version
version=$(printf '%(%Y-%m-%d)T\n' -1)

new_branch="spec-changes-on-${version}"
export new_branch
message="OAS spec changes on the ${version}"
export message

git add ${target_folders} oas.*.*.json
git checkout -b "${new_branch}"
git add ${target_folders} README.md
git commit -m "${message}"
git push --quiet origin "${new_branch}"
}

function github_draft_pr() {
function create_github_pull_request() {
curl -X POST \
-H "authorization: Bearer ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
Expand All @@ -51,9 +60,9 @@ function github_draft_pr() {

setup
git fetch origin master
git_diff
check_oas_spec

if [[ -n "${output}" ]]; then
if [[ ${isSpecChanged} == true ]]; then
git_push
github_draft_pr
create_github_pull_request
fi

0 comments on commit f2ad9b9

Please sign in to comment.