forked from runs-on/action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
89 lines (72 loc) · 2.39 KB
/
main.go
File metadata and controls
89 lines (72 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"context"
"flag"
"github.com/runs-on/action/internal/cache"
"github.com/runs-on/action/internal/config"
"github.com/runs-on/action/internal/costs"
"github.com/runs-on/action/internal/env"
"github.com/runs-on/action/internal/monitoring"
"github.com/runs-on/action/internal/sccache"
"github.com/sethvargo/go-githubactions"
)
// handleMainExecution contains the original main logic.
func handleMainExecution(action *githubactions.Action, ctx context.Context) {
cfg, err := config.NewConfigFromInputs(action)
if err != nil {
action.Fatalf("Failed to load configuration: %v", err)
}
// Execute logic based on configuration
if cfg.HasShowEnv() {
env.DisplayEnvVars()
}
cache.UpdateZctionsConfig(action, cfg.ActionsResultsURL, cfg.ZctionsResultsURL)
if cfg.HasShowCosts() {
action.Infof("show_costs is enabled. You will find cost details in the post-execution step of this action.")
}
// Configure sccache if requested
if cfg.HasSccache() {
if err := sccache.ConfigureSccache(action, cfg.Sccache); err != nil {
action.Errorf("Failed to configure sccache: %v", err)
}
}
// Configure CloudWatch metrics if requested
if cfg.HasMetrics() {
if err := monitoring.GenerateCloudWatchConfig(action, cfg.Metrics, cfg.NetworkInterface, cfg.DiskDevice); err != nil {
action.Errorf("Failed to configure CloudWatch metrics: %v", err)
}
}
action.Infof("Action finished.")
}
// handlePostExecution contains the logic for the post-execution phase.
func handlePostExecution(action *githubactions.Action, ctx context.Context) {
action.Infof("Running post-execution phase...")
cfg, err := config.NewConfigFromInputs(action)
if err != nil {
action.Errorf("Failed to load configuration in post-execution: %v", err)
return
}
if cfg.HasShowEnv() {
env.DisplayEnvVars()
}
err = costs.ComputeAndDisplayCosts(action, cfg)
if err != nil {
action.Warningf("Failed to compute or display costs: %v", err)
}
// Display metrics summary
if cfg.HasMetrics() {
monitoring.GenerateMetricsSummary(action, cfg.Metrics, "chart", cfg.NetworkInterface, cfg.DiskDevice)
}
action.Infof("Post-execution phase finished.")
}
func main() {
ctx := context.Background()
postFlag := flag.Bool("post", false, "Indicates the post-execution phase")
flag.Parse()
action := githubactions.New()
if *postFlag {
handlePostExecution(action, ctx)
} else {
handleMainExecution(action, ctx)
}
}