Skip to content

Commit

Permalink
v1.7.1.0: Include Git hash in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
ruipin committed Jun 14, 2021
1 parent 9c77e65 commit dd2ae9f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 22 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Prepare Environment
id: prepare_env
run: |
# Calculate project information
PROJECT="${GITHUB_REPOSITORY#ruipin/}"
PROJECT_NO_FVTT="${PROJECT#fvtt-}"
Expand All @@ -27,6 +28,9 @@ jobs:
echo ::set-output name=PROJECT::${PROJECT}
echo ::set-output name=PROJECT_NO_FVTT::${PROJECT_NO_FVTT}
# Calculate version information
GIT_HASH="$(git rev-parse HEAD)"
VERSION="${GITHUB_REF#refs/*/v}"
SPLIT_VERSION_1="${VERSION#*.}"
SPLIT_VERSION_2="${SPLIT_VERSION_1#*.}"
Expand All @@ -43,23 +47,27 @@ jobs:
git merge-base --is-ancestor HEAD origin/master && IS_PRERELEASE="false"
fi
# Store environment
echo ::set-output name=VERSION::${VERSION}
echo ::set-output name=MAJOR_VERSION::${MAJOR_VERSION}
echo ::set-output name=MINOR_VERSION::${MINOR_VERSION}
echo ::set-output name=PATCH_VERSION::${PATCH_VERSION}
echo ::set-output name=SUFFIX_VERSION::${SUFFIX_VERSION}
echo ::set-output name=IS_PRERELEASE::${IS_PRERELEASE}
echo ::set-output name=GIT_HASH::${GIT_HASH}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $GITHUB_ENV
echo "MINOR_VERSION=${MINOR_VERSION}" >> $GITHUB_ENV
echo "PATCH_VERSION=${PATCH_VERSION}" >> $GITHUB_ENV
echo "SUFFIX_VERSION=${SUFFIX_VERSION}" >> $GITHUB_ENV
echo "IS_PRERELEASE=${IS_PRERELEASE}" >> $GITHUB_ENV
echo "GIT_HASH=${GIT_HASH}" >> $GITHUB_ENV
echo "Project: '$PROJECT' ; Version: '$VERSION' ; Major: '$MAJOR_VERSION' ; Minor: '$MINOR_VERSION' ; Patch: '$PATCH_VERSION' ; Suffix: '$SUFFIX_VERSION' ; Pre-release: '$IS_PRERELEASE' ;"
echo "Project: '$PROJECT' ; Version: '$VERSION' ; Major: '$MAJOR_VERSION' ; Minor: '$MINOR_VERSION' ; Patch: '$PATCH_VERSION' ; Suffix: '$SUFFIX_VERSION' ; Hash: '$GIT_HASH' ; Pre-release: '$IS_PRERELEASE' ;"
if ! grep "\"$VERSION\"" module.json ; then
# Sanity check
if ! grep "\"${VERSION}\"" module.json ; then
echo "module.json version does not match the tag"
exit 1
fi
Expand Down Expand Up @@ -90,6 +98,7 @@ jobs:
npm run build
sed -r \
-e 's~("git_version":).*~\1 "${{ steps.prepare_env.outputs.GIT_HASH }}"~' \
-e 's~("esmodules":).*~\1 ["lib-wrapper.js"],~' \
-e 's~("styles":).*~\1 ["lib-wrapper.css"],~' \
-e 's~("manifest":)[^,]*~\1 "https://github.com/ruipin/${{ steps.prepare_env.outputs.PROJECT }}/releases/latest/download/module.json"~' \
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.7.1.0 (2021-06-14)

- Include Git commit hash in manifest.
- Update release scripts.
- Update version parsing code.

# 1.7.0.0 (2021-06-09)

