Skip to content

Commit 3a8a8b1

Browse files
committed
Added automatic versioning
Based off the versioning in littlefs, which went through a number of iterations before arriving at the current scheme 1. Version macros (EQUEUE_VERSION, EQUEUE_VERSION_MAJOR, and EQUEUE_VERSION_MINOR) are available in equeue.h for feature tests 2. These are used in CI to determine the current version 3. Additionally, CI keeps track of a simple incrementing patch number. Every time CI completes on master and is the most recent commit, a new patch number is generated, and a patch tag (ie v1.3.2) is created. 4. On top of this, CI will keep a major version branch (ie v1) updated to point to the most recent commit. 5. Each release, CI will automatically create release notes containing a list of new commits. This can be used as a starting point for additional notes and is a draft on major or minor releases.
1 parent e3008b2 commit 3a8a8b1

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

.travis.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,67 @@ jobs:
7171
fi
7272
fi
7373
74+
# Deploy stage for updating versions and tags
75+
- stage: deploy
76+
env:
77+
- STAGE=deploy
78+
- NAME=deploy
79+
script:
80+
- |
81+
bash << 'SCRIPT'
82+
set -ev
83+
# Find version defined in equeue.h
84+
EQUEUE_VERSION=$(grep -ox '#define EQUEUE_VERSION .*' equeue.h \
85+
| cut -d ' ' -f3)
86+
EQUEUE_VERSION_MAJOR=$((0xffff & ($EQUEUE_VERSION >> 16)))
87+
EQUEUE_VERSION_MINOR=$((0xffff & ($EQUEUE_VERSION >> 0)))
88+
# Grab latest patch from repo tags, default to 0, needs finagling
89+
# to get past GitHub's pagination API
90+
PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$EQUEUE_VERSION_MAJOR.$EQUEUE_VERSION_MINOR.
91+
PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
92+
| sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
93+
|| echo $PREV_URL)
94+
EQUEUE_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
95+
| jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
96+
.captures[].string | tonumber) | max + 1' \
97+
|| echo 0)
98+
# We have our new version
99+
EQUEUE_VERSION="v$EQUEUE_VERSION_MAJOR.$EQUEUE_VERSION_MINOR.$EQUEUE_VERSION_PATCH"
100+
echo "VERSION $EQUEUE_VERSION"
101+
# Check that we're the most recent commit
102+
CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
103+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
104+
| jq -re '.sha')
105+
[ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
106+
# Create major branch (vN)
107+
git branch v$EQUEUE_VERSION_MAJOR HEAD
108+
git push https://[email protected]/$TRAVIS_REPO_SLUG.git \
109+
v$EQUEUE_VERSION_MAJOR
110+
# Create patch version tag (vN.N.N)
111+
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
112+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
113+
-d "{
114+
\"ref\": \"refs/tags/$EQUEUE_VERSION\",
115+
\"sha\": \"$TRAVIS_COMMIT\"
116+
}"
117+
# Build release notes
118+
PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
119+
if [ ! -z "$PREV" ]
120+
then
121+
echo "PREV $PREV"
122+
CHANGES=$(git log --oneline $PREV.. --grep='^Merge' --invert-grep)
123+
printf "CHANGES\n%s\n\n" "$CHANGES"
124+
fi
125+
# Create the release
126+
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
127+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
128+
-d "{
129+
\"tag_name\": \"$EQUEUE_VERSION\",
130+
\"name\": \"${EQUEUE_VERSION%.0}\",
131+
\"draft\": $(jq -R 'endswith(".0")' <<< "$EQUEUE_VERSION"),
132+
\"body\": $(jq -sR '.' <<< "$CHANGES")
133+
}" #"
134+
SCRIPT
74135
75136
# Manage statuses
76137
before_install:
@@ -109,3 +170,5 @@ after_success:
109170
# Job control
110171
stages:
111172
- name: test
173+
- name: deploy
174+
if: branch = master AND type = push

equeue.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ extern "C" {
1818
#include <stdint.h>
1919

2020

21+
// Version info
22+
// Major (top-nibble), incremented on backwards incompatible changes
23+
// Minor (bottom-nibble), incremented on feature additions
24+
#define EQUEUE_VERSION 0x00010001
25+
#define EQUEUE_VERSION_MAJOR (0xffff & (EQUEUE_VERSION >> 16))
26+
#define EQUEUE_VERSION_MINOR (0xffff & (EQUEUE_VERSION >> 0))
27+
28+
2129
// The minimum size of an event
2230
// This size is guaranteed to fit events created by event_call
2331
#define EQUEUE_EVENT_SIZE (sizeof(struct equeue_event) + 2*sizeof(void*))

0 commit comments

Comments
 (0)