Skip to content

Commit 89d18ae

Browse files
committed
Add support against supply attack in Gat
Add support against supply attack in Gat, and output sha ids instead of `uses` tags.
1 parent 128f0af commit 89d18ae

File tree

6 files changed

+184
-134
lines changed

6 files changed

+184
-134
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ new Workflow("My first workflow")
3939
},
4040
],
4141
})
42-
.compile('my-first-workflow.yml');
42+
.compile("my-first-workflow.yml");
4343
```
4444

4545
Notice that you need to call the `compile()` method at the end, passing the file name of the generated Github Actions workflow.
@@ -52,12 +52,6 @@ You can build your templates running this command in your root folder:
5252
npx gat build
5353
```
5454

55-
Alternatively you can also compile a single template:
56-
57-
```bash
58-
npx gat build .github/templates/some-workflow.ts
59-
```
60-
6155
Following the previous example, you should see now a file `.github/workflows/my-first-workflow.yml` like this:
6256

6357
```yaml

src/__snapshots__/workflow.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ jobs:
204204
runs-on: ubuntu-22.04
205205
timeout-minutes: 15
206206
steps:
207-
- uses: actions/checkout@v3
207+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
208208
with:
209209
ref: main
210210
"

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ cli
2525
await execPromise(
2626
`npx ts-node ${process.env["GAT_BUILD_FLAGS"] ?? "--swc -T"} ${path.join(
2727
folder,
28-
"index.ts"
29-
)}`
28+
"index.ts",
29+
)}`,
3030
);
3131

3232
process.exit(0);

src/step.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ export interface UseStep extends BaseStep {
1818
uses: string;
1919
with?: Record<string, string | number | boolean>;
2020
}
21+
22+
export const isUseStep = (step: Step): step is UseStep => {
23+
return (step as UseStep).uses !== undefined;
24+
};

src/workflow.spec.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RunStep, UseStep } from "./step";
33
import { Workflow } from "./workflow";
44

