build_artifacts.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import("core.package.package")
  2. import("core.base.semver")
  3. import("packages")
  4. function build_artifacts(name, versions)
  5. local buildinfo = {name = name, versions = versions}
  6. print(buildinfo)
  7. os.tryrm("build-artifacts")
  8. os.exec("git clone [email protected]:xmake-mirror/build-artifacts.git -b build")
  9. local oldir = os.cd("build-artifacts")
  10. local trycount = 0
  11. while trycount < 2 do
  12. local ok = try
  13. {
  14. function ()
  15. io.save("build.txt", buildinfo)
  16. os.exec("git add -A")
  17. os.exec("git commit -a -m \"autobuild %s by xmake-repo/ci\"", name)
  18. os.exec("git push origin build")
  19. return true
  20. end,
  21. catch
  22. {
  23. function ()
  24. os.exec("git reset --hard HEAD^")
  25. os.exec("git pull origin build")
  26. end
  27. }
  28. }
  29. if ok then
  30. break
  31. end
  32. trycount = trycount + 1
  33. end
  34. assert(trycount < 2)
  35. os.cd(oldir)
  36. end
  37. function main()
  38. local files = os.iorun("git diff --name-only HEAD^")
  39. for _, file in ipairs(files:split('\n'), string.trim) do
  40. if file:find("packages", 1, true) and path.filename(file) == "xmake.lua" then
  41. assert(file == file:lower(), "%s must be lower case!", file)
  42. local packagedir = path.directory(file)
  43. local packagename = path.filename(packagedir)
  44. if #path.filename(path.directory(packagedir)) == 1 then
  45. local instance = package.load_from_repository(packagename, nil, packagedir, file)
  46. if instance and packages.is_supported(instance, "windows")
  47. and (instance.is_headeronly and not instance:is_headeronly()) then
  48. local versions = instance:versions()
  49. if versions and #versions > 0 then
  50. table.sort(versions, function (a, b) return semver.compare(a, b) > 0 end)
  51. local version_latest = versions[1]
  52. build_artifacts(instance:name(), table.wrap(version_latest))
  53. end
  54. end
  55. end
  56. end
  57. end
  58. end