Skip to content

Commit 720c77f

Browse files
setup(workflows): enhance security of yamls (#148)
1 parent 9976e78 commit 720c77f

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ on:
2525
- reopened
2626
- synchronize
2727

28+
permissions:
29+
contents: read
30+
2831
jobs:
2932
get-matrix:
3033
name: Configure Node LTS environment matrix
@@ -33,7 +36,12 @@ jobs:
3336
outputs:
3437
latest: ${{ steps.set-matrix.outputs.requireds }}
3538
steps:
36-
- uses: ljharb/actions/node/matrix@main
39+
- name: Harden the runner (Audit all outbound calls)
40+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
41+
with:
42+
egress-policy: audit
43+
44+
- uses: ljharb/actions/node/matrix@7f214d8efdbdcefc96ad9689663ef387a195deec # main
3745
id: set-matrix
3846
with:
3947
versionsAsRoot: true
@@ -48,12 +56,17 @@ jobs:
4856
runs-on: ubuntu-latest
4957

5058
steps:
51-
- uses: actions/checkout@v4
59+
- name: Harden the runner (Audit all outbound calls)
60+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
61+
with:
62+
egress-policy: audit
63+
64+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5265
with:
5366
persist-credentials: false
5467
show-progress: false
5568
- name: Set up Node.js LTS
56-
uses: actions/setup-node@v4
69+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
5770
with:
5871
cache: "npm"
5972
check-latest: true
@@ -62,6 +75,23 @@ jobs:
6275
- run: node --run lint
6376
- run: node --run type-check
6477

78+
validate-yaml:
79+
name: Validate YAML files
80+
81+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
82+
83+
runs-on: ubuntu-latest
84+
85+
steps:
86+
- name: Harden the runner (Audit all outbound calls)
87+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
88+
with:
89+
egress-policy: audit
90+
91+
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
92+
- name: Validate YAML files
93+
run: yamllint -c .yamllint.yaml -f github ./
94+
6595
tests:
6696
name: Unit, e2e, coverage
6797

@@ -80,12 +110,17 @@ jobs:
80110
- windows-latest
81111

82112
steps:
83-
- uses: actions/checkout@v4
113+
- name: Harden the runner (Audit all outbound calls)
114+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
115+
with:
116+
egress-policy: audit
117+
118+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
84119
with:
85120
persist-credentials: false
86121
show-progress: false
87122
- name: Set up Node.js ${{ matrix.node-version }}
88-
uses: actions/setup-node@v4
123+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
89124
with:
90125
cache: "npm"
91126
check-latest: true

.yamllint.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# We use yamllint to ensure our YAML files are well-formed and follow best practices.
2+
# In future, I (@AugustinMauroy) want to use `codemod validate` to validate YAML files.
3+
# But this feature only check `workflow.yaml` and not `codemod.yaml`.
4+
5+
yaml-files:
6+
- '*.yaml'
7+
- '*.yml'
8+
9+
rules:
10+
anchors: enable
11+
braces: enable
12+
brackets: enable
13+
colons: enable
14+
commas: enable
15+
comments:
16+
level: warning
17+
comments-indentation:
18+
level: warning
19+
document-end: disable
20+
document-start: disable
21+
empty-lines: enable
22+
empty-values: disable
23+
float-values: disable
24+
hyphens: enable
25+
indentation: enable
26+
key-duplicates: enable
27+
key-ordering: disable
28+
line-length:
29+
level: warning
30+
new-line-at-end-of-file: enable
31+
new-lines: enable
32+
octal-values: disable
33+
quoted-strings: disable
34+
trailing-spaces: enable
35+
truthy:
36+
level: warning

recipes/process-main-module/workflow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nodes:
88
type: direct
99
steps:
1010
- name: Handle DEP0138 via transforming `process.mainModule` to `require.main`.
11-
js-ast-grep:
11+
js-ast-grep:
1212
js_file: src/workflow.ts
1313
base_path: .
1414
include:

0 commit comments

Comments
 (0)