Skip to content

Commit ee93c84

Browse files
authored
Ignore interpolated references during parsing (#97)
This fixes the issue where Ratchet completely fails because there's a GitHub Actions reference that uses interpolation. Those references will now be ignored.
1 parent d04d673 commit ee93c84

File tree

7 files changed

+77
-40
lines changed

7 files changed

+77
-40
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515
release:
1616
runs-on: 'ubuntu-latest'
1717
steps:
18-
- uses: 'docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf' # ratchet:docker/setup-qemu-action@v3
18+
- uses: 'docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a' # ratchet:docker/setup-qemu-action@v3
1919

2020
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
2121
with:
2222
fetch-depth: 0
2323

24-
- uses: 'actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed' # ratchet:actions/setup-go@v5
24+
- uses: 'actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34' # ratchet:actions/setup-go@v5
2525
with:
2626
go-version-file: 'go.mod'
2727

@@ -39,7 +39,7 @@ jobs:
3939
env:
4040
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
4141

42-
- uses: 'actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018' # ratchet:actions/attest-build-provenance@v1
42+
- uses: 'actions/attest-build-provenance@520d128f165991a6c774bcb264f323e3d70747f4' # ratchet:actions/attest-build-provenance@v2
4343
with:
4444
subject-path: |-
4545
dist/*.tar.gz

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
2121

22-
- uses: 'actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed' # ratchet:actions/setup-go@v5
22+
- uses: 'actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34' # ratchet:actions/setup-go@v5
2323
with:
2424
go-version-file: 'go.mod'
2525

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ only applies to the line on which it appears.
262262
possible, but most CI systems also don't support these advanced YAML
263263
features.
264264

265-
Similarly, Ratchet does not support matrix-style expansion, since those
265+
Similarly, Ratchet does not support expansion or inteprolation, since those
266266
values cannot be guaranteed to be known at compile time. For example,
267-
Ratchet will error on the following GitHub Actions workflow:
267+
Ratchet will ignore the following `${{ }}` reference in a GitHub Actions
268+
workflow:
268269

269270
```yaml
270271
jobs:

go.mod

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
module github.com/sethvargo/ratchet
22

3-
go 1.22.0
3+
go 1.23.0
44

5-
toolchain go1.23.3
5+
toolchain go1.23.5
66

77
require (
88
github.com/braydonk/yaml v0.7.0
99
github.com/google/go-cmp v0.6.0
10-
github.com/google/go-containerregistry v0.20.2
10+
github.com/google/go-containerregistry v0.20.3
1111
github.com/google/go-github/v58 v58.0.0
12-
golang.org/x/oauth2 v0.24.0
13-
golang.org/x/sync v0.9.0
12+
golang.org/x/oauth2 v0.25.0
13+
golang.org/x/sync v0.10.0
1414
)
1515

1616
require (
17-
github.com/containerd/stargz-snapshotter/estargz v0.16.1 // indirect
18-
github.com/docker/cli v27.3.1+incompatible // indirect
17+
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
18+
github.com/docker/cli v27.5.1+incompatible // indirect
1919
github.com/docker/distribution v2.8.3+incompatible // indirect
2020
github.com/docker/docker-credential-helpers v0.8.2 // indirect
2121
github.com/google/go-querystring v1.1.0 // indirect
2222
github.com/klauspost/compress v1.17.11 // indirect
23-
github.com/kr/pretty v0.3.1 // indirect
2423
github.com/mitchellh/go-homedir v1.1.0 // indirect
2524
github.com/opencontainers/go-digest v1.0.0 // indirect
2625
github.com/opencontainers/image-spec v1.1.0 // indirect
2726
github.com/pkg/errors v0.9.1 // indirect
2827
github.com/sirupsen/logrus v1.9.3 // indirect
29-
github.com/vbatts/tar-split v0.11.6 // indirect
30-
golang.org/x/sys v0.27.0 // indirect
28+
github.com/vbatts/tar-split v0.11.7 // indirect
29+
golang.org/x/sys v0.29.0 // indirect
3130
)

go.sum

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,55 @@
11
github.com/braydonk/yaml v0.7.0 h1:ySkqO7r0MGoCNhiRJqE0Xe9yhINMyvOAB3nFjgyJn2k=
22
github.com/braydonk/yaml v0.7.0/go.mod h1:hcm3h581tudlirk8XEUPDBAimBPbmnL0Y45hCRl47N4=
3-
github.com/containerd/stargz-snapshotter/estargz v0.16.1 h1:7YswwU6746cJBN3p3l65JRk3+NZL7bap9Y6E3YeYowk=
4-
github.com/containerd/stargz-snapshotter/estargz v0.16.1/go.mod h1:uyr4BfYfOj3G9WBVE8cOlQmXAbPN9VEQpBBeJIuOipU=
5-
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
3+
github.com/containerd/stargz-snapshotter/estargz v0.16.3 h1:7evrXtoh1mSbGj/pfRccTampEyKpjpOnS3CyiV1Ebr8=
4+
github.com/containerd/stargz-snapshotter/estargz v0.16.3/go.mod h1:uyr4BfYfOj3G9WBVE8cOlQmXAbPN9VEQpBBeJIuOipU=
65
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
76
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
87
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9-
github.com/docker/cli v27.3.1+incompatible h1:qEGdFBF3Xu6SCvCYhc7CzaQTlBmqDuzxPDpigSyeKQQ=
10-
github.com/docker/cli v27.3.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
8+
github.com/docker/cli v27.5.1+incompatible h1:JB9cieUT9YNiMITtIsguaN55PLOHhBSz3LKVc6cqWaY=
9+
github.com/docker/cli v27.5.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
1110
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
1211
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
1312
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
1413
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
1514
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1615
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1716
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
18-
github.com/google/go-containerregistry v0.20.2 h1:B1wPJ1SN/S7pB+ZAimcciVD+r+yV/l/DSArMxlbwseo=
19-
github.com/google/go-containerregistry v0.20.2/go.mod h1:z38EKdKh4h7IP2gSfUUqEvalZBqs6AoLeWfUy34nQC8=
17+
github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI=
18+
github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI=
2019
github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw=
2120
github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4=
2221
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
2322
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
2423
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
2524
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
26-
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
27-
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
28-
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
29-
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
3025
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
3126
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
3227
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
3328
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
3429
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
3530
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
36-
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
3731
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
3832
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3933
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4034
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
41-
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
42-
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
4335
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
4436
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
4537
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4638
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4739
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
4840
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
49-
github.com/vbatts/tar-split v0.11.6 h1:4SjTW5+PU11n6fZenf2IPoV8/tz3AaYHMWjf23envGs=
50-
github.com/vbatts/tar-split v0.11.6/go.mod h1:dqKNtesIOr2j2Qv3W/cHjnvk9I8+G7oAkFDFN6TCBEI=
51-
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
52-
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
53-
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
54-
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
41+
github.com/vbatts/tar-split v0.11.7 h1:ixZ93pO/GmvaZw4Vq9OwmfZK/kc2zKdPfu0B+gYqs3U=
42+
github.com/vbatts/tar-split v0.11.7/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA=
43+
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
44+
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
45+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
46+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
5547
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
56-
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
57-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
48+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
49+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5850
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
51+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
5952
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
60-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
61-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
6253
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6354
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
6455
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

parser/actions.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func (a *Actions) parseOne(refs *RefsList, node *yaml.Node) error {
8282
for k, property := range step.Content {
8383
if property.Value == "uses" {
8484
uses := step.Content[k+1]
85+
// Ignore interpolations, since we cannot resolve most of
86+
// their values.
87+
if strings.Contains(uses.Value, "${{") {
88+
continue
89+
}
90+
8591
// Only include references to remote workflows. This could be
8692
// a local workflow, which should not be pinned.
8793
switch {
@@ -119,6 +125,13 @@ func (a *Actions) parseOne(refs *RefsList, node *yaml.Node) error {
119125
for k, property := range containerMap.Content {
120126
if property.Value == "image" {
121127
image := containerMap.Content[k+1]
128+
129+
// Ignore interpolations, since we cannot resolve most of
130+
// their values.
131+
if strings.Contains(image.Value, "${{") {
132+
continue
133+
}
134+
122135
ref := resolver.NormalizeContainerRef(image.Value)
123136
refs.Add(ref, image)
124137
break
@@ -138,6 +151,13 @@ func (a *Actions) parseOne(refs *RefsList, node *yaml.Node) error {
138151
for k, property := range subMap.Content {
139152
if property.Value == "image" {
140153
image := subMap.Content[k+1]
154+
155+
// Ignore interpolations, since we cannot resolve most of
156+
// their values.
157+
if strings.Contains(image.Value, "${{") {
158+
continue
159+
}
160+
141161
ref := resolver.NormalizeContainerRef(image.Value)
142162
refs.Add(ref, image)
143163
break
@@ -157,6 +177,13 @@ func (a *Actions) parseOne(refs *RefsList, node *yaml.Node) error {
157177
for k, property := range step.Content {
158178
if property.Value == "uses" {
159179
uses := step.Content[k+1]
180+
181+
// Ignore interpolations, since we cannot resolve most of
182+
// their values.
183+
if strings.Contains(uses.Value, "${{") {
184+
continue
185+
}
186+
160187
// Only include references to remote workflows. This could be
161188
// a local workflow, which should not be pinned.
162189
switch {
@@ -176,6 +203,12 @@ func (a *Actions) parseOne(refs *RefsList, node *yaml.Node) error {
176203
if sub.Value == "uses" {
177204
uses := jobMap.Content[j+1]
178205

206+
// Ignore interpolations, since we cannot resolve most of
207+
// their values.
208+
if strings.Contains(uses.Value, "${{") {
209+
continue
210+
}
211+
179212
// Only include references to remote workflows. This could be a
180213
// local workflow, which should not be pinned.
181214
switch {

parser/actions_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ runs:
9191
"container://ubuntu@sha256:47f14534bda344d9fe6ffd6effb95eefe579f4be0d508b7445cf77f61a0e5724",
9292
},
9393
},
94+
{
95+
name: "ignores_interpolated",
96+
in: `
97+
jobs:
98+
my_job:
99+
container:
100+
image: 'ghcr.io/${{ github.repository }}/container:1.2.3'
101+
steps:
102+
- uses: 'actions/${{ github.sha }}'
103+
104+
`,
105+
exp: []string{},
106+
},
94107
}
95108

96109
for _, tc := range cases {

0 commit comments

Comments
 (0)