feat: add option to specify subdirectory in repo to use

renovate/rouge-4.x
Jef Roosens 2022-12-16 11:21:28 +01:00
parent a48358fd75
commit 1ce7b9d571
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
14 changed files with 120 additions and 28 deletions

View File

@ -22,6 +22,7 @@ pub:
kind string kind string
url string url string
branch string branch string
path string
repo string repo string
base_image string base_image string
force bool force bool
@ -29,7 +30,7 @@ pub:
// str return a single-line string representation of a build log // str return a single-line string representation of a build log
pub fn (c BuildConfig) str() string { pub fn (c BuildConfig) str() string {
return '{ target: $c.target_id, kind: $c.kind, url: $c.url, branch: $c.branch, repo: $c.repo, base_image: $c.base_image, force: $c.force }' return '{ target: $c.target_id, kind: $c.kind, url: $c.url, branch: $c.branch, path: $c.path, repo: $c.repo, base_image: $c.base_image, force: $c.force }'
} }
// create_build_image creates a builder image given some base image which can // create_build_image creates a builder image given some base image which can
@ -116,6 +117,7 @@ pub fn build_target(address string, api_key string, base_image_id string, target
kind: target.kind kind: target.kind
url: target.url url: target.url
branch: target.branch branch: target.branch
path: target.path
repo: target.repo repo: target.repo
base_image: base_image_id base_image: base_image_id
force: force force: force

View File

@ -0,0 +1,20 @@
echo -e '+ echo -e '\''[vieter]\\nServer = https://example.com/$repo/$arch\\nSigLevel = Optional'\'' >> /etc/pacman.conf'
echo -e '[vieter]\nServer = https://example.com/$repo/$arch\nSigLevel = Optional' >> /etc/pacman.conf
echo -e '+ pacman -Syu --needed --noconfirm'
pacman -Syu --needed --noconfirm
echo -e '+ su builder'
su builder
echo -e '+ git clone --single-branch --depth 1 '\''https://examplerepo.com'\'' repo'
git clone --single-branch --depth 1 'https://examplerepo.com' repo
echo -e '+ cd '\''repo/example/path'\'''
cd 'repo/example/path'
echo -e '+ makepkg --nobuild --syncdeps --needed --noconfirm'
makepkg --nobuild --syncdeps --needed --noconfirm
echo -e '+ source PKGBUILD'
source PKGBUILD
echo -e '+ curl -s --head --fail https://example.com/vieter/x86_64/$pkgname-$pkgver-$pkgrel && exit 0'
curl -s --head --fail https://example.com/vieter/x86_64/$pkgname-$pkgver-$pkgrel && exit 0
echo -e '+ [ "$(id -u)" == 0 ] && exit 0'
[ "$(id -u)" == 0 ] && exit 0
echo -e '+ MAKEFLAGS="-j$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in $(ls -1 *.pkg*); do curl -XPOST -T "$pkg" -H "X-API-KEY: $API_KEY" https://example.com/vieter/publish; done'
MAKEFLAGS="-j$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in $(ls -1 *.pkg*); do curl -XPOST -T "$pkg" -H "X-API-KEY: $API_KEY" https://example.com/vieter/publish; done

View File

@ -0,0 +1,20 @@
echo -e '+ echo -e '\''[vieter]\\nServer = https://example.com/$repo/$arch\\nSigLevel = Optional'\'' >> /etc/pacman.conf'
echo -e '[vieter]\nServer = https://example.com/$repo/$arch\nSigLevel = Optional' >> /etc/pacman.conf
echo -e '+ pacman -Syu --needed --noconfirm'
pacman -Syu --needed --noconfirm
echo -e '+ su builder'
su builder
echo -e '+ git clone --single-branch --depth 1 '\''https://examplerepo.com'\'' repo'
git clone --single-branch --depth 1 'https://examplerepo.com' repo
echo -e '+ cd '\''repo/example/path with spaces'\'''
cd 'repo/example/path with spaces'
echo -e '+ makepkg --nobuild --syncdeps --needed --noconfirm'
makepkg --nobuild --syncdeps --needed --noconfirm
echo -e '+ source PKGBUILD'
source PKGBUILD
echo -e '+ curl -s --head --fail https://example.com/vieter/x86_64/$pkgname-$pkgver-$pkgrel && exit 0'
curl -s --head --fail https://example.com/vieter/x86_64/$pkgname-$pkgver-$pkgrel && exit 0
echo -e '+ [ "$(id -u)" == 0 ] && exit 0'
[ "$(id -u)" == 0 ] && exit 0
echo -e '+ MAKEFLAGS="-j$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in $(ls -1 *.pkg*); do curl -XPOST -T "$pkg" -H "X-API-KEY: $API_KEY" https://example.com/vieter/publish; done'
MAKEFLAGS="-j$(nproc)" makepkg -s --noconfirm --needed --noextract && for pkg in $(ls -1 *.pkg*); do curl -XPOST -T "$pkg" -H "X-API-KEY: $API_KEY" https://example.com/vieter/publish; done

View File

@ -59,8 +59,13 @@ fn create_build_script(address string, config BuildConfig, build_arch string) st
} }
} }
commands << if config.path != '' {
"cd 'repo/$config.path'"
} else {
'cd repo'
}
commands << [ commands << [
'cd repo',
'makepkg --nobuild --syncdeps --needed --noconfirm', 'makepkg --nobuild --syncdeps --needed --noconfirm',
'source PKGBUILD', 'source PKGBUILD',
] ]

