Skip to content

Commit

Permalink
fix: keep 404 actions and skip actions pinned with full commit hash (#97
Browse files Browse the repository at this point in the history
)
  • Loading branch information
suzuki-shunsuke committed Jul 6, 2023
1 parent 139116f commit 6dc04f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/controller/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (ctrl *Controller) parseLine(ctx context.Context, logE *logrus.Entry, line
sha, _, err := ctrl.RepositoriesService.GetCommitSHA1(ctx, action.RepoOwner, action.RepoName, action.Version, "")
if err != nil {
logerr.WithError(logE, err).Warn("get a reference")
return "", nil
return line, nil
}
longVersion := action.Version
if shortTagPattern.MatchString(action.Version) {
Expand Down Expand Up @@ -113,6 +113,9 @@ func (ctrl *Controller) parseLine(ctx context.Context, logE *logrus.Entry, line

func (ctrl *Controller) patchLine(line string, action *Action, version, tag string) string {
if action.Tag == "" {
if version == tag {
return line
}
return strings.Replace(line, fmt.Sprintf("@%s", action.Version), fmt.Sprintf("@%s # %s", version, tag), 1)
}
return strings.Replace(line, fmt.Sprintf("@%s # %s", action.Version, action.Tag), fmt.Sprintf("@%s # %s", action.Version, tag), 1)
Expand All @@ -123,14 +126,22 @@ func (ctrl *Controller) runWorkflow(ctx context.Context, logE *logrus.Entry, wor
if err != nil {
return err
}
changed := false
for i, line := range lines {
line := line
l, err := ctrl.parseLine(ctx, logE, line)
if err != nil {
logerr.WithError(logE, err).Error("parse a line")
continue
}
if line != l {
changed = true
}
lines[i] = l
}
if !changed {
return nil
}
f, err := os.Create(workflowFilePath)
if err != nil {
return fmt.Errorf("create a workflow file: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions testdata/foo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
steps:
- uses: actions/checkout@83b7061638ee4956cf7545a6f7efe594e5ad0247 # v3
- uses: actions/checkout@83b7061638ee4956cf7545a6f7efe594e5ad0247 # tag=v3
- uses: actions/checkout@83b7061638ee4956cf7545a6f7efe594e5ad0247
- uses: suzuki-shunsuke/repo-404@83b7061638ee4956cf7545a6f7efe594e5ad0247
- uses: actions/checkout@v2
- uses: actions/cache@v3.3.1
actionlint:
Expand Down

0 comments on commit 6dc04f6

Please sign in to comment.