Skip to content

Commit

Permalink
Fix issue where HOSTS_VERSION was incompatible with packages not usin…
Browse files Browse the repository at this point in the history
…g webpack. (#142)

We were setting the HOSTS_VERSION at build time using webpack.

We also want customers who want to use modules/not use our webpack build to be able to do so.

These are incompatible.

To solve this, we are now writing out the version number into source at release time.
This should have the same effect as before, anyone using an NPM release will get a version number, otherwise you will have 'development'.

I tested this in a release in my fork, you can see the overwritten file here in the artifacts: https://github.com/prestomation/amazon-sumerian-hosts/actions/runs/3301290701
  • Loading branch information
prestomation authored Oct 25, 2022
1 parent dec55fb commit 64f40e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- name: "Set version number"
run: |
perl -i -p -e "s/HOSTS_VERSION = .*/HOSTS_VERSION = '${{ github.event.release.tag_name }}';/" ${{ github.workspace }}/packages/amazon-sumerian-hosts-core/src/core/Utils.js
- run: npm run release
- run: npm publish --workspaces --access public
env:
Expand Down
6 changes: 3 additions & 3 deletions packages/amazon-sumerian-hosts-core/src/core/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: MIT-0
import Deferred from './Deferred';

// This line gets replaced by Github actions to the SHA of the git commit
const HOSTS_VERSION = "development";

/**
* A collection of useful generic functions.
*
Expand Down Expand Up @@ -194,9 +197,6 @@ class Utils {
}

static getVersion() {
// HOSTS_VERSION is defined by Webpack, to the version of the library
// Either a git commit or a release version
// eslint-disable-next-line no-undef
return HOSTS_VERSION;
}
}
Expand Down
5 changes: 0 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ if (process.env.ENGINE === 'core') {

let devServerOnlyEntryPoints = {};

// During a github build we pull the git commit sha out of the environment
// for local builds we hardcode 'development', so we can differentiate these(i.e. in dev the commit hash is not really accurate)
const HOSTS_VERSION = JSON.stringify(process.env.GITHUB_SHA || 'development');

let prodOnlyExternals = [];

if (isDevServer) {
Expand Down Expand Up @@ -133,7 +129,6 @@ module.exports = {
banner: `Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0`,
entryOnly: true,
}),
new webpack.DefinePlugin({HOSTS_VERSION}),
],
devServer: {
devMiddleware: {
Expand Down

0 comments on commit 64f40e8

Please sign in to comment.