Skip to content

Commit

Permalink
feat: Add git sha to build artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTolmay committed Nov 9, 2023
1 parent 466c5ac commit c0c0a51
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
limitations under the License.
*/

import { execSync } from 'child_process';
import { type } from '@lowdefy/helpers';

function validateApp({ components }) {
function buildApp({ components }) {
if (type.isNone(components.app)) {
components.app = {};
}
Expand All @@ -34,7 +35,12 @@ function validateApp({ components }) {
if (type.isNone(components.app.html.appendHead)) {
components.app.html.appendHead = '';
}
try {
components.app.git_sha = execSync('git rev-parse HEAD').toString().trim();
} catch (_) {
//pass
}
return components;
}

export default validateApp;
export default buildApp;
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,88 @@
limitations under the License.
*/

import validateApp from './validateApp.js';
import { execSync } from 'child_process';

import buildApp from './buildApp.js';
import testContext from '../test/testContext.js';

const context = testContext();

test('validateApp no app defined', () => {
let git_sha;

try {
git_sha = execSync('git rev-parse HEAD').toString().trim();
} catch (_) {
//pass
}

test('buildApp no app defined', () => {
const components = {};
const result = validateApp({ components, context });
const result = buildApp({ components, context });
expect(result).toEqual({
app: {
html: {
appendBody: '',
appendHead: '',
},
git_sha,
},
});
});

test('validateApp empty app object', () => {
test('buildApp empty app object', () => {
const components = { app: {} };
const result = validateApp({ components, context });
const result = buildApp({ components, context });
expect(result).toEqual({
app: {
html: {
appendBody: '',
appendHead: '',
},
git_sha,
},
});
});

test('validateApp empty html', () => {
test('buildApp empty html', () => {
const components = { app: { html: {} } };
const result = validateApp({ components, context });
const result = buildApp({ components, context });
expect(result).toEqual({
app: {
html: {
appendBody: '',
appendHead: '',
},
git_sha,
},
});
});

test('validateApp appendHead and appendHead', () => {
test('buildApp appendHead and appendHead', () => {
const components = {
app: {
html: {
appendBody: 'body',
appendHead: 'head',
},
git_sha,
},
};
const result = validateApp({ components, context });
const result = buildApp({ components, context });
expect(result).toEqual({
app: {
html: {
appendBody: 'body',
appendHead: 'head',
},
git_sha,
},
});
});

test('validateApp app not an object', () => {
test('buildApp app not an object', () => {
const components = {
app: 'app',
};
expect(() => validateApp({ components, context })).toThrow('lowdefy.app is not an object.');
expect(() => buildApp({ components, context })).toThrow('lowdefy.app is not an object.');
});
4 changes: 2 additions & 2 deletions packages/build/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import createPluginTypesMap from './utils/createPluginTypesMap.js';

import addDefaultPages from './build/addDefaultPages/addDefaultPages.js';
import addKeys from './build/addKeys.js';
import buildApp from './build/buildApp.js';
import buildAuth from './build/buildAuth/buildAuth.js';
import buildConnections from './build/buildConnections.js';
import buildImports from './build/buildImports/buildImports.js';
Expand All @@ -31,7 +32,6 @@ import buildTypes from './build/buildTypes.js';
import cleanBuildDirectory from './build/cleanBuildDirectory.js';
import copyPublicFolder from './build/copyPublicFolder.js';
import testSchema from './build/testSchema.js';
import validateApp from './build/validateApp.js';
import validateConfig from './build/validateConfig.js';
import updateServerPackageJson from './build/updateServerPackageJson.js';
import writeApp from './build/writeApp.js';
Expand All @@ -50,7 +50,7 @@ async function build(options) {
const context = createContext(options);
const components = await buildRefs({ context });
testSchema({ components, context });
validateApp({ components, context });
buildApp({ components, context });
validateConfig({ components, context });
addDefaultPages({ components, context });
buildAuth({ components, context });
Expand Down

0 comments on commit c0c0a51

Please sign in to comment.