@@ -3,6 +3,10 @@ package project
3
3
import (
4
4
"fmt"
5
5
"log/slog"
6
+ "os"
7
+
8
+ "github.com/input-output-hk/catalyst-forge/lib/tools/argo"
9
+ tg "github.com/input-output-hk/catalyst-forge/lib/tools/git"
6
10
7
11
"cuelang.org/go/cue"
8
12
"github.com/go-git/go-git/v5"
@@ -55,15 +59,31 @@ func GetDefaultRuntimes(logger *slog.Logger) []RuntimeData {
55
59
56
60
// getCommitHash returns the commit hash of the HEAD commit.
57
61
func getCommitHash (repo * git.Repository ) (string , error ) {
58
- ref , err := repo .Head ()
59
- if err != nil {
60
- return "" , fmt .Errorf ("failed to get HEAD: %w" , err )
61
- }
62
+ if tg .InCI () {
63
+ v , exists := os .LookupEnv ("GITHUB_SHA" )
64
+ if ! exists {
65
+ return "" , fmt .Errorf ("GITHUB_SHA not found in environment" )
66
+ }
62
67
63
- obj , err := repo .CommitObject (ref .Hash ())
64
- if err != nil {
65
- return "" , fmt .Errorf ("failed to get commit object: %w" , err )
66
- }
68
+ return v , nil
69
+ } else if argo .InArgo () {
70
+ v , exists := os .LookupEnv ("ARGOCD_APP_REVISION" )
71
+ if ! exists {
72
+ return "" , fmt .Errorf ("ARGOCD_APP_REVISION not found in environment" )
73
+ }
67
74
68
- return obj .Hash .String (), nil
75
+ return v , nil
76
+ } else {
77
+ ref , err := repo .Head ()
78
+ if err != nil {
79
+ return "" , fmt .Errorf ("failed to get HEAD: %w" , err )
80
+ }
81
+
82
+ obj , err := repo .CommitObject (ref .Hash ())
83
+ if err != nil {
84
+ return "" , fmt .Errorf ("failed to get commit object: %w" , err )
85
+ }
86
+
87
+ return obj .Hash .String (), nil
88
+ }
69
89
}
0 commit comments