Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## 2.2.2

### Fixes

- Skip local actions when checking pinned actions in Danger ([#41](https://github.com/getsentry/github-workflows/pull/41))

## 2.2.1

### Fixes
Expand Down
14 changes: 5 additions & 9 deletions danger/dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ async function checkActionsArePinned() {
const usesRegex = /^\+? *uses:/;
const usesActionRegex =
/^\+? *uses: *(?<user>[^\/]+)\/(?<action>[^@]+)@(?<ref>[^ ]*)/;
const usesLocalRegex = /^\+? *uses: *\.\//; // e.g. 'uses: ./.github/actions/something'
const shaRegex = /^[a-f0-9]{40}$/;
const whitelistedUsers = ["getsentry", "actions"];

Expand All @@ -142,7 +143,8 @@ async function checkActionsArePinned() {
for (const chunk of diff.chunks) {
for (const change of chunk.changes) {
if (change.add) {
const match = change.content.match(usesActionRegex);
const line = change.content;
const match = line.match(usesActionRegex);
// Example of `match.groups`:
// [Object: null prototype] {
// user: 'getsentry',
Expand All @@ -151,21 +153,15 @@ async function checkActionsArePinned() {
// }
if (match && match.groups) {
if (!match.groups.ref.match(shaRegex)) {
if (whitelistedUsers.includes(match.groups.user)) {
message(
"Consider pinning the action by specifying a commit SHA instead of a tag/branch.",
path,
change.ln
);
} else {
if (!whitelistedUsers.includes(match.groups.user)) {
fail(
"Please pin the action by specifying a commit SHA instead of a tag/branch.",
path,
change.ln
);
}
}
} else if (change.content.match(usesRegex)) {
} else if (line.match(usesRegex) && !line.match(usesLocalRegex)) {
warn(
"Couldn't parse 'uses:' declaration while checking for action pinning.",
path,
Expand Down