@@ -4,32 +4,51 @@ import { fileURLToPath } from "node:url";
44import { extraArgs } from "./config.ts" ;
55import { precompile } from "./precompile.ts" ;
66import { typst } from "./typst.ts" ;
7- import { duration_fmt } from "./util.ts" ;
7+ import { duration_fmt , execFile } from "./util.ts" ;
8+
9+ interface GitInfo {
10+ name : string ;
11+ commit_url : string ;
12+ log_url : string ;
13+ /** latest git log */
14+ latest_log : string ;
15+ }
16+
17+ async function git_info ( ) : Promise < GitInfo | null > {
18+ const git_log = execFile ( "git" , [
19+ "log" ,
20+ "--max-count=1" ,
21+ "--pretty=fuller" ,
22+ "--date=iso" ,
23+ ] ) . then ( ( { stdout } ) => stdout . trim ( ) ) ;
824
9- function git_info ( ) : string [ ] {
1025 if ( env . GITHUB_ACTIONS === "true" ) {
1126 // https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
1227 const base = `${ env . GITHUB_SERVER_URL } /${ env . GITHUB_REPOSITORY } ` ;
13- const info = {
14- name : `${ env . GITHUB_SHA ?. slice ( 0 , 8 ) } (${ env . GITHUB_REF } )` ,
28+ return {
29+ name : `${ env . GITHUB_SHA ?. slice ( 0 , 8 ) } (${ env . GITHUB_REF_NAME } )` ,
1530 commit_url : `${ base } /commit/${ env . GITHUB_SHA } ` ,
1631 log_url : `${ base } /actions/runs/${ env . GITHUB_RUN_ID } ` ,
32+ latest_log : await git_log ,
1733 } ;
18- return [ "--input" , `git=${ JSON . stringify ( info ) } ` ] ;
1934 } else if ( env . NETLIFY === "true" ) {
2035 // https://docs.netlify.com/configure-builds/environment-variables/
21- const info = {
36+ return {
2237 name : `${ env . COMMIT_REF ?. slice ( 0 , 8 ) } (${ env . HEAD } )` ,
2338 commit_url : `${ env . REPOSITORY_URL } /commit/${ env . COMMIT_REF } ` ,
2439 log_url :
2540 `https://app.netlify.com/sites/${ env . SITE_NAME } /deploys/${ env . DEPLOY_ID } ` ,
41+ latest_log : await git_log ,
2642 } ;
27- return [ "--input" , `git=${ JSON . stringify ( info ) } ` ] ;
2843 } else {
29- return [ ] ;
44+ return null ;
3045 }
3146}
3247
48+ function as_input ( info : GitInfo | null ) : string [ ] {
49+ return info ? [ "--input" , `git=${ JSON . stringify ( info ) } ` ] : [ ] ;
50+ }
51+
3352if ( process . argv [ 1 ] === fileURLToPath ( import . meta. url ) ) {
3453 await precompile ( ) ;
3554
@@ -38,7 +57,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
3857 "compile" ,
3958 "index.typ" ,
4059 "dist/index.html" ,
41- ...git_info ( ) ,
60+ ...as_input ( await git_info ( ) ) ,
4261 ...extraArgs . build ,
4362 ] ) ;
4463 console . log (
0 commit comments