Skip to content

Commit

Permalink
Added automatic versioning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geky committed Aug 4, 2019
1 parent e3008b2 commit 3a8a8b1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,67 @@ jobs:
fi
fi
# Deploy stage for updating versions and tags
- stage: deploy
env:
- STAGE=deploy
- NAME=deploy
script:
- |
bash << 'SCRIPT'
set -ev
# Find version defined in equeue.h
EQUEUE_VERSION=$(grep -ox '#define EQUEUE_VERSION .*' equeue.h \
| cut -d ' ' -f3)
EQUEUE_VERSION_MAJOR=$((0xffff & ($EQUEUE_VERSION >> 16)))
EQUEUE_VERSION_MINOR=$((0xffff & ($EQUEUE_VERSION >> 0)))
# Grab latest patch from repo tags, default to 0, needs finagling
# to get past GitHub's pagination API
PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$EQUEUE_VERSION_MAJOR.$EQUEUE_VERSION_MINOR.
PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
| sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
|| echo $PREV_URL)
EQUEUE_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
| jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
.captures[].string | tonumber) | max + 1' \
|| echo 0)
# We have our new version
EQUEUE_VERSION="v$EQUEUE_VERSION_MAJOR.$EQUEUE_VERSION_MINOR.$EQUEUE_VERSION_PATCH"
echo "VERSION $EQUEUE_VERSION"
# Check that we're the most recent commit
CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
| jq -re '.sha')
[ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
# Create major branch (vN)
git branch v$EQUEUE_VERSION_MAJOR HEAD
git push https://[email protected]/$TRAVIS_REPO_SLUG.git \
v$EQUEUE_VERSION_MAJOR
# Create patch version tag (vN.N.N)
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
-d "{
\"ref\": \"refs/tags/$EQUEUE_VERSION\",
\"sha\": \"$TRAVIS_COMMIT\"
}"
# Build release notes
PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
if [ ! -z "$PREV" ]
then
echo "PREV $PREV"
CHANGES=$(git log --oneline $PREV.. --grep='^Merge' --invert-grep)
printf "CHANGES\n%s\n\n" "$CHANGES"
fi
# Create the release
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
-d "{
\"tag_name\": \"$EQUEUE_VERSION\",
\"name\": \"${EQUEUE_VERSION%.0}\",
\"draft\": $(jq -R 'endswith(".0")' <<< "$EQUEUE_VERSION"),
\"body\": $(jq -sR '.' <<< "$CHANGES")
}" #"
SCRIPT
# Manage statuses
before_install:
Expand Down Expand Up @@ -109,3 +170,5 @@ after_success:
# Job control
stages:
- name: test
- name: deploy
if: branch = master AND type = push
8 changes: 8 additions & 0 deletions equeue.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ extern "C" {
#include <stdint.h>


// Version info
// Major (top-nibble), incremented on backwards incompatible changes
// Minor (bottom-nibble), incremented on feature additions
#define EQUEUE_VERSION 0x00010001
#define EQUEUE_VERSION_MAJOR (0xffff & (EQUEUE_VERSION >> 16))
#define EQUEUE_VERSION_MINOR (0xffff & (EQUEUE_VERSION >> 0))


// The minimum size of an event
// This size is guaranteed to fit events created by event_call
#define EQUEUE_EVENT_SIZE (sizeof(struct equeue_event) + 2*sizeof(void*))
Expand Down

0 comments on commit 3a8a8b1

Please sign in to comment.