-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide
VERSION
file with asset bundle, read in application (#3148)
* Add documentation / comments on new build options
- Loading branch information
1 parent
e3c5c59
commit 8400176
Showing
7 changed files
with
185 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules | |
/flow-typed | ||
.vscode | ||
bash | ||
public/VERSION |
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,40 @@ | ||
#!/usr/bin/env node | ||
import { execSync } from "child_process"; | ||
import { writeFileSync } from "fs"; | ||
import fetch from "node-fetch"; | ||
|
||
async function getLatestReleaseVersion() { | ||
const res = await fetch( | ||
"https://api.github.com/repos/Kinto/kinto-admin/releases/latest", | ||
{ headers: { "user-agent": "Kinto Admin CI" } } // `user-agent` header required by Github API | ||
); | ||
const body = await res.json(); | ||
return body.tag_name.replace(/^v/, ""); | ||
} | ||
|
||
const getGitVersion = () => { | ||
try { | ||
return execSync("git describe --tags --abbrev=4", { | ||
encoding: "utf-8", | ||
}) | ||
.trim() | ||
.replace(/^v/, ""); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
(async () => { | ||
/** | ||
* The `KINTO_ADMIN_VERSION` env var is used when someone wants to download | ||
* an earlier release and build assets from source. Since they won't be in a | ||
* `git` directory to be able to pull version information from the latest | ||
* tag, this allows them to inject the version they're downloading into the bundle. | ||
*/ | ||
const version = | ||
process.env.KINTO_ADMIN_VERSION || | ||
getGitVersion() || | ||
(await getLatestReleaseVersion()); | ||
|
||
writeFileSync("./public/VERSION", version); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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