Skip to content

Commit 10e833c

Browse files
committed
fix ghcr.io/ and docker.io Docker images are not allowed at image in action.yml (Fix #428)
1 parent c33463f commit 10e833c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

rule_action.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ var BrandingIcons = map[string]struct{}{
284284
"zoom-out": {},
285285
}
286286

287+
// https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsimage
288+
func isImageOnDockerRegistry(image string) bool {
289+
return strings.HasPrefix(image, "docker://") ||
290+
strings.HasPrefix(image, "ghcr.io/") ||
291+
strings.HasPrefix(image, "docker.io/")
292+
}
293+
287294
// RuleAction is a rule to check running action in steps of jobs.
288295
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsuses
289296
type RuleAction struct {
@@ -423,7 +430,7 @@ func (rule *RuleAction) checkRunsFileExists(file, dir, prop, name string, pos *P
423430
func (rule *RuleAction) checkLocalDockerActionRuns(r *ActionMetadataRuns, dir, name string, pos *Pos) {
424431
if r.Image == "" {
425432
rule.missingRunsProp(pos, "image", "Docker", name, dir)
426-
} else if !strings.HasPrefix(r.Image, "docker://") {
433+
} else if !isImageOnDockerRegistry(r.Image) {
427434
rule.checkRunsFileExists(r.Image, dir, "image", name, pos)
428435
if filepath.Base(filepath.FromSlash(r.Image)) != "Dockerfile" {
429436
rule.Errorf(pos, `the local file %q referenced from "image" key must be named "Dockerfile" in %q action. the action is defined at %q`, r.Image, name, dir)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Docker action'
2+
author: 'rhysd <https://rhysd.github.io>'
3+
description: 'Correct Docker action'
4+
5+
runs:
6+
using: 'docker'
7+
image: 'docker.io/rhysd/actionlint:latest'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Docker action'
2+
author: 'rhysd <https://rhysd.github.io>'
3+
description: 'Correct Docker action'
4+
5+
runs:
6+
using: 'docker'
7+
image: 'ghcr.io/rhysd/actionlint:latest'

testdata/projects/local_docker_action/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ jobs:
1212
- uses: ./missing_files
1313
- uses: ./ok_dockerfile_subdir
1414
- uses: ./invalid_dockerfile
15+
- uses: ./ok_docker_ghcr.io
16+
- uses: ./ok_docker_docker.io

0 commit comments

Comments
 (0)