Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(copy): add copy policy. #45

Closed
wants to merge 1 commit into from
Closed

Conversation

jvanz
Copy link
Contributor

@jvanz jvanz commented Jan 22, 2025

Description

Adds the "copy" policy to allow users to copy files from git repositories into local files.

Adds the "copy" policy to allow users to copy files from git
repositories into local files.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@olblak
Copy link
Member

olblak commented Jan 23, 2025

@olblak
Copy link
Member

olblak commented Jan 23, 2025

Sorry I meant the other scm


and the action

@jvanz
Copy link
Contributor Author

jvanz commented Jan 28, 2025

I've tried to do that using the file policy. I've applied this diff:

diff --git a/updatecli/policies/file/updatecli.d/default.yaml b/updatecli/policies/file/updatecli.d/default.yaml
index 0af4fc9..4f193c9 100644
--- a/updatecli/policies/file/updatecli.d/default.yaml
+++ b/updatecli/policies/file/updatecli.d/default.yaml
@@ -1,9 +1,11 @@
 ---
 # Helpers
+# {{ if .scm }}
 # {{ $GitHubUser := env ""}}
 # {{ $GitHubRepositoryList := env "GITHUB_REPOSITORY" | split "/"}}
 # {{ $GitHubPAT := env "GITHUB_TOKEN"}}
 # {{ $GitHubUsername := env "GITHUB_ACTOR"}}
+# {{ end }}
 # {{ $DefaultTitle := (print "chore: sync file(s) from " .src.url ) }}
 
 name: '{{ default $DefaultTitle .title }}'
@@ -12,6 +14,7 @@ name: '{{ default $DefaultTitle .title }}'
 pipelineid: '{{ .pipelineid }}'
 # {{ end }}
 
+# {{ if .scm }}
 # scms defines the source control management system to interact with.
 scms:
   default:
@@ -50,6 +53,7 @@ scms:
 #{{ if .scm.commitmessage.scope }}
         scope: '{{ .scm.commitmessage.scope }}'
 # {{ end }}
+# {{ end }}
 # {{ end }}
   source:
     kind: git
@@ -62,7 +66,9 @@ sources:
 # {{ range $index, $file := .files }}
   {{ $index }}:
     name: 'Get {{$file.src }} from source repository'
+# {{ if .scm }}
     scmid: 'source'
+# {{ end }}
     kind: 'file'
     spec:
       file: '{{ $file.src }}'
@@ -74,13 +80,16 @@ targets:
   "{{ $index }}":
     name: 'sync {{ $file.dst }} file'
     kind: 'file'
+# {{ if .scm }}
     scmid: 'default'
+# {{ end }}
     sourceid: '{{ $index }}'
     spec:
       file: '{{ $file.dst }}'
       forcecreate: true
 # {{ end }}
       
+# {{ if .scm }}
 # actions defines what to do when a target with the same scmid is modified.
 actions:
   default:
@@ -100,3 +109,4 @@ actions:
 # {{ end }}
 # {{ end }}
     scmid: "default"
+# {{ end }}

And used this values file:

---
title: "chore: sync file from source repository"

files:
  - src: "cli-docs.md"
    dst: "/tmp/kwctl-cli.md"

src:
  branch: "main"
  url: "https://github.com/kubewarden/kwctl.git"

However, when I run the updatecli diff -v custom.yaml I saw the following error:

        template: cfg:24: undefined variable "$GitHubUser"
ERROR: failed loading pipeline(s)
        * "updatecli.d/default.yaml" - template: cfg:24: undefined variable "$GitHubUser"

0 pipeline(s) successfully loaded

SCM repository retrieved: 0

It looks to me that even if I put all the scm and github references under the if statements in the template, updatecli is trying to use a variable that should not be used.

Am I doing something wrong? 😅

@olblak
Copy link
Member

olblak commented Jan 28, 2025

You can run updatecli manifest show --config updatecli.d --values values.yaml --values testdata/values.yaml --debug to see how the templating is done.

Let me open a pullrequest as I think I have something working

@olblak
Copy link
Member

olblak commented Jan 28, 2025

I just open #46
Could you have a look?

@jvanz
Copy link
Contributor Author

jvanz commented Jan 30, 2025

Superseded by #46

@jvanz jvanz closed this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants