Skip to content

Commit 4b9d178

Browse files
authored
fix: danger local action check (#41)
1 parent c5242b6 commit 4b9d178

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 2.2.2
6+
7+
### Fixes
8+
9+
- Skip local actions when checking pinned actions in Danger ([#41](https://github.com/getsentry/github-workflows/pull/41))
10+
511
## 2.2.1
612

713
### Fixes

danger/dangerfile.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ async function checkActionsArePinned() {
134134
const usesRegex = /^\+? *uses:/;
135135
const usesActionRegex =
136136
/^\+? *uses: *(?<user>[^\/]+)\/(?<action>[^@]+)@(?<ref>[^ ]*)/;
137+
const usesLocalRegex = /^\+? *uses: *\.\//; // e.g. 'uses: ./.github/actions/something'
137138
const shaRegex = /^[a-f0-9]{40}$/;
138139
const whitelistedUsers = ["getsentry", "actions"];
139140

@@ -142,7 +143,8 @@ async function checkActionsArePinned() {
142143
for (const chunk of diff.chunks) {
143144
for (const change of chunk.changes) {
144145
if (change.add) {
145-
const match = change.content.match(usesActionRegex);
146+
const line = change.content;
147+
const match = line.match(usesActionRegex);
146148
// Example of `match.groups`:
147149
// [Object: null prototype] {
148150
// user: 'getsentry',
@@ -151,21 +153,15 @@ async function checkActionsArePinned() {
151153
// }
152154
if (match && match.groups) {
153155
if (!match.groups.ref.match(shaRegex)) {
154-
if (whitelistedUsers.includes(match.groups.user)) {
155-
message(
156-
"Consider pinning the action by specifying a commit SHA instead of a tag/branch.",
157-
path,
158-
change.ln
159-
);
160-
} else {
156+
if (!whitelistedUsers.includes(match.groups.user)) {
161157
fail(
162158
"Please pin the action by specifying a commit SHA instead of a tag/branch.",
163159
path,
164160
change.ln
165161
);
166162
}
167163
}
168-
} else if (change.content.match(usesRegex)) {
164+
} else if (line.match(usesRegex) && !line.match(usesLocalRegex)) {
169165
warn(
170166
"Couldn't parse 'uses:' declaration while checking for action pinning.",
171167
path,

0 commit comments

Comments
 (0)