.travis.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. # Environment variables
  2. env:
  3. global:
  4. - CFLAGS=-Werror
  5. # Common test script
  6. script:
  7. # make sure example can at least compile
  8. - sed -n '/``` c/,/```/{/```/d; p;}' README.md > test.c &&
  9. make all CFLAGS+="
  10. -Duser_provided_block_device_read=NULL
  11. -Duser_provided_block_device_prog=NULL
  12. -Duser_provided_block_device_erase=NULL
  13. -Duser_provided_block_device_sync=NULL
  14. -include stdio.h"
  15. # run tests
  16. - make test QUIET=1
  17. # run tests with a few different configurations
  18. - make test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=1 -DLFS_CACHE_SIZE=4"
  19. - make test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=512 -DLFS_CACHE_SIZE=512 -DLFS_BLOCK_CYCLES=16"
  20. - make test QUIET=1 CFLAGS+="-DLFS_BLOCK_COUNT=1023 -DLFS_LOOKAHEAD_SIZE=256"
  21. - make clean test QUIET=1 CFLAGS+="-DLFS_INLINE_MAX=0"
  22. - make clean test QUIET=1 CFLAGS+="-DLFS_NO_INTRINSICS"
  23. # compile and find the code size with the smallest configuration
  24. - make clean size
  25. OBJ="$(ls lfs*.o | tr '\n' ' ')"
  26. CFLAGS+="-DLFS_NO_ASSERT -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR"
  27. | tee sizes
  28. # update status if we succeeded, compare with master if possible
  29. - |
  30. if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
  31. then
  32. CURR=$(tail -n1 sizes | awk '{print $1}')
  33. PREV=$(curl -u "$GEKY_BOT_STATUSES" https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
  34. | jq -re "select(.sha != \"$TRAVIS_COMMIT\")
  35. | .statuses[] | select(.context == \"$STAGE/$NAME\").description
  36. | capture(\"code size is (?<size>[0-9]+)\").size" \
  37. || echo 0)
  38. STATUS="Passed, code size is ${CURR}B"
  39. if [ "$PREV" -ne 0 ]
  40. then
  41. STATUS="$STATUS ($(python -c "print '%+.2f' % (100*($CURR-$PREV)/$PREV.0)")%)"
  42. fi
  43. fi
  44. # CI matrix
  45. jobs:
  46. include:
  47. # native testing
  48. - stage: test
  49. env:
  50. - STAGE=test
  51. - NAME=littlefs-x86
  52. # cross-compile with ARM (thumb mode)
  53. - stage: test
  54. env:
  55. - STAGE=test
  56. - NAME=littlefs-arm
  57. - CC="arm-linux-gnueabi-gcc --static -mthumb"
  58. - EXEC="qemu-arm"
  59. install:
  60. - sudo apt-get install
  61. gcc-arm-linux-gnueabi
  62. libc6-dev-armel-cross
  63. qemu-user
  64. - arm-linux-gnueabi-gcc --version
  65. - qemu-arm -version
  66. # cross-compile with PowerPC
  67. - stage: test
  68. env:
  69. - STAGE=test
  70. - NAME=littlefs-powerpc
  71. - CC="powerpc-linux-gnu-gcc --static"
  72. - EXEC="qemu-ppc"
  73. install:
  74. - sudo apt-get install
  75. gcc-powerpc-linux-gnu
  76. libc6-dev-powerpc-cross
  77. qemu-user
  78. - powerpc-linux-gnu-gcc --version
  79. - qemu-ppc -version
  80. # cross-compile with MIPS
  81. - stage: test
  82. env:
  83. - STAGE=test
  84. - NAME=littlefs-mips
  85. - CC="mips-linux-gnu-gcc --static"
  86. - EXEC="qemu-mips"
  87. install:
  88. - sudo apt-get install
  89. gcc-mips-linux-gnu
  90. libc6-dev-mips-cross
  91. qemu-user
  92. - mips-linux-gnu-gcc --version
  93. - qemu-mips -version
  94. # self-host with littlefs-fuse for fuzz test
  95. - stage: test
  96. env:
  97. - STAGE=test
  98. - NAME=littlefs-fuse
  99. if: branch !~ -prefix$
  100. install:
  101. - sudo apt-get install libfuse-dev
  102. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2-alpha
  103. - fusermount -V
  104. - gcc --version
  105. before_script:
  106. # setup disk for littlefs-fuse
  107. - rm -rf littlefs-fuse/littlefs/*
  108. - cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
  109. - mkdir mount
  110. - sudo chmod a+rw /dev/loop0
  111. - dd if=/dev/zero bs=512 count=4096 of=disk
  112. - losetup /dev/loop0 disk
  113. script:
  114. # self-host test
  115. - make -C littlefs-fuse
  116. - littlefs-fuse/lfs --format /dev/loop0
  117. - littlefs-fuse/lfs /dev/loop0 mount
  118. - ls mount
  119. - mkdir mount/littlefs
  120. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  121. - cd mount/littlefs
  122. - stat .
  123. - ls -flh
  124. - make -B test_dirs test_files QUIET=1
  125. # self-host with littlefs-fuse for fuzz test
  126. - stage: test
  127. env:
  128. - STAGE=test
  129. - NAME=littlefs-migration
  130. if: branch !~ -prefix$
  131. install:
  132. - sudo apt-get install libfuse-dev
  133. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2-alpha v2
  134. - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v1 v1
  135. - fusermount -V
  136. - gcc --version
  137. before_script:
  138. # setup disk for littlefs-fuse
  139. - rm -rf v2/littlefs/*
  140. - cp -r $(git ls-tree --name-only HEAD) v2/littlefs
  141. - mkdir mount
  142. - sudo chmod a+rw /dev/loop0
  143. - dd if=/dev/zero bs=512 count=4096 of=disk
  144. - losetup /dev/loop0 disk
  145. script:
  146. # compile v1 and v2
  147. - make -C v1
  148. - make -C v2
  149. # run self-host test with v1
  150. - v1/lfs --format /dev/loop0
  151. - v1/lfs /dev/loop0 mount
  152. - ls mount
  153. - mkdir mount/littlefs
  154. - cp -r $(git ls-tree --name-only HEAD) mount/littlefs
  155. - cd mount/littlefs
  156. - stat .
  157. - ls -flh
  158. - make -B test_dirs test_files QUIET=1
  159. # attempt to migrate
  160. - cd ../..
  161. - fusermount -u mount
  162. - v2/lfs --migrate /dev/loop0
  163. - v2/lfs /dev/loop0 mount
  164. # run self-host test with v2 right where we left off
  165. - ls mount
  166. - cd mount/littlefs
  167. - stat .
  168. - ls -flh
  169. - make -B test_dirs test_files QUIET=1
  170. # Automatically create releases
  171. - stage: deploy
  172. env:
  173. - STAGE=deploy
  174. - NAME=deploy
  175. script:
  176. - |
  177. bash << 'SCRIPT'
  178. set -ev
  179. # Find version defined in lfs.h
  180. LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
  181. LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
  182. LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
  183. # Grab latests patch from repo tags, default to 0, needs finagling
  184. # to get past github's pagination api
  185. PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
  186. PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
  187. | sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
  188. || echo $PREV_URL)
  189. LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
  190. | jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
  191. .captures[].string | tonumber) | max + 1' \
  192. || echo 0)
  193. # We have our new version
  194. LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
  195. echo "VERSION $LFS_VERSION"
  196. # Check that we're the most recent commit
  197. CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
  198. https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
  199. | jq -re '.sha')
  200. [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
  201. # Create major branch
  202. git branch v$LFS_VERSION_MAJOR HEAD
  203. # Create major prefix branch
  204. git config user.name "geky bot"
  205. git config user.email "bot@geky.net"
  206. git fetch https://github.com/$TRAVIS_REPO_SLUG.git \
  207. --depth=50 v$LFS_VERSION_MAJOR-prefix || true
  208. ./scripts/prefix.py lfs$LFS_VERSION_MAJOR
  209. git branch v$LFS_VERSION_MAJOR-prefix $( \
  210. git commit-tree $(git write-tree) \
  211. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  212. -p HEAD \
  213. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  214. git reset --hard
  215. # Update major version branches (vN and vN-prefix)
  216. git push https://$GEKY_BOT_RELEASES@github.com/$TRAVIS_REPO_SLUG.git \
  217. v$LFS_VERSION_MAJOR \
  218. v$LFS_VERSION_MAJOR-prefix
  219. # Create patch version tag (vN.N.N)
  220. curl -f -u "$GEKY_BOT_RELEASES" -X POST \
  221. https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
  222. -d "{
  223. \"ref\": \"refs/tags/$LFS_VERSION\",
  224. \"sha\": \"$TRAVIS_COMMIT\"
  225. }"
  226. # Create minor release?
  227. [[ "$LFS_VERSION" == *.0 ]] || exit 0
  228. # Build release notes
  229. PREV=$(git tag --sort=-v:refname -l "v*.0" | head -1)
  230. if [ ! -z "$PREV" ]
  231. then
  232. echo "PREV $PREV"
  233. CHANGES=$'### Changes\n\n'$( \
  234. git log --oneline $PREV.. --grep='^Merge' --invert-grep)
  235. printf "CHANGES\n%s\n\n" "$CHANGES"
  236. fi
  237. # Create the release
  238. curl -f -u "$GEKY_BOT_RELEASES" -X POST \
  239. https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
  240. -d "{
  241. \"tag_name\": \"$LFS_VERSION\",
  242. \"name\": \"${LFS_VERSION%.0}\",
  243. \"draft\": true,
  244. \"body\": $(jq -sR '.' <<< "$CHANGES")
  245. }" #"
  246. SCRIPT
  247. # Manage statuses
  248. before_install:
  249. - |
  250. curl -u "$GEKY_BOT_STATUSES" -X POST \
  251. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  252. -d "{
  253. \"context\": \"$STAGE/$NAME\",
  254. \"state\": \"pending\",
  255. \"description\": \"${STATUS:-In progress}\",
  256. \"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
  257. }"
  258. after_failure:
  259. - |
  260. curl -u "$GEKY_BOT_STATUSES" -X POST \
  261. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  262. -d "{
  263. \"context\": \"$STAGE/$NAME\",
  264. \"state\": \"failure\",
  265. \"description\": \"${STATUS:-Failed}\",
  266. \"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
  267. }"
  268. after_success:
  269. - |
  270. curl -u "$GEKY_BOT_STATUSES" -X POST \
  271. https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
  272. -d "{
  273. \"context\": \"$STAGE/$NAME\",
  274. \"state\": \"success\",
  275. \"description\": \"${STATUS:-Passed}\",
  276. \"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
  277. }"
  278. # Job control
  279. stages:
  280. - name: test
  281. - name: deploy
  282. if: branch = master AND type = push