55
describe("Workflow", () => {
6-
it("generates a simple workflow", () => {
6+
it("generates a simple workflow", async () => {
77
const workflow = new Workflow("Simple");
88
workflow
99
.on("pull_request", { types: ["opened"] })
@@ -15,21 +15,21 @@ describe("Workflow", () => {
1515
dependsOn: ["job1"],
1616
});
1717

18-
expect(workflow.compile()).toMatchSnapshot();
18+
expect(await workflow.compile()).toMatchSnapshot();
1919
});
2020

21-
it("allows multiple events", () => {
21+
it("allows multiple events", async () => {
2222
const workflow = new Workflow("Multiple events");
2323
workflow
2424
.on("push", { branches: ["main"] })
2525
.on("pull_request", { types: ["opened"] })
2626
.addJob("job1", {
2727
steps: [{ name: "Do something", run: "exit 0" }],
2828
});
29-
expect(workflow.compile()).toMatchSnapshot();
29+
expect(await workflow.compile()).toMatchSnapshot();
3030
});
3131

32-
it("allows declaring default options", () => {
32+
it("allows declaring default options", async () => {
3333
const workflow = new Workflow("Default options");
3434
workflow
3535
.on("push", { branches: ["main"] })
@@ -39,10 +39,10 @@ describe("Workflow", () => {
3939
.addJob("job1", {
4040
steps: [{ name: "Do something", run: "exit 0" }],
4141
});
42-
expect(workflow.compile()).toMatchSnapshot();
42+
expect(await workflow.compile()).toMatchSnapshot();
4343
});
4444

45-
it("allows declaring environment variables", () => {
45+
it("allows declaring environment variables", async () => {
4646
const workflow = new Workflow("With Environment variables");
4747
workflow
4848
.on("push")
@@ -56,10 +56,10 @@ describe("Workflow", () => {
5656
},
5757
],
5858
});
59-
expect(workflow.compile()).toMatchSnapshot();
59+
expect(await workflow.compile()).toMatchSnapshot();
6060
});
6161

62-
it("allows using a concurrency group", () => {
62+
it("allows using a concurrency group", async () => {
6363
const workflow = new Workflow("Concurrency group");
6464
workflow.on("push").addJob("job1", {
6565
concurrency: {
@@ -72,10 +72,10 @@ describe("Workflow", () => {
7272
},
7373
],
7474
});
75-
expect(workflow.compile()).toMatchSnapshot();
75+
expect(await workflow.compile()).toMatchSnapshot();
7676
});
7777

78-
it("allows using outputs", () => {
78+
it("allows using outputs", async () => {
7979
const workflow = new Workflow("Using outputs");
8080
workflow.on("push").addJob("job1", {
8181
steps: [
@@ -88,10 +88,10 @@ describe("Workflow", () => {
8888
"random-number": "${{ steps.random-number.outputs.random-number }}",
8989
},
9090
});
91-
expect(workflow.compile()).toMatchSnapshot();
91+
expect(await workflow.compile()).toMatchSnapshot();
9292
});
9393

94-
it("allows conditional jobs", () => {
94+
it("allows conditional jobs", async () => {
9595
const workflow = new Workflow("Conditional job");
9696
workflow.on("push").addJob("job1", {
9797
ifExpression: "${{ github.ref != 'refs/heads/main' }}",
@@ -101,10 +101,10 @@ describe("Workflow", () => {
101101
},
102102
],
103103
});
104-
expect(workflow.compile()).toMatchSnapshot();
104+
expect(await workflow.compile()).toMatchSnapshot();
105105
});
106106

107-
it("allows a job matrix", () => {
107+
it("allows a job matrix", async () => {
108108
const workflow = new Workflow("Conditional job");
109109
workflow.on("push").addJob("job1", {
110110
matrix: {
@@ -132,10 +132,10 @@ describe("Workflow", () => {
132132
},
133133
],
134134
});
135-
expect(workflow.compile()).toMatchSnapshot();
135+
expect(await workflow.compile()).toMatchSnapshot();
136136
});
137137

138-
it("allows uses steps", () => {
138+
it("allows uses steps", async () => {
139139
const workflow = new Workflow("Uses steps");
140140
workflow
141141
.on("push")
@@ -151,10 +151,10 @@ describe("Workflow", () => {
151151
},
152152
],
153153
});
154-
expect(workflow.compile()).toMatchSnapshot();
154+
expect(await workflow.compile()).toMatchSnapshot();
155155
});
156156

157-
it("allows custom types in a workflow", () => {
157+
it("allows custom types in a workflow", async () => {
158158
interface MyUseStep extends UseStep {
159159
uses: "custom-action";
160160
with: { foo: string };
@@ -163,7 +163,7 @@ describe("Workflow", () => {
163163
type CustomRunner = "standard-runner";
164164

165165
const workflow = new Workflow<CustomStep, CustomRunner>(
166-
"With custom types"
166+
"With custom types",
167167
);
168168

169169
workflow.on("push").addJob("job1", {
@@ -181,10 +181,10 @@ describe("Workflow", () => {
181181
],
182182
});
183183

184-
expect(workflow.compile()).toMatchSnapshot();
184+
expect(await workflow.compile()).toMatchSnapshot();
185185
});
186186

187-
it("support workflow dispatch event", () => {
187+
it("support workflow dispatch event", async () => {
188188
const workflow = new Workflow("Workflow dispatch");
189189
workflow
190190
.on("workflow_dispatch", {
@@ -203,29 +203,29 @@ describe("Workflow", () => {
203203
.addJob("job1", {
204204
steps: [{ name: "Do something", run: "exit 0" }],
205205
});
206-
expect(workflow.compile()).toMatchSnapshot();
206+
expect(await workflow.compile()).toMatchSnapshot();
207207
});
208208

209-
it("supports schedule event", () => {
209+
it("supports schedule event", async () => {
210210
const workflow = new Workflow("Schedule")
211211
.on("schedule", [{ cron: "0 4 * * 1-5" }])
212212
.addJob("job1", {
213213
steps: [{ name: "Do something", run: "exit 0" }],
214214
});
215-
expect(workflow.compile()).toMatchSnapshot();
215+
expect(await workflow.compile()).toMatchSnapshot();
216216
});
217217

218-
it("supports a pretty name for the job", () => {
218+
it("supports a pretty name for the job", async () => {
219219
const workflow = new Workflow("Job with pretty name")
220220
.on("push")
221221
.addJob("job1", {
222222
prettyName: "My pretty name",
223223
steps: [{ name: "Do something", run: "exit 0" }],
224224
});
225-
expect(workflow.compile()).toMatchSnapshot();
225+
expect(await workflow.compile()).toMatchSnapshot();
226226
});
227227

228-
it("allows permissions into jobs", () => {
228+
it("allows permissions into jobs", async () => {
229229
const workflow = new Workflow("Job with permissions")
230230
.on("push")
231231
.addJob("job1", {
@@ -235,10 +235,10 @@ describe("Workflow", () => {
235235
},
236236
steps: [{ name: "Do something", run: "exit 0" }],
237237
});
238-
expect(workflow.compile()).toMatchSnapshot();
238+
expect(await workflow.compile()).toMatchSnapshot();
239239
});
240240

241-
it("allows multiline strings", () => {
241+
it("allows multiline strings", async () => {
242242
const workflow = new Workflow("Multiline strings")
243243
.on("push")
244244
.addJob("job1", {
@@ -250,10 +250,10 @@ exit 0`,
250250
},
251251
],
252252
});
253-
expect(workflow.compile()).toMatchSnapshot();
253+
expect(await workflow.compile()).toMatchSnapshot();
254254
});
255255

256-
it("allows concurrency groups at workflow level", () => {
256+
it("allows concurrency groups at workflow level", async () => {
257257
const workflow = new Workflow("Concurrency at workflow level")
258258
.on("push")
259259
.setConcurrencyGroup({
@@ -268,6 +268,6 @@ exit 0`,
268268
},
269269
],
270270
});
271-
expect(workflow.compile()).toMatchSnapshot();
271+
expect(await workflow.compile()).toMatchSnapshot();
272272
});
273273
});

0 commit comments

Comments
 (0)