View File

@ -1,5 +1,46 @@
module build module build
fn test_create_build_script_git() {
config := BuildConfig{
target_id: 1
kind: 'git'
url: 'https://examplerepo.com'
repo: 'vieter'
base_image: 'not-used:latest'
}
build_script := create_build_script('https://example.com', config, 'x86_64')
expected := $embed_file('scripts/git.sh')
assert build_script == expected.to_string().trim_space()
}
fn test_create_build_script_git_path() {
mut config := BuildConfig{
target_id: 1
kind: 'git'
url: 'https://examplerepo.com'
repo: 'vieter'
path: 'example/path'
base_image: 'not-used:latest'
}
mut build_script := create_build_script('https://example.com', config, 'x86_64')
mut expected := $embed_file('scripts/git_path.sh')
assert build_script == expected.to_string().trim_space()
config = BuildConfig{
...config
path: 'example/path with spaces'
}
build_script = create_build_script('https://example.com', config, 'x86_64')
expected = $embed_file('scripts/git_path_spaces.sh')
assert build_script == expected.to_string().trim_space()
}
fn test_create_build_script_git_branch() { fn test_create_build_script_git_branch() {
config := BuildConfig{ config := BuildConfig{
target_id: 1 target_id: 1
@ -11,22 +52,7 @@ fn test_create_build_script_git_branch() {
} }
build_script := create_build_script('https://example.com', config, 'x86_64') build_script := create_build_script('https://example.com', config, 'x86_64')
expected := $embed_file('build_script_git_branch.sh') expected := $embed_file('scripts/git_branch.sh')
assert build_script == expected.to_string().trim_space()
}
fn test_create_build_script_git() {
config := BuildConfig{
target_id: 1
kind: 'git'
url: 'https://examplerepo.com'
repo: 'vieter'
base_image: 'not-used:latest'
}
build_script := create_build_script('https://example.com', config, 'x86_64')
expected := $embed_file('build_script_git.sh')
assert build_script == expected.to_string().trim_space() assert build_script == expected.to_string().trim_space()
} }
@ -41,7 +67,7 @@ fn test_create_build_script_url() {
} }
build_script := create_build_script('https://example.com', config, 'x86_64') build_script := create_build_script('https://example.com', config, 'x86_64')
expected := $embed_file('build_script_url.sh') expected := $embed_file('scripts/url.sh')
assert build_script == expected.to_string().trim_space() assert build_script == expected.to_string().trim_space()
} }

View File

@ -44,6 +44,7 @@ pub struct NewTarget {
url string url string
branch string branch string
repo string repo string
path string
arch []string arch []string
} }

