@@ -68,21 +68,33 @@ task downloadProtoFiles {
6868
6969 doLast {
7070 def protoDir = file(" ${ rootProject.projectDir} /internal/durabletask-protobuf/protos" )
71+ def protoFile = new File (protoDir, ' orchestrator_service.proto' )
72+ def commitHashFile = new File (" ${ rootProject.projectDir} /internal/durabletask-protobuf/PROTO_SOURCE_COMMIT_HASH" )
7173 protoDir. mkdirs()
7274
7375 // Download the proto file
7476 new URL (" https://raw.githubusercontent.com/dapr/durabletask-protobuf/${ ext.branch} /protos/orchestrator_service.proto" )
7577 .withInputStream { i ->
76- new File (protoDir, ' orchestrator_service.proto ' ) . withOutputStream { it << i }
78+ protoFile . withOutputStream { it << i }
7779 }
78-
79- // Get and save the commit hash
80- def commitHashFile = new File (" ${ rootProject.projectDir} /internal/durabletask-protobuf/PROTO_SOURCE_COMMIT_HASH" )
81- def commitApiUrl = new URL (" https://api.github.com/repos/dapr/durabletask-protobuf/commits?path=protos/orchestrator_service.proto&sha=${ ext.branch} &per_page=1" )
82- def connection = commitApiUrl. openConnection()
83- connection. setRequestProperty(' Accept' , ' application/vnd.github.v3+json' )
84- def commitHash = new groovy.json.JsonSlurper (). parse(connection. inputStream)[0 ]. sha
85- commitHashFile. text = commitHash
80+
81+ try {
82+ def commitApiUrl = new URL (" https://api.github.com/repos/dapr/durabletask-protobuf/commits?path=protos/orchestrator_service.proto&sha=${ ext.branch} &per_page=1" )
83+ def connection = commitApiUrl. openConnection()
84+ connection. setRequestProperty(' Accept' , ' application/vnd.github.v3+json' )
85+ connection. setRequestProperty(' User-Agent' , ' durabletask-java-build' )
86+
87+ // Add GitHub token if available (automatically provided in GitHub Actions)
88+ if (System . env. GITHUB_TOKEN ) {
89+ connection. setRequestProperty(' Authorization' , " token ${ System.env.GITHUB_TOKEN} " )
90+ }
91+
92+ def commitHash = new groovy.json.JsonSlurper (). parse(connection. inputStream)[0 ]. sha
93+ commitHashFile. text = commitHash
94+ logger. info(" Successfully updated proto commit hash: ${ commitHash} " )
95+ } catch (Exception e) {
96+ logger. error(" Failed to fetch commit hash from GitHub API: ${ e.message} " )
97+ }
8698 }
8799}
88100
0 commit comments