- **[BREAKING]** Removed `libWrapper.clear_modules` API, `libWrapper.ClearModule` hook, and `LibWrapperModuleError` exception class (all deprecated since v1.6.0.0).
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ static ignore_conflicts(package_id, ignore_ids, targets, options={}) { /* ... */
#### 1.3.3.5. Library Versioning
This library follows [Semantic Versioning](https://semver.org/), with two custom fields `SUFFIX` and `META`, used together to track release meta-data (e.g. unstable versions or release candidates) and manifest-only changes (e.g. when `compatibleCoreVersion` increases).
This library follows [Semantic Versioning](https://semver.org/), with two custom fields `SUFFIX` and `META`. These are used to track manifest-only changes (e.g. when `compatibleCoreVersion` increases) and track release meta-data (e.g. release candidates and unstable versions) respectively. See below for examples.
The version string will always have format `<MAJOR>.<MINOR>.<PATCH>.<SUFFIX><META>`.
The `MAJOR`, `MINOR`, `PATCH` and `SUFFIX` fields will always be integers.
The `META` field is always a string, although it will often be empty.
This last field is unnecessary when comparing versions, as a change to this field will always cause one of the other fields to be incremented.
The `META` field is always a string, although it will often be empty. The `-` character between `SUFFIX` and `META` is optional if `META` is empty or does not start with a digit.
This last field `META` is unnecessary when comparing versions, as a change to this field will always cause one of the other fields to be incremented.
A few (non-exhaustive) examples of valid version strings and the corresponding `[MAJOR, MINOR, PATCH, SUFFIX, META]`:
Expand All @@ -364,6 +364,12 @@ static get version() { /* ... */ }
*/
static get versions() { /* ... */ }
/**
* Get the Git version identifier.
* @returns {string} Git version identifier, usually 'HEAD' or the commit hash.
*/
static get git_version() { return GIT_VERSION };
// Methods
/**
Expand Down Expand Up @@ -396,7 +402,7 @@ else {
The arguments `minor`, `patch` and `suffix` are optional. Note the usage of `?.` to ensure this works (and is falsy) before v1.4.0.0.
If you wish to detect versions below v1.4.0.0, you should instead use `versions` instead:
If you wish to detect versions below v1.4.0.0, you should use `versions` instead:
```javascript
const [lwmajor, lwminor, lwpatch, lwsuffix] = libWrapper.versions;
Expand Down
5 changes: 4 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
"name": "lib-wrapper",
"title": "libWrapper",
"description": "Library for wrapping core Foundry VTT methods, meant to improve compatibility between packages that wrap the same methods.",
"version": "1.7.0.0",
"version": "1.7.1.0",
"author": "Rui Pinheiro",
"esmodules": ["src/index.js"],
"styles": ["dist/lib-wrapper.css"],
"minimumCoreVersion": "0.6.5",
"compatibleCoreVersion": "0.8.6",
"flags": {
"git_version": "HEAD"
},
"library": true,
"url": "https://github.com/ruipin/fvtt-lib-wrapper",
"manifest": "https://github.com/ruipin/fvtt-lib-wrapper/releases/latest/download/module.json",
Expand Down
38 changes: 27 additions & 11 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,35 @@ export const PACKAGE_TITLE = 'libWrapper';


//*********************
// Semantic versioning

export let VERSION = '';
export let MAJOR_VERSION = -1;
export let MINOR_VERSION = -1;
export let PATCH_VERSION = -1;
export let SUFFIX_VERSION = -1;
export let META_VERSION = '';
// Versioning

export let VERSION = '';
export let MAJOR_VERSION = -1;
export let MINOR_VERSION = -1;
export let PATCH_VERSION = -1;
export let SUFFIX_VERSION = -1;
export let META_VERSION = '';
export let GIT_VERSION = '';
export let GIT_VERSION_SHORT = '';
export let VERSION_WITH_GIT = '';

export function parse_manifest_version() {
if(VERSION)
return;

const version_str = game.modules?.get(PACKAGE_ID)?.data?.version;
// Find package manifest
const manifest = game.modules?.get(PACKAGE_ID)?.data;
if(!manifest)
throw `libWrapper: Unable to find package manifest inside 'game.modules'`;

// Grab git version
GIT_VERSION = manifest.flags?.git_version ?? 'unknown';
GIT_VERSION_SHORT = (GIT_VERSION.length >= 40) ? GIT_VERSION.slice(0,7) : GIT_VERSION;

// Parse version string
const version_str = manifest.version;
if(!version_str)
throw `libWrapper: Unable to find version string inside 'game.modules'`;
throw `libWrapper: Unable to find version string inside package manifest`;

const match = version_str.match(/^([0-9]+)\.([0-9]+)\.([0-9]+).([0-9]+)(.*)$/i);
if(!match)
Expand All @@ -36,7 +49,10 @@ export function parse_manifest_version() {
MINOR_VERSION = parseInt(match[2]);
PATCH_VERSION = parseInt(match[3]);
SUFFIX_VERSION = parseInt(match[4]);
META_VERSION = match[5];
META_VERSION = match[5].replace(/^-/gi, '');

// Conclude
VERSION_WITH_GIT = `${VERSION} (${GIT_VERSION_SHORT})`;
}


Expand Down
11 changes: 9 additions & 2 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import {
PACKAGE_ID, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, SUFFIX_VERSION, META_VERSION, VERSION, parse_manifest_version,
PACKAGE_ID, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, SUFFIX_VERSION, META_VERSION, VERSION, GIT_VERSION, VERSION_WITH_GIT, parse_manifest_version,
IS_UNITTEST, PROPERTIES_CONFIGURABLE, DEBUG, setDebug,
TYPES, TYPES_REVERSE, TYPES_LIST,
PERF_MODES, PERF_MODES_REVERSE, PERF_MODES_LIST
Expand Down Expand Up @@ -200,6 +200,13 @@ export class libWrapper {
*/
static get versions() { return [MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, SUFFIX_VERSION, META_VERSION]; }

/**
* Get the Git version identifier.
* @returns {string} Git version identifier, usually 'HEAD' or the commit hash.
*/
static get git_version() { return GIT_VERSION };


/**
* @returns {boolean} The real libWrapper module will always return false. Fallback implementations (e.g. poly-fill / shim) should return true.
*/
Expand Down Expand Up @@ -586,7 +593,7 @@ init_error_listeners();
LibWrapperNotifications.init();

// Notify everyone the library has loaded and is ready to start registering wrappers
console.info(`libWrapper ${VERSION}: Ready.`);
console.info(`libWrapper ${VERSION_WITH_GIT}: Ready.`);
Hooks.callAll('libWrapper.Ready', libWrapper);

return wrapped(...args);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

import {PACKAGE_ID, PACKAGE_TITLE, VERSION, TYPES_REVERSE, PERF_MODES_REVERSE} from '../consts.js';
import {PACKAGE_ID, PACKAGE_TITLE, VERSION_WITH_GIT, TYPES_REVERSE, PERF_MODES_REVERSE} from '../consts.js';
import {LibWrapperStats} from './stats.js';
import {WRAPPERS} from '../utils/misc.js';
import {PackageInfo, PACKAGE_TYPES} from '../utils/package_info.js';
Expand Down Expand Up @@ -326,7 +326,7 @@ export class LibWrapperSettings extends FormApplication {
let data = {
about: {
name: PACKAGE_TITLE,
version: VERSION,
version: VERSION_WITH_GIT,
collect_stats: LibWrapperStats.collect_stats
},

Expand Down

0 comments on commit dd2ae9f

Please sign in to comment.