Skip to content

Commit 06767cc

Browse files
Cruz Monrreal IICruz Monrreal II
authored andcommitted
Corrected simplified astyle job behavior when base branch is not master
Consolidated efforts from PR #9336. Previous job's env vars would not be populated correctly if the base branch of a PR was not master. Corected by pulling remaining respository information to perform comparison between read-only instance of PR and base branch.
1 parent 8b6fffb commit 06767cc

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed

.travis.yml

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -134,43 +134,25 @@ matrix:
134134
- env:
135135
- NAME=astyle
136136
install:
137-
- curl -L0 https://mbed-os.s3-eu-west-1.amazonaws.com/builds/deps/astyle_3.1_linux.tar.gz --output astyle.tar.gz;
138-
mkdir -p BUILD && tar xf astyle.tar.gz -C BUILD;
139-
pushd BUILD/astyle/build/gcc;
140-
make;
141-
export PATH=$PWD/bin:$PATH;
142-
popd;
143-
- astyle --version
137+
- >-
138+
curl -L0 https://mbed-os.s3-eu-west-1.amazonaws.com/builds/deps/astyle_3.1_linux.tar.gz --output astyle.tar.gz;
139+
mkdir -p BUILD && tar xf astyle.tar.gz -C BUILD;
140+
cd BUILD/astyle/build/gcc;
141+
make;
142+
export PATH=$PWD/bin:$PATH;
143+
cd -
144+
- astyle --version
145+
# Fetch remaining information needed for branch comparison
146+
- git fetch --all --unshallow --tags
147+
- git fetch origin "${TRAVIS_BRANCH}"
144148
script:
145-
# only changed files this time
146-
git diff --name-only --diff-filter=d $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)$' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-files-changed.out;
147-
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
148-
git --no-pager diff;
149-
echo "";
150-
echo "AStyle check failed, please fix style issues as shown above";
151-
(exit 1);
152-
else
153-
echo "Coding style check OK";
154-
fi
155-
after_success:
156-
# run astyle for all files on the branch
157-
- git checkout -- .
158-
- find -regex '.*\.\(h\|c\|hpp\|cpp\)$' -type f | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-branch.out;
159-
# update status if we succeeded, compare with master if possible
160-
- |
161-
CURR=$(cat astyle-branch.out | grep Formatted | wc -l)
162-
PREV=$(curl -u "$MBED_BOT" https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
163-
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
164-
| .statuses[] | select(.context == \"travis-ci/$NAME\").description
165-
| capture(\", (?<files>[0-9]+) files\").files" \
166-
|| echo 0)
149+
- >-
150+
git diff --name-only --diff-filter=d FETCH_HEAD..HEAD \
151+
| ( grep '.\(c\|cpp\|h\|hpp\)$' || true ) \
152+
| ( fgrep -v -f .astyleignore || true ) \
153+
| while read file; do astyle -n --options=.astylerc "${file}"; done
154+
- git diff --exit-code --diff-filter=d --color
167155

168-
STATUSM="Passed, ${CURR} files"
169-
if [ "$PREV" -ne 0 ]
170-
then
171-
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") files)"
172-
fi
173-
- bash -c "$STATUS" success "$STATUSM"
174156
- env:
175157
- NAME=events
176158
- EVENTS=events

0 commit comments

Comments
 (0)