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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions updatecli/policies/copy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## 0.1.0

* Initial release
29 changes: 29 additions & 0 deletions updatecli/policies/copy/Policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# Policy.yaml contains metadata for the Updatecli policy.

# Authors is the policy authors
authors:
- José Guilherme Vanz <[email protected]>

# URL is the policy url
url: "https://github.com/updatecli/policies/"

# Documentation is the policy documentation URL
documentation: "https://github.com/updatecli/policies/tree/main/updatecli/policies/copy/README.md"

# Source is the policy source URL
source: "https://github.com/updatecli/policies/tree/main/updatecli/policies/copy/"

# Version is the policy version.
version: 0.1.0

# Vendor is the policy vendor
vendor: Updatecli project

# License is the policy licenses
licenses:
- "Apache-2.0 license"

# Description is the short policy description
description: |
Copy files from a git repository to a local file
29 changes: 29 additions & 0 deletions updatecli/policies/copy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## DESCRIPTION

This policy can be used to copy files from a source repository to a local file


Here is a basic example of a configuration

```values.yaml

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

files:
- src: .golangci.yml
dst: .golangci.yml
- src: _typos.toml
dst: _typos.toml
- src: codecov.yaml
dst: codecov.yaml
- src: .gitignore
dst: .gitignore
```

Then you can execute this policy running:

```
updatecli diff --values values.yaml ghcr.io/updatecli/policies/updatecli/copy:latest
```
13 changes: 13 additions & 0 deletions updatecli/policies/copy/testdata/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
src:
url: "https://github.com/updatecli/updatecli.git"
branch: "main"

files:
- src: .golangci.yml
dst: .golangci.yml
- src: _typos.toml
dst: _typos.toml
- src: codecov.yaml
dst: codecov.yaml
- src: .gitignore
dst: .gitignore
40 changes: 40 additions & 0 deletions updatecli/policies/copy/updatecli.d/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# Helpers
# {{ $DefaultTitle := (print "copy file(s) from " .src.url ) }}

name: '{{ default $DefaultTitle .title }}'

# {{ if .pipelineid }}
pipelineid: '{{ .pipelineid }}'
# {{ end }}

# scms defines the source control management system to interact with.
scms:
source:
kind: git
spec:
url: "{{ .src.url }}"
branch: "{{ .src.branch }}"

# sources defines where to find the information.
sources:
# {{ range $index, $file := .files }}
{{ $index }}:
name: 'Get {{$file.src }} from source repository'
scmid: 'source'
kind: 'file'
spec:
file: '{{ $file.src }}'
# {{ end }}

## targets defines where to apply the changes.
targets:
# {{ range $index, $file := .files }}
"{{ $index }}":
name: 'sync {{ $file.dst }} file'
kind: 'file'
sourceid: '{{ $index }}'
spec:
file: '{{ $file.dst }}'
forcecreate: true
# {{ end }}
23 changes: 23 additions & 0 deletions updatecli/policies/copy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# Values.yaml contains settings that be used from Updatecli manifest.

## title override the default title of the policy
#title: "chore: sync file from source repository"

## files contains the list of files to be copied from the source repository to the target repository.
#files:
# - src: ""
# dst: ""

## pipelineid is the pipeline id to be used by the policy
## It is used to identify the pipeline that is running the policy.
## Different pipelines sharing the same pipelineid and the same scm configuration
## will update the same pullrequest
#pipelineid: "file"


## src contains the source repository information
## It is used to fetch the files to be copied to the target repository
#src:
# url: ""
# branch: ""