-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add contracts git version to DB (#76)
- Loading branch information
Showing
10 changed files
with
161 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const tagFile = "git-tag.txt"; | ||
export const tagFilePath = `${process.cwd()}/artifacts/${tagFile}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import fs from "fs"; | ||
import { tagFilePath } from "./constants"; | ||
import { getLogger } from "../../deploy/logger/create-logger"; | ||
|
||
|
||
const logger = getLogger(); | ||
|
||
export const getGitTag = () => { | ||
if (!fs.existsSync(tagFilePath)) { | ||
throw Error(`No git tag found at ${tagFilePath}`); | ||
} | ||
|
||
const tag = fs.readFileSync(tagFilePath, "utf8").trim(); | ||
logger.info(`Git tag found at ${tagFilePath}: ${tag}`); | ||
|
||
return tag; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
tag=$(git describe --tags --abbrev=0) | ||
echo "Last tag: $tag" | ||
commit=$(git rev-list -n 1 "$tag") | ||
echo "Commit: $commit" | ||
echo "$tag:$commit" > ./artifacts/git-tag.txt | ||
echo "Git tag saved to ./artifacts/git-tag.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { exec } from "child_process"; | ||
import { promisify } from "util"; | ||
import { getLogger } from "../../deploy/logger/create-logger"; | ||
import fs from "fs"; | ||
import { tagFilePath } from "./constants"; | ||
|
||
|
||
const execAsync = promisify(exec); | ||
const logger = getLogger(); | ||
|
||
|
||
const acquireLatestGitTag = async () => { | ||
const gitTag = await execAsync("git describe --tags --abbrev=0"); | ||
const tag = gitTag.stdout.trim(); | ||
|
||
logger.info(`Latest git tag acquired: ${tag}`); | ||
|
||
const commitHash = await execAsync(`git rev-list -n 1 ${tag}`); | ||
const commit = commitHash.stdout.trim(); | ||
|
||
const full = `${tag}:${commit}`; | ||
logger.info(`Git commit hash acquired for tag: ${commit}. Full: ${full}`); | ||
|
||
return full; | ||
}; | ||
|
||
const saveTag = async () => { | ||
const tag = await acquireLatestGitTag(); | ||
|
||
fs.writeFileSync(tagFilePath, tag, "utf8"); | ||
logger.info(`Saved git tag-commit to ${tagFilePath}}`); | ||
}; | ||
|
||
saveTag() | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
.then(process.exit(0)) | ||
.catch(e => { | ||
logger.error(e); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters