Skip to content

Commit 522b070

Browse files
zshannonclaude
andcommitted
feat: Add git commit hash tracking to server build
- Inject git commit SHA via build-time ldflags - Add X-Git-Commit and X-Server-Version response headers - Update typescript-go API compatibility for latest version - Add Chtimes method for vfs.VFS interface compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent ae6611f commit 522b070

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

.github/workflows/deploy-server.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ jobs:
4444
flyctl deploy --remote-only \
4545
--config server/fly.toml \
4646
--dockerfile server/Dockerfile \
47-
--build-arg BUILDKIT_INLINE_CACHE=1
47+
--build-arg BUILDKIT_INLINE_CACHE=1 \
48+
--build-arg GIT_COMMIT=${{ github.sha }}

server/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM --platform=linux/x86_64 golang:1.24-bookworm AS build
22

3+
# Accept git commit as build argument
4+
ARG GIT_COMMIT=unknown
5+
36
WORKDIR /workspace
47

58
# Copy only what's needed for the Go module
@@ -15,7 +18,7 @@ RUN set -xe; \
1518
go build \
1619
-mod=readonly \
1720
-buildmode=pie \
18-
-ldflags "-linkmode external -extldflags -static-pie" \
21+
-ldflags "-linkmode external -extldflags -static-pie -X main.gitCommit=${GIT_COMMIT}" \
1922
-tags netgo \
2023
-o /server .
2124

server/server.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ import (
2525
lru "github.com/hashicorp/golang-lru/v2"
2626
"github.com/microsoft/typescript-go/internal/ast"
2727
"github.com/microsoft/typescript-go/internal/bundled"
28-
"github.com/microsoft/typescript-go/internal/collections"
2928
"github.com/microsoft/typescript-go/internal/compiler"
3029
"github.com/microsoft/typescript-go/internal/core"
30+
"github.com/microsoft/typescript-go/internal/execute/tsc"
3131
"github.com/microsoft/typescript-go/internal/tsoptions"
32-
"github.com/microsoft/typescript-go/internal/tspath"
3332
"github.com/microsoft/typescript-go/internal/vfs"
3433
)
3534

3635
var (
3736
serverVersion = "1.0.0"
3837
startTime = time.Now()
38+
gitCommit = "unknown" // Set at build time with -ldflags
3939

4040
// S3 client and configuration
4141
s3Client *s3.Client
@@ -631,6 +631,12 @@ func (fs *s3FS) Remove(path string) error {
631631
return nil
632632
}
633633

634+
func (fs *s3FS) Chtimes(path string, aTime time.Time, mTime time.Time) error {
635+
// S3-backed file system doesn't support changing file times
636+
// This is a no-op implementation for compatibility
637+
return nil
638+
}
639+
634640
func (fs *s3FS) DirectoryExists(path string) bool {
635641
if path == "/" || path == "" {
636642
return true
@@ -726,10 +732,10 @@ func typecheckTypeScript(code string, version string) TypecheckResponse {
726732
}
727733

728734
// Create cache
729-
extendedConfigCache := &collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry]{}
735+
extendedConfigCache := &tsc.ExtendedConfigCache{}
730736

731737
// Create host
732-
host := compiler.NewCachedFSCompilerHost("/", wrappedFS, bundled.LibPath(), extendedConfigCache)
738+
host := compiler.NewCachedFSCompilerHost("/", wrappedFS, bundled.LibPath(), extendedConfigCache, nil)
733739

734740
// Create program
735741
program := compiler.NewProgram(compiler.ProgramOptions{
@@ -981,6 +987,10 @@ func loggingMiddleware(next http.HandlerFunc) http.HandlerFunc {
981987
return func(w http.ResponseWriter, r *http.Request) {
982988
start := time.Now()
983989

990+
// Add git commit header to all responses
991+
w.Header().Set("X-Git-Commit", gitCommit)
992+
w.Header().Set("X-Server-Version", serverVersion)
993+
984994
// Create a custom response writer to capture status code
985995
lrw := &loggingResponseWriter{ResponseWriter: w, statusCode: http.StatusOK}
986996

0 commit comments

Comments
 (0)