ruki 4 лет назад
Родитель
Сommit
a7cc62683f
3 измененных файлов с 58 добавлено и 6 удалено
  1. 4 1
      .github/workflows/deploy.yml
  2. 49 0
      scripts/build_artifacts.lua
  3. 5 5
      scripts/packages.lua

+ 4 - 1
.github/workflows/deploy.yml

@@ -35,7 +35,7 @@ jobs:
           export PATH=`pwd`/node-v14.15.4-linux-x64/bin:$PATH
           sudo npm install markdown-to-html -g
 
-      - name: Publish
+      - name: Publish documents
         run: |
           git clone [email protected]:xmake-io/xrepo-docs.git
           cd xrepo-docs
@@ -51,4 +51,7 @@ jobs:
           git diff-index --quiet HEAD || git commit -m "autoupdate docs by xmake-repo/ci"
           git push all master
 
+      - name: Build artifacts
+        run: |
+          xmake l scripts/build_artifacts.lua
 

+ 49 - 0
scripts/build_artifacts.lua

@@ -0,0 +1,49 @@
+import("core.package.package")
+import("core.base.semver")
+import("packages")
+
+function build_artifacts(name, versions)
+    local buildinfo = {name = name, versions = versions}
+    print(buildinfo)
+    os.exec("git clone [email protected]:xmake-mirror/build-artifacts.git -b build")
+    local oldir = os.cd("build-artifacts")
+    local trycount = 0
+    while trycount < 2 do
+        local ok = try { function ()
+            os.exec("git reset --hard HEAD^")
+            os.exec("git pull origin build")
+            io.save("build.txt", buildinfo)
+            os.exec("git add -A")
+            os.exec("git commit -a -m \"autobuild %s by xmake-repo/ci\"", name)
+            os.exec("git push origin build")
+            return true
+        end }
+        if ok then
+            break
+        end
+        trycount = trycount + 1
+    end
+    assert(trycount < 2)
+    os.cd(oldir)
+end
+
+function main()
+    local files = os.iorun("git diff --name-only HEAD^")
+    for _, file in ipairs(files:split('\n'), string.trim) do
+       if file:find("packages", 1, true) and path.filename(file) == "xmake.lua" then
+           assert(file == file:lower(), "%s must be lower case!", file)
+           local packagedir = path.directory(file)
+           local packagename = path.filename(packagedir)
+           local instance = package.load_from_repository(packagename, nil, packagedir, file)
+           if instance and packages.is_supported(instance, "windows")
+              and (instance.is_headeronly and not instance:is_headeronly()) then
+               local versions = instance:versions()
+               if versions and #versions > 0 then
+                   table.sort(versions, function (a, b) return semver.compare(a, b) > 0 end)
+                   local version_latest = versions[1]
+                   build_artifacts(instance:name(), table.wrap(version_latest))
+               end
+           end
+       end
+    end
+end

+ 5 - 5
scripts/packages.lua

@@ -3,7 +3,7 @@ import("core.package.package")
 import("core.platform.platform")
 
 -- is supported platform and architecture?
-function _is_supported(instance, plat, arch, opt)
+function is_supported(instance, plat, arch, opt)
 
     -- get script
     local script = instance:get("install")
@@ -29,17 +29,17 @@ function _is_supported(instance, plat, arch, opt)
         for _pattern, _script in pairs(script) do
             local hosts = {}
             local hosts_spec = false
-            _pattern = _pattern:gsub("@(.+)", function (v) 
+            _pattern = _pattern:gsub("@(.+)", function (v)
                 for _, host in ipairs(v:split(',')) do
                     hosts[host] = true
                     hosts_spec = true
                 end
-                return "" 
+                return ""
             end)
             if _pattern:trim() == "" and opt and opt.onlyhost then
                 _pattern = os.subhost()
             end
-            if not _pattern:startswith("__") and (not hosts_spec or hosts[os.subhost() .. '|' .. os.subarch()] or hosts[os.subhost()])  
+            if not _pattern:startswith("__") and (not hosts_spec or hosts[os.subhost() .. '|' .. os.subarch()] or hosts[os.subhost()])
             and (_pattern:trim() == "" or (plat .. '|' .. arch):find('^' .. _pattern .. '$') or plat:find('^' .. _pattern .. '$')) then
                 result = _script
                 break
@@ -65,7 +65,7 @@ function main(opt)
                 if archs then
                     local package_archs = {}
                     for _, arch in ipairs(archs) do
-                        if _is_supported(instance, plat, arch, opt) then
+                        if is_supported(instance, plat, arch, opt) then
                             table.insert(package_archs, arch)
                         end
                     end