@@ -35,7 +35,7 @@ script:
3535 if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
3636 then
3737 CURR=$(tail -n1 sizes | awk '{print $1}')
38- PREV=$(curl -u $GEKY_BOT_STATUSES https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
38+ PREV=$(curl -u " $GEKY_BOT_STATUSES" https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
3939 | jq -re "select(.sha != \"$TRAVIS_COMMIT\")
4040 | .statuses[] | select(.context == \"$STAGE/$NAME\").description
4141 | capture(\"code size is (?<size>[0-9]+)\").size" \
@@ -100,6 +100,7 @@ jobs:
100100 env :
101101 - STAGE=test
102102 - NAME=littlefs-fuse
103+ if : branch !~ -prefix$
103104 install :
104105 - sudo apt-get install libfuse-dev
105106 - git clone --depth 1 https://github.com/geky/littlefs-fuse
@@ -128,56 +129,88 @@ jobs:
128129 - ls
129130 - make -B test_dirs test_files QUIET=1
130131
131- # Automatically update releases
132+ # Automatically create releases
132133 - stage : deploy
133134 env :
134135 - STAGE=deploy
135136 - NAME=deploy
136137 script :
137- # Find version defined in lfs.h
138- - LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
139- - LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
140- - LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
141- # Grab latests patch from repo tags, default to 0
142- - LFS_VERSION_PATCH=$(curl -f -u "$GEKY_BOT_RELEASES"
143- https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs
144- | jq 'map(.ref | match(
145- " refs/tags/v'" $LFS_VERSION_MAJOR"'\\.'"$LFS_VERSION_MINOR"'\\.(.*)$")
146- .captures[].string | tonumber + 1) | max // 0')
147- # We have our new version
148- - LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
149- - echo "VERSION $LFS_VERSION"
150138 - |
139+ bash << 'SCRIPT'
140+ set -ev
141+ # Find version defined in lfs.h
142+ LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
143+ LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
144+ LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
145+ # Grab latests patch from repo tags, default to 0, needs finagling
146+ # to get past github's pagination api
147+ PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
148+ PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
149+ | sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
150+ || echo $PREV_URL)
151+ LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
152+ | jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
153+ .captures[].string | tonumber) | max + 1' \
154+ || echo 0)
155+ # We have our new version
156+ LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
157+ echo "VERSION $LFS_VERSION"
151158 # Check that we're the most recent commit
152159 CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
153- https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
154- | jq -re '.sha')
155- if [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ]
160+ https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
161+ | jq -re '.sha')
162+ [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
163+ # Create major branch
164+ git branch v$LFS_VERSION_MAJOR HEAD
165+ # Create major prefix branch
166+ git config user.name "geky bot"
167+ git config user.email "bot@geky.net"
168+ git fetch https://github.com/$TRAVIS_REPO_SLUG.git \
169+ --depth=50 v$LFS_VERSION_MAJOR-prefix || true
170+ ./scripts/prefix.py lfs$LFS_VERSION_MAJOR
171+ git branch v$LFS_VERSION_MAJOR-prefix $( \
172+ git commit-tree $(git write-tree) \
173+ $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
174+ -p HEAD \
175+ -m "Generated v$LFS_VERSION_MAJOR prefixes")
176+ git reset --hard
177+ # Update major version branches (vN and vN-prefix)
178+ git push https://$GEKY_BOT_RELEASES@github.com/$TRAVIS_REPO_SLUG.git \
179+ v$LFS_VERSION_MAJOR \
180+ v$LFS_VERSION_MAJOR-prefix
181+ # Create patch version tag (vN.N.N)
182+ curl -f -u "$GEKY_BOT_RELEASES" -X POST \
183+ https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
184+ -d "{
185+ \"ref\": \"refs/tags/$LFS_VERSION\",
186+ \"sha\": \"$TRAVIS_COMMIT\"
187+ }"
188+ # Create minor release?
189+ [[ "$LFS_VERSION" == *.0 ]] || exit 0
190+ # Build release notes
191+ PREV=$(git tag --sort=-v:refname -l "v*.0" | head -1)
192+ if [ ! -z "$PREV" ]
156193 then
157- # Build release notes
158- PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
159- if [ ! -z "$PREV" ]
160- then
161- echo "PREV $PREV"
162- CHANGES=$'### Changes\n\n'$( \
163- git log --oneline $PREV.. --grep='^Merge' --invert-grep)
164- printf "CHANGES\n%s\n\n" "$CHANGES"
165- fi
166- # Create the release
167- curl -f -u "$GEKY_BOT_RELEASES" -X POST \
168- https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
169- -d "{
170- \"tag_name\": \"$LFS_VERSION\",
171- \"target_commitish\": \"$TRAVIS_COMMIT\",
172- \"name\": \"${LFS_VERSION%.0}\",
173- \"body\": $(jq -sR '.' <<< "$CHANGES")
174- }"
194+ echo "PREV $PREV"
195+ CHANGES=$'### Changes\n\n'$( \
196+ git log --oneline $PREV.. --grep='^Merge' --invert-grep)
197+ printf "CHANGES\n%s\n\n" "$CHANGES"
175198 fi
199+ # Create the release
200+ curl -f -u "$GEKY_BOT_RELEASES" -X POST \
201+ https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
202+ -d "{
203+ \"tag_name\": \"$LFS_VERSION\",
204+ \"name\": \"${LFS_VERSION%.0}\",
205+ \"draft\": true,
206+ \"body\": $(jq -sR '.' <<< "$CHANGES")
207+ }" #"
208+ SCRIPT
176209
177210# Manage statuses
178211before_install :
179212 - |
180- curl -u $GEKY_BOT_STATUSES -X POST \
213+ curl -u " $GEKY_BOT_STATUSES" -X POST \
181214 https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
182215 -d "{
183216 \"context\": \"$STAGE/$NAME\",
@@ -188,7 +221,7 @@ before_install:
188221
189222after_failure :
190223 - |
191- curl -u $GEKY_BOT_STATUSES -X POST \
224+ curl -u " $GEKY_BOT_STATUSES" -X POST \
192225 https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
193226 -d "{
194227 \"context\": \"$STAGE/$NAME\",
@@ -199,7 +232,7 @@ after_failure:
199232
200233after_success :
201234 - |
202- curl -u $GEKY_BOT_STATUSES -X POST \
235+ curl -u " $GEKY_BOT_STATUSES" -X POST \
203236 https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
204237 -d "{
205238 \"context\": \"$STAGE/$NAME\",
0 commit comments