Skip to content

Commit 0052b66

Browse files
committed
fix: construct absolute paths
1 parent 834f091 commit 0052b66

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

advisories/V8-advisory.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schema_version": "1.6.7",
33
"id": "V8",
4-
"modified": "2025-01-24T11:43:39+01:00",
4+
"modified": "2025-01-24T14:25:05+01:00",
55
"published": "2024-11-22T16:36:05+01:00",
66
"summary": "https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/security/updates.md",
77
"details": "Dependency on outdated V8 found. Please update to the latest beta, stable, or extended stable versions.",

src/V8-cache.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"d458198c60d6f63bfdf80e2ce0d3a6b7e496c710"
1616
],
1717
"2025-01-24": [
18-
"8afc4bb6114b959f0ac400041a73c9dd0ada1e39",
1918
"7b97c21ae1cde63a0ca1f1a2d3459ea758adaac0",
20-
"685de311c1e4a25951ee1bb3c88fcca0726a4e95"
19+
"685de311c1e4a25951ee1bb3c88fcca0726a4e95",
20+
"155e22e0bb76706f997c4db28f899b91957818f3"
2121
]
2222
}

src/main.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,31 @@ type Advisory struct {
6161
Affected []AffectedItem `json:"affected"`
6262
}
6363

64+
const (
65+
policyBasePath = "policies/V8-policy.json"
66+
cacheBasePath = "src/V8-cache.json"
67+
advisoryBasePath = "advisories/V8-advisory.json"
68+
)
69+
6470
var (
6571
now = time.Now()
6672
nowTimestamp = now.Format(time.RFC3339)
6773
today = format(now)
68-
policyPath = "policies/V8-policy.json"
69-
cachePath = "src/V8-cache.json"
70-
advisoryPath = "advisories/V8-advisory.json"
74+
dir string
75+
policyPath string
76+
cachePath string
77+
advisoryPath string
7178
)
7279

7380
type Repositories interface {
7481
ListCommits(ctx context.Context, owner, repo string, opts *github.CommitsListOptions) ([]*github.RepositoryCommit, *github.Response, error)
7582
}
7683

7784
func main() {
85+
// Construct absolute path of the runner.
86+
_, filename, _, _ := runtime.Caller(0)
87+
dir = filepath.Dir(filename)
88+
7889
policy, err := loadPolicy()
7990
if err != nil {
8091
panic(err)
@@ -112,10 +123,8 @@ func main() {
112123
}
113124

114125
func loadPolicy() (*Policy, error) {
115-
_, filename, _, _ := runtime.Caller(0)
116-
dir := filepath.Dir(filename)
117-
advisoryFilePath := filepath.Join(dir, "../advisories/V8-advisory.json")
118-
data, err := os.ReadFile(advisoryFilePath)
126+
policyPath = filepath.Join(dir, "../", policyBasePath)
127+
data, err := os.ReadFile(policyPath)
119128
if err != nil {
120129
return nil, err
121130
}
@@ -131,6 +140,7 @@ func loadPolicy() (*Policy, error) {
131140

132141
func loadCache() (map[string][]string, error) {
133142
cacheData := make(map[string][]string)
143+
cachePath = filepath.Join(dir, "../", cacheBasePath)
134144
data, err := os.ReadFile(cachePath)
135145
if err != nil {
136146
if !os.IsNotExist(err) {
@@ -146,7 +156,6 @@ func loadCache() (map[string][]string, error) {
146156
}
147157

148158
func saveCache(cacheData map[string][]string) error {
149-
150159
updatedData, err := json.MarshalIndent(cacheData, "", " ")
151160
if err != nil {
152161
return fmt.Errorf("error marshalling cache data: %w", err)
@@ -159,6 +168,7 @@ func saveCache(cacheData map[string][]string) error {
159168
}
160169

161170
func loadAdvisory() (*Advisory, error) {
171+
advisoryPath = filepath.Join(dir, "../", advisoryBasePath)
162172
advisoryData, err := os.ReadFile(advisoryPath)
163173
var advisory Advisory
164174
if err == nil {

0 commit comments

Comments
 (0)