From 64f40e823bb10085c6202a3eeb8ea2d17d56d5d3 Mon Sep 17 00:00:00 2001 From: Preston Tamkin Date: Mon, 24 Oct 2022 17:41:55 -0700 Subject: [PATCH] Fix issue where HOSTS_VERSION was incompatible with packages not using 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 --- .github/workflows/npm-publish.yml | 4 ++++ packages/amazon-sumerian-hosts-core/src/core/Utils.js | 6 +++--- webpack.config.js | 5 ----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 18006cc..2f9d3ab 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -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: diff --git a/packages/amazon-sumerian-hosts-core/src/core/Utils.js b/packages/amazon-sumerian-hosts-core/src/core/Utils.js index 993a714..1e487dd 100644 --- a/packages/amazon-sumerian-hosts-core/src/core/Utils.js +++ b/packages/amazon-sumerian-hosts-core/src/core/Utils.js @@ -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. * @@ -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; } } diff --git a/webpack.config.js b/webpack.config.js index 627ddc2..4bda0de 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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) { @@ -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: {