Skip to content

Commit 497a00c

Browse files
committed
update go-actions-cache to bd99cf5bbc65 (v2 API)
Brings in initial support for V2 Cache API Signed-off-by: Tonis Tiigi <[email protected]>
1 parent c5d6871 commit 497a00c

File tree

137 files changed

+28611
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+28611
-40
lines changed

cache/remotecache/gha/gha.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"fmt"
88
"io"
99
"os"
10+
"strconv"
11+
"strings"
1012
"sync"
1113
"time"
1214

@@ -39,6 +41,7 @@ const (
3941
attrURL = "url"
4042
attrRepository = "repository"
4143
attrGHToken = "ghtoken"
44+
attrAPIVersion = "version"
4245
version = "1"
4346

4447
defaultTimeout = 10 * time.Minute
@@ -50,6 +53,7 @@ type Config struct {
5053
Token string // token for the Github Cache runtime API
5154
GHToken string // token for the Github REST API
5255
Repository string
56+
Version int
5357
Timeout time.Duration
5458
}
5559

@@ -66,6 +70,23 @@ func getConfig(attrs map[string]string) (*Config, error) {
6670
if !ok {
6771
return nil, errors.Errorf("token not set for github actions cache")
6872
}
73+
var apiVersionInt int
74+
apiVersion, ok := attrs[attrAPIVersion]
75+
if ok {
76+
i, err := strconv.ParseInt(apiVersion, 10, 64)
77+
if err != nil {
78+
return nil, errors.Wrapf(err, "failed to parse api version %q, expected positive integer", apiVersion)
79+
}
80+
apiVersionInt = int(i)
81+
}
82+
// best effort on old clients
83+
if apiVersionInt == 0 {
84+
if strings.Contains(url, "results-receiver.actions.githubusercontent.com") {
85+
apiVersionInt = 2
86+
} else {
87+
apiVersionInt = 1
88+
}
89+
}
6990

7091
timeout := defaultTimeout
7192
if v, ok := attrs[attrTimeout]; ok {
@@ -82,6 +103,7 @@ func getConfig(attrs map[string]string) (*Config, error) {
82103
Timeout: timeout,
83104
GHToken: attrs[attrGHToken],
84105
Repository: attrs[attrRepository],
106+
Version: apiVersionInt,
85107
}, nil
86108
}
87109

@@ -107,7 +129,7 @@ type exporter struct {
107129

108130
func NewExporter(c *Config) (remotecache.Exporter, error) {
109131
cc := v1.NewCacheChains()
110-
cache, err := actionscache.New(c.Token, c.URL, actionscache.Opt{
132+
cache, err := actionscache.New(c.Token, c.URL, c.Version > 1, actionscache.Opt{
111133
Client: tracing.DefaultClient,
112134
Timeout: c.Timeout,
113135
})
@@ -282,7 +304,7 @@ type importer struct {
282304
}
283305

284306
func NewImporter(c *Config) (remotecache.Importer, error) {
285-
cache, err := actionscache.New(c.Token, c.URL, actionscache.Opt{
307+
cache, err := actionscache.New(c.Token, c.URL, c.Version > 1, actionscache.Opt{
286308
Client: tracing.DefaultClient,
287309
Timeout: c.Timeout,
288310
})

cmd/buildctl/build/util.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package build
22

33
import (
44
"os"
5+
"strconv"
56

67
"github.com/pkg/errors"
78

@@ -15,12 +16,30 @@ import (
1516
// environments variables and add it to cache Options
1617
// Since it works for both import and export
1718
func loadGithubEnv(cache client.CacheOptionsEntry) (client.CacheOptionsEntry, error) {
19+
version, ok := cache.Attrs["version"]
20+
if !ok {
21+
if v, ok := os.LookupEnv("ACTIONS_CACHE_SERVICE_V2"); ok {
22+
if b, err := strconv.ParseBool(v); err == nil && b {
23+
version = "2"
24+
cache.Attrs["version"] = version
25+
}
26+
}
27+
}
28+
1829
if _, ok := cache.Attrs["url"]; !ok {
19-
url, ok := os.LookupEnv("ACTIONS_CACHE_URL")
20-
if !ok {
21-
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_CACHE_URL")
30+
if version == "2" {
31+
url, ok := os.LookupEnv("ACTIONS_RESULTS_URL")
32+
if !ok {
33+
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_RESULTS_URL")
34+
}
35+
cache.Attrs["url"] = url
36+
} else {
37+
url, ok := os.LookupEnv("ACTIONS_CACHE_URL")
38+
if !ok {
39+
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_CACHE_URL")
40+
}
41+
cache.Attrs["url"] = url
2242
}
23-
cache.Attrs["url"] = url
2443
}
2544

2645
if _, ok := cache.Attrs["token"]; !ok {

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ require (
7070
github.com/stretchr/testify v1.10.0
7171
github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205
7272
github.com/tonistiigi/fsutil v0.0.0-20250113203817-b14e27f4135a
73-
github.com/tonistiigi/go-actions-cache v0.0.0-20241210095730-017636a73805
73+
github.com/tonistiigi/go-actions-cache v0.0.0-20250211194249-bd99cf5bbc65
7474
github.com/tonistiigi/go-archvariant v1.0.0
7575
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4
7676
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
@@ -111,6 +111,9 @@ require (
111111
require (
112112
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
113113
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20231105174938-2b5cbb29f3e2 // indirect
114+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
115+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
116+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 // indirect
114117
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 // indirect
115118
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 // indirect
116119
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 // indirect

go.sum

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8af
33
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
44
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20231105174938-2b5cbb29f3e2 h1:dIScnXFlF784X79oi7MzVT6GWqr/W1uUt0pB5CsDs9M=
55
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20231105174938-2b5cbb29f3e2/go.mod h1:gCLVsLfv1egrcZu+GoJATN5ts75F2s62ih/457eWzOw=
6+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M=
7+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0/go.mod h1:YL1xnZ6QejvQHWJrX/AvhFl4WW4rqHVoKspWNVwFk0M=
8+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 h1:B/dfvscEQtew9dVuoxqxrUKKv8Ih2f55PydknDamU+g=
9+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0/go.mod h1:fiPSssYvltE08HJchL04dOy+RD4hgrjph0cwGGMntdI=
10+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=
11+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY=
12+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0 h1:PiSrjRPpkQNjrM8H0WwKMnZUdu1RGMtd/LdGKUrOo+c=
13+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0/go.mod h1:oDrbWx4ewMylP7xHivfgixbfGBT6APAwsSoHRKotnIc=
14+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 h1:mlmW46Q0B79I+Aj4azKC6xDMFN9a9SyZWESlGWYXbFs=
15+
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0/go.mod h1:PXe2h+LKcWTX9afWdZoHyODqR4fBa5boUM/8uJfZ0Jo=
616
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
717
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
18+
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU=
19+
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
820
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
921
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
1022
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
@@ -308,6 +320,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
308320
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
309321
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw3fD4oEoeorXc6saIiQ23LrGLth0Gw=
310322
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
323+
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
324+
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
311325
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
312326
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
313327
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -377,8 +391,8 @@ github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205 h1:eUk79E1
377391
github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205/go.mod h1:3Iuxbr0P7D3zUzBMAZB+ois3h/et0shEz0qApgHYGpY=
378392
github.com/tonistiigi/fsutil v0.0.0-20250113203817-b14e27f4135a h1:EfGw4G0x/8qXWgtcZ6KVaPS+wpWOQMaypczzP8ojkMY=
379393
github.com/tonistiigi/fsutil v0.0.0-20250113203817-b14e27f4135a/go.mod h1:Dl/9oEjK7IqnjAm21Okx/XIxUCFJzvh+XdVHUlBwXTw=
380-
github.com/tonistiigi/go-actions-cache v0.0.0-20241210095730-017636a73805 h1:l2x1Ubj8f5xhPzZI428ZQ6+BDafGovpdk2ITnD3twTw=
381-
github.com/tonistiigi/go-actions-cache v0.0.0-20241210095730-017636a73805/go.mod h1:xsu+XeKT9piH/5f9Y1Zsv5krQqI34CWkIusbs5027IM=
394+
github.com/tonistiigi/go-actions-cache v0.0.0-20250211194249-bd99cf5bbc65 h1:57xLt2zJ6in5Au6plQUKm1gfasse4j3h9lrvoor2xPs=
395+
github.com/tonistiigi/go-actions-cache v0.0.0-20250211194249-bd99cf5bbc65/go.mod h1:h0oRlVs3NoFIHysRQ4rU1+RG4QmU0M2JVSwTYrB4igk=
382396
github.com/tonistiigi/go-archvariant v1.0.0 h1:5LC1eDWiBNflnTF1prCiX09yfNHIxDC/aukdhCdTyb0=
383397
github.com/tonistiigi/go-archvariant v1.0.0/go.mod h1:TxFmO5VS6vMq2kvs3ht04iPXtu2rUT/erOnGFYfk5Ho=
384398
github.com/tonistiigi/go-csvvalue v0.0.0-20240710180619-ddb21b71c0b4 h1:7I5c2Ig/5FgqkYOh/N87NzoyI9U15qUPXhDD8uCupv8=

0 commit comments

Comments
 (0)