Skip to content

Commit

Permalink
Merge pull request #29 from Peefy/fix-oci-source
Browse files Browse the repository at this point in the history
fix: kcl run oci source entry
  • Loading branch information
Peefy authored Dec 23, 2023
2 parents 92127f1 + e5a2392 commit 2dd33c7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions examples/source/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
make -C oci
5 changes: 5 additions & 0 deletions examples/source/oci/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
run:
kcl run oci://ghcr.io/kcl-lang/helloworld

test:
make run
2 changes: 1 addition & 1 deletion examples/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$ErrorActionPreference = "Stop"
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path

$paths = @("configuration", "validation", "abstraction", "definition", "konfig", "mutation", "data-integration", "automation", "package-management", "kubernetes", "codelab", "server")
$paths = @("configuration", "validation", "abstraction", "definition", "konfig", "mutation", "data-integration", "automation", "package-management", "kubernetes", "codelab", "server", "source")
foreach ($path in $paths) {
Write-Host "Testing $path ..."
Set-Location -Path "$pwd\$path"
Expand Down
2 changes: 1 addition & 1 deletion examples/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pwd=$(
pwd
)

for path in "configuration" "validation" "abstraction" "definition" "konfig" "mutation" "data-integration" "automation" "package-management" "kubernetes" "codelab" "server"; do
for path in "configuration" "validation" "abstraction" "definition" "konfig" "mutation" "data-integration" "automation" "package-management" "kubernetes" "codelab" "server" "source"; do
echo "\033[1mTesting $path ...\033[0m"
if (cd $pwd/$path && make test); then
echo "\033[32mTest SUCCESSED - $path\033[0m\n"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
kcl-lang.io/kcl-go v0.7.1
kcl-lang.io/kcl-openapi v0.5.5
kcl-lang.io/kcl-playground v0.5.1-0.20230919072953-347ab8959295
kcl-lang.io/kpm v0.4.4
kcl-lang.io/kpm v0.4.6
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,8 @@ kcl-lang.io/kcl-openapi v0.5.5 h1:6LSbiy53nczagm7Ohgdy1DVgQ+5ffMihsOUY7PGkbh0=
kcl-lang.io/kcl-openapi v0.5.5/go.mod h1:Ai9mFztCVKkRSFabczO/r5hCNdqaNtAc2ZIRxTeV0Mk=
kcl-lang.io/kcl-playground v0.5.1-0.20230919072953-347ab8959295 h1:RUY3w6jNAB6GoMo27CO1oS4C4gjyWdMXfOTNpTEnkjs=
kcl-lang.io/kcl-playground v0.5.1-0.20230919072953-347ab8959295/go.mod h1:3aMvkPRLMZeORiQ/sHxXQCopwr8L1MMSSXMPC+hxwPA=
kcl-lang.io/kpm v0.4.4 h1:3WoYQEN0AQsFTIyleDRLLzP2l8XAJ7cn2UuADPgRMjs=
kcl-lang.io/kpm v0.4.4/go.mod h1:Yu8uUz7R1NeiP8vJrLQytGVYo+EewJi4EU+rfhYiiYc=
kcl-lang.io/kpm v0.4.6 h1:yaQdRQMqByaxyUb3uEp27zI7xxcsnp1iIcgqU9hFVqI=
kcl-lang.io/kpm v0.4.6/go.mod h1:Ba2ijUHQR/sMdB4S7982vOrajly4LdgshrqXd2SXBog=
kcl-lang.io/lib v0.7.3 h1:YsKBo5jrICQ3fJobywkB9dFfVIW/ixCAkqmYQ5Z2lqQ=
kcl-lang.io/lib v0.7.3/go.mod h1:ubsalGXxJaa5II/EsHmsI/tL2EluYHIcW+BwzQPt+uY=
oras.land/oras-go v1.2.3 h1:v8PJl+gEAntI1pJ/LCrDgsuk+1PKVavVEPsYIHFE5uY=
Expand Down
25 changes: 21 additions & 4 deletions pkg/options/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,37 @@ func NewRunOptions() *RunOptions {
func (o *RunOptions) Run() error {
var result *kcl.KCLResultList
var err error
opts := CompileOptionFromCli(o)
cli, err := client.NewKpmClient()
if o.Quiet {
cli.SetLogWriter(nil)
if err != nil {
return err
}
// acquire the lock of the package cache.
err = cli.AcquirePackageCacheLock()
if err != nil {
return err
}
pwd, err := os.Getwd()
defer func() {
// release the lock of the package cache after the function returns.
releaseErr := cli.ReleasePackageCacheLock()
if releaseErr != nil && err == nil {
err = releaseErr
}
}()
opts := CompileOptionFromCli(o)
if o.Quiet {
cli.SetLogWriter(nil)
}
if err != nil {
return err
}
entry, errEvent := runner.FindRunEntryFrom(opts.Entries())
if errEvent != nil {
return errEvent
}
pwd, err := os.Getwd()
if err != nil {
return err
}
if entry.IsEmpty() {
// kcl compiles the current package under '$pwd'.
if _, e := api.GetKclPackage(pwd); e == nil {
Expand Down Expand Up @@ -137,9 +152,11 @@ func (o *RunOptions) Run() error {
result, err = cli.CompileWithOpts(opts)
} else if entry.IsTar() {
// kcl compiles the package from the kcl package tar.
opts.SetEntries([]string{})
result, err = cli.CompileTarPkg(entry.PackageSource(), opts)
} else if entry.IsUrl() {
// kcl compiles the package from the OCI reference or url.
opts.SetEntries([]string{})
result, err = cli.CompileOciPkg(entry.PackageSource(), o.Tag, opts)
} else {
// If there is only kcl file without kcl package (kcl.mod)
Expand Down

0 comments on commit 2dd33c7

Please sign in to comment.