Skip to content

Commit ee37fbe

Browse files
committed
feat(file): add file policy.
Adds a new policy to copy files from on git repository to another. Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
1 parent 0d9598d commit ee37fbe

File tree

6 files changed

+219
-0
lines changed

6 files changed

+219
-0
lines changed

updatecli/policies/file/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## 0.1.0
4+
5+
* Initial release

updatecli/policies/file/Policy.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
# Policy.yaml contains metadata for the Updatecli policy.
3+
4+
# Authors is the policy authors
5+
authors:
6+
- José Guilherme Vanz <jvanz@jvanz.com>
7+
8+
# URL is the policy url
9+
url: https://github.com/updatecli/policies/
10+
11+
# Documentation is the policy documentation URL
12+
documentation: https://github.com/updatecli/policies/tree/main/updatecli/policies/file/README.md
13+
14+
# Source is the policy source URL
15+
source: https://github.com/updatecli/policies/tree/main/updatecli/policies/file/
16+
17+
# Version is the policy version.
18+
version: 0.1.0
19+
20+
# Vendor is the policy vendor
21+
vendor: Updatecli project
22+
23+
# License is the policy licenses
24+
licenses:
25+
- "Apache-2.0 license"
26+
27+
# Description is the short policy description
28+
description: |
29+
Copy files from a git repository and commit it into another git repository.

updatecli/policies/file/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## DESCRIPTION
2+
3+
This policy can be used to copy files from a source repository to a destination repository.
4+
5+
By default the policy uses the following environment variable to set default values
6+
7+
* `GITHUB_REPOSITORY`: To retrieve the GitHub repository to publish the files. It must be of type `OWNER/REPOSITORY`
8+
9+
* `GITHUB_ACTOR`: To retrieve the GitHub username used for authentication
10+
* `GITHUB_TOKEN`: To retrieve the GitHub token used for authentication
11+
12+
Here is a basic example of a configuration
13+
14+
```values.yaml
15+
scm:
16+
author: "Updatecli bot"
17+
branch: "main"
18+
owner: "updatecli"
19+
repository: "udash"
20+
username: "updatecli-bot"
21+
22+
src:
23+
url: "https://github.com/updatecli/updatecli.git"
24+
branch: "main"
25+
26+
files:
27+
- src: .golangci.yml
28+
dst: .golangci.yml
29+
- src: _typos.toml
30+
dst: _typos.toml
31+
- src: codecov.yaml
32+
dst: codecov.yaml
33+
- src: .gitignore
34+
dst: .gitignore
35+
```
36+
37+
Then you can execute this policy running:
38+
39+
```
40+
export GITHUB_TOKEN=yyy
41+
export GITHUB_ACTOR=xxx
42+
updatecli diff --values values.yaml ghcr.io/updatecli/policies/updatecli/file:latest
43+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
scm:
2+
author: "Updatecli bot"
3+
branch: "main"
4+
owner: "updatecli"
5+
repository: "udash"
6+
username: "updatecli-bot"
7+
8+
src:
9+
url: "https://github.com/updatecli/updatecli.git"
10+
branch: "main"
11+
12+
files:
13+
- src: .golangci.yml
14+
dst: .golangci.yml
15+
- src: _typos.toml
16+
dst: _typos.toml
17+
- src: codecov.yaml
18+
dst: codecov.yaml
19+
- src: .gitignore
20+
dst: .gitignore
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
# Helpers
3+
# {{ $GitHubUser := env ""}}
4+
# {{ $GitHubRepositoryList := env "GITHUB_REPOSITORY" | split "/"}}
5+
# {{ $GitHubPAT := env "GITHUB_TOKEN"}}
6+
# {{ $GitHubUsername := env "GITHUB_ACTOR"}}
7+
# {{ $DefaultTitle := (print "chore: sync file(s) from " .src.url ) }}
8+
9+
name: '{{ default $DefaultTitle .title }}'
10+
11+
# {{ if .pipelineid }}
12+
pipelineid: '{{ .pipelineid }}'
13+
# {{ end }}
14+
15+
# scms defines the source control management system to interact with.
16+
scms:
17+
default:
18+
kind: "github"
19+
spec:
20+
# Priority set to the environment variable
21+
user: '{{ default $GitHubUser .scm.user}}'
22+
# {{ if .scm.email }}
23+
email: '{{ .scm.email }}'
24+
# {{ end }}
25+
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
26+
repository: '{{ default $GitHubRepositoryList._1 .scm.repository}}'
27+
token: '{{ default $GitHubPAT .scm.token }}'
28+
username: '{{ default $GitHubUsername .scm.username }}'
29+
branch: '{{ .scm.branch }}'
30+
#{{ if .scm.commitusingapi }}
31+
commitusingapi: {{ .scm.commitusingapi }}
32+
# {{ end }}
33+
source:
34+
kind: git
35+
spec:
36+
url: "{{ .src.url }}"
37+
branch: "{{ .src.branch }}"
38+
39+
# sources defines where to find the information.
40+
sources:
41+
# {{ range $index, $file := .files }}
42+
{{ $index }}:
43+
name: 'Get {{$file.src }} from source repository'
44+
scmid: 'source'
45+
kind: 'file'
46+
spec:
47+
file: '{{ $file.src }}'
48+
# {{ end }}
49+
50+
## targets defines where to apply the changes.
51+
targets:
52+
# {{ range $index, $file := .files }}
53+
"{{ $index }}":
54+
name: 'chore: sync {{ $file.dst }} file'
55+
kind: 'file'
56+
scmid: 'default'
57+
sourceid: '{{ $index }}'
58+
spec:
59+
file: '{{ $file.dst }}'
60+
forcecreate: true
61+
# {{ end }}
62+
63+
# actions defines what to do when a target with the same scmid is modified.
64+
actions:
65+
default:
66+
kind: "github/pullrequest"
67+
spec:
68+
# {{ if .pr.title }}
69+
title: '{{ .pr.title }}'
70+
# {{ end }}
71+
# {{ if .pr.description }}
72+
description: '{{ .pr.description }}'
73+
# {{ end }}
74+
automerge: {{ .pr.automerge }}
75+
# {{ if .pr.labels }}
76+
labels:
77+
# {{ range .pr.labels }}
78+
- '{{ . }}'
79+
# {{ end }}
80+
# {{ end }}
81+
scmid: "default"

updatecli/policies/file/values.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# Values.yaml contains settings that be used from Updatecli manifest.
3+
4+
## title override the default title of the policy
5+
#title: "chore: sync file from source repository"
6+
7+
## files contains the list of files to be copied from the source repository to the target repository.
8+
#files:
9+
# - src: ""
10+
# dst: ""
11+
12+
## pipelineid is the pipeline id to be used by the policy
13+
## It is used to identify the pipeline that is running the policy.
14+
## Different pipelines sharing the same pipelineid and the same scm configuration
15+
## will update the same pullrequest
16+
#pipelineid: "file"
17+
18+
## pr contains the pull request settings that can be overridden
19+
pr:
20+
automerge: false
21+
# description: ""
22+
labels:
23+
- dependencies
24+
# title: ""
25+
26+
## src contains the source repository information
27+
## It is used to fetch the files to be copied to the target repository
28+
#src:
29+
# url: ""
30+
# branch: ""
31+
32+
## scm contains the source control management information
33+
scm:
34+
commitusingapi: true
35+
user: updatecli
36+
# email: updatecli-bot@updatecli.io
37+
# owner: updatecli
38+
# repository: updatecli
39+
# token: "xxx"
40+
# username: "updatecli-bot"
41+
# branch: main

0 commit comments

Comments
 (0)