Merge pull request #1434 from knorrium/fix_git_commit_error
Fix git commit error
This commit is contained in:
commit
46405438d3
@ -2,6 +2,7 @@ import * as fs from 'fs';
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import { IBackendInfo } from '../mempool.interfaces';
|
import { IBackendInfo } from '../mempool.interfaces';
|
||||||
|
const { spawnSync } = require('child_process');
|
||||||
|
|
||||||
class BackendInfo {
|
class BackendInfo {
|
||||||
private gitCommitHash = '';
|
private gitCommitHash = '';
|
||||||
@ -27,10 +28,23 @@ class BackendInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setLatestCommitHash(): void {
|
private setLatestCommitHash(): void {
|
||||||
try {
|
//TODO: share this logic with `generate-config.js`
|
||||||
this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
|
if (process.env.DOCKER_COMMIT_HASH) {
|
||||||
} catch (e) {
|
this.gitCommitHash = process.env.DOCKER_COMMIT_HASH;
|
||||||
logger.err('Could not load git commit info: ' + (e instanceof Error ? e.message : e));
|
} else {
|
||||||
|
try {
|
||||||
|
const gitRevParse = spawnSync('git', ['rev-parse', '--short', 'HEAD']);
|
||||||
|
if (!gitRevParse.error) {
|
||||||
|
const output = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, '');
|
||||||
|
this.gitCommitHash = output ? output : '?';
|
||||||
|
} else if (gitRevParse.error.code === 'ENOENT') {
|
||||||
|
console.log('git not found, cannot parse git hash');
|
||||||
|
this.gitCommitHash = '?';
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
console.log('Could not load git commit info: ' + e.message);
|
||||||
|
this.gitCommitHash = '?';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
FROM node:16.10.0-buster-slim AS builder
|
FROM node:16.10.0-buster-slim AS builder
|
||||||
|
|
||||||
|
ARG commitHash
|
||||||
|
ENV DOCKER_COMMIT_HASH=${commitHash}
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ if (process.env.DOCKER_COMMIT_HASH) {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const gitRevParse = spawnSync('git', ['rev-parse', '--short', 'HEAD']);
|
const gitRevParse = spawnSync('git', ['rev-parse', '--short', 'HEAD']);
|
||||||
|
|
||||||
if (!gitRevParse.error) {
|
if (!gitRevParse.error) {
|
||||||
gitCommitHash = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, '');
|
const output = gitRevParse.stdout.toString('utf-8').replace(/[\n\r\s]+$/, '');
|
||||||
|
gitCommitHash = output ? output : '?';
|
||||||
console.log(`mempool revision ${gitCommitHash}`);
|
console.log(`mempool revision ${gitCommitHash}`);
|
||||||
} else if (gitRevParse.error.code === 'ENOENT') {
|
} else if (gitRevParse.error.code === 'ENOENT') {
|
||||||
console.log('git not found, cannot parse git hash');
|
console.log('git not found, cannot parse git hash');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user