View File

@ -82,6 +82,11 @@ pub fn cmd() cli.Command {
description: "Which branch to clone; only applies to kind 'git'." description: "Which branch to clone; only applies to kind 'git'."
flag: cli.FlagType.string flag: cli.FlagType.string
}, },
cli.Flag{
name: 'path'
description: 'Subdirectory inside Git repository to use.'
flag: cli.FlagType.string
},
] ]
execute: fn (cmd cli.Command) ! { execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')! config_file := cmd.flags.get_string('config-file')!
@ -92,6 +97,7 @@ pub fn cmd() cli.Command {
url: cmd.args[0] url: cmd.args[0]
repo: cmd.args[1] repo: cmd.args[1]
branch: cmd.flags.get_string('branch') or { '' } branch: cmd.flags.get_string('branch') or { '' }
path: cmd.flags.get_string('path') or { '' }
} }
raw := cmd.flags.get_bool('raw')! raw := cmd.flags.get_bool('raw')!
@ -159,6 +165,11 @@ pub fn cmd() cli.Command {
description: 'Kind of target.' description: 'Kind of target.'
flag: cli.FlagType.string flag: cli.FlagType.string
}, },
cli.Flag{
name: 'path'
description: 'Subdirectory inside Git repository to use.'
flag: cli.FlagType.string
},
] ]
execute: fn (cmd cli.Command) ! { execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')! config_file := cmd.flags.get_string('config-file')!

View File

@ -18,12 +18,14 @@ const (
$embed_file('migrations/002-rename-to-targets/up.sql'), $embed_file('migrations/002-rename-to-targets/up.sql'),
$embed_file('migrations/003-target-url-type/up.sql'), $embed_file('migrations/003-target-url-type/up.sql'),
$embed_file('migrations/004-nullable-branch/up.sql'), $embed_file('migrations/004-nullable-branch/up.sql'),
$embed_file('migrations/005-repo-path/up.sql'),
] ]
migrations_down = [ migrations_down = [
$embed_file('migrations/001-initial/down.sql'), $embed_file('migrations/001-initial/down.sql'),
$embed_file('migrations/002-rename-to-targets/down.sql'), $embed_file('migrations/002-rename-to-targets/down.sql'),
$embed_file('migrations/003-target-url-type/down.sql'), $embed_file('migrations/003-target-url-type/down.sql'),
$embed_file('migrations/004-nullable-branch/down.sql'), $embed_file('migrations/004-nullable-branch/down.sql'),
$embed_file('migrations/005-repo-path/down.sql'),
] ]
) )

View File

@ -0,0 +1 @@
ALTER TABLE Target DROP COLUMN path;

View File

@ -0,0 +1 @@
ALTER TABLE Target ADD COLUMN path TEXT;

View File

@ -28,21 +28,24 @@ pub mut:
repo string [nonull] repo string [nonull]
// Cron schedule describing how frequently to build the repo. // Cron schedule describing how frequently to build the repo.
schedule string schedule string
// Subdirectory in the Git repository to cd into
path string
// On which architectures the package is allowed to be built. In reality, // On which architectures the package is allowed to be built. In reality,
// this controls which builders will periodically build the image. // this controls which agents will build this package when scheduled.
arch []TargetArch [fkey: 'target_id'] arch []TargetArch [fkey: 'target_id']
} }
// str returns a string representation. // str returns a string representation.
pub fn (gr &Target) str() string { pub fn (t &Target) str() string {
mut parts := [ mut parts := [
'id: $gr.id', 'id: $t.id',
'kind: $gr.kind', 'kind: $t.kind',
'url: $gr.url', 'url: $t.url',
'branch: $gr.branch', 'branch: $t.branch',
'repo: $gr.repo', 'path: $t.path',
'schedule: $gr.schedule', 'repo: $t.repo',
'arch: ${gr.arch.map(it.value).join(', ')}', 'schedule: $t.schedule',
'arch: ${t.arch.map(it.value).join(', ')}',
] ]
str := parts.join('\n') str := parts.join('\n')