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

Allow using latest as git commit #4

Merged
merged 2 commits into from
Aug 1, 2023
Merged
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: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ modules: {}
* `paths`: a list of strings indicating the path to .deb files (or just a list of prefixes to search for .deb files) when used with"dpkg" or "dpkg-buildpackage", or a list of paths to .inst files which contain a list of packages to install when used with "apt".
* `url`: a string indicating the URL to retrieve the source code, only required if source type is "tar" or "git".
* `type`: a string indicating the type of source control system, currently "tar" and "git" are supported.
* `tag`: a string indicating the git tag to use, only used if type is "git".
* `commit`: a string indicating the git commit to use, only used if type is "git".
* `tag`: a string indicating the git tag to use, only used if type is "git". Use either this or `branch` and `commit`.
* `branch`: a string indicating the git branch to pull from, only used if type is "git". Use either this and `commit` or `tag`.
* `commit`: a string with the commit hash to use, only used if type is "git". Passing "latest" to this field will use the most recent commmit from the branch specified above. Use either this and `branch` or `tag`.
* `buildFlags`: an array of strings indicating any additional build flags or options. Only used if type is "meson" or "go".
* `buildVars`: a collection of key-value pairs indicating any additional build variables. Only used if type is "go".
* `modules`: an array of objects containing the modules needed to build the source code.
Expand Down
13 changes: 13 additions & 0 deletions core/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
)

// ResolveSources resolves the sources of a recipe and downloads them
Expand Down Expand Up @@ -106,6 +107,18 @@ func DownloadGitSource(recipe *Recipe, source Source) error {
return err
}

if source.Commit == "latest" {
cmd := exec.Command(
"git", "--no-pager", "log", "-n", "1", "--pretty=format:\"%H\"", source.Branch,
)
cmd.Dir = dest
latest_tag, err := cmd.Output()
if err != nil {
return err
}
source.Commit = strings.Trim(string(latest_tag), "\"")
}

fmt.Printf("Checking out branch: %s\n", source.Branch)
cmd = exec.Command(
"git",
Expand Down