generated from version-fox/vfox-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
211 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: update_versions | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * 1" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Update version file | ||
run: | | ||
cd assets | ||
python -m pip install requests | ||
python -m pip install bs4 | ||
python get_versions.py | ||
- name: Push updated version file | ||
run: | | ||
pwd | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]"github-actions[bot] | ||
if [[ -n $(git status -s) ]]; then | ||
git add . | ||
git commit -m "chore(versions.txt): update Cmake version file" | ||
git push https://github-actions[bot]:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git | ||
else | ||
echo "never updated." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
# vfox-plugin-template | ||
|
||
This is a [vfox plugin](https://vfox.lhan.me/plugins/create/howto.html) template with CI that package and publish the plugin. | ||
|
||
## Usage | ||
|
||
1. [Generate](https://github.com/version-fox/vfox-plugin-template/generate) a new repository based on this template. | ||
2. Configure [metadata](https://github.com/version-fox/vfox-plugin-template/blob/main/metadata.lua) information | ||
3. To develop your plugin further, please read [the plugins create section of the docs](https://vfox.lhan.me/plugins/create/howto.html). | ||
|
||
|
||
## How to publish? | ||
|
||
1. Push a new tag to the repository which name is `vX.Y.Z` (X.Y.Z is the version number). | ||
2. The CI will automatically package, then publish [release](https://github.com/version-fox/vfox-plugin-template/releases/tag/v0.0.1) and publish [manifest](https://github.com/version-fox/vfox-plugin-template/releases/tag/manifest). | ||
# Introduction | ||
vfox-cmake is a plugin for [vfox](https://vfox.lhan.me/). | ||
# Install | ||
After installing vfox, run the following command to add the plugin: | ||
```bash | ||
vfox add cmake | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
import re | ||
import json | ||
|
||
def get_info(): | ||
base_url = "https://cmake.org/files/" | ||
|
||
releases = {'darwin': [],'windows':[],"linux":[]} | ||
resp = requests.get(base_url) | ||
resp.raise_for_status() | ||
|
||
big_version_urls = [] | ||
soup = BeautifulSoup(resp.content, 'html.parser') | ||
|
||
for a in soup.find_all('a', href=True): | ||
href = a['href'] | ||
sn = re.match(r'^v\d', href) | ||
es = href.endswith('/') | ||
version = href[:-1] | ||
if sn and es : | ||
big_version_urls.append(base_url + version) | ||
|
||
pattern = r"cmake-(\d+\.\d+\.?\d*[-\w\d]*)-([\w\d]+)-([\w\d_-]+)" | ||
|
||
for url in big_version_urls: | ||
resp = requests.get(url) | ||
resp.raise_for_status() | ||
soup = BeautifulSoup(resp.content, 'html.parser') | ||
|
||
for a in soup.find_all('a', href=True): | ||
href = a['href'] | ||
sn = re.match(r'^cmake', href) | ||
es = href.endswith('.txt') | ||
if sn and es: | ||
resp = requests.get(url + '/' + href) | ||
resp.raise_for_status() | ||
sha256_files = resp.text.split('\n') | ||
macos_universal_versions = set() | ||
for line in sha256_files: | ||
if is_matched(line): | ||
sha256, filename = line.split() | ||
if re.match(pattern, filename): | ||
version, os, arch = re.match(pattern, filename).groups() | ||
else: | ||
continue | ||
os = os.lower() | ||
arch = arch.lower() | ||
download_url = url + '/' + filename | ||
|
||
if os in ["macos","darwin"]: | ||
if arch =="x86_64": | ||
if version not in macos_universal_versions: | ||
releases["darwin"].append({'arch':'amd64','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
elif arch == "universal": | ||
releases["darwin"].append({'arch':'','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
macos_universal_versions.add(version) | ||
elif os in["windows","win32","win64"]: | ||
if arch in ["x64", "x86_64"]: | ||
releases["windows"].append({'arch':'amd64','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
elif arch in ["i386", "x86"]: | ||
releases["windows"].append({'arch':'386','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
elif arch == "arm64": | ||
releases["windows"].append({'arch':'arm64','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
elif os == "linux": | ||
if arch in ["i386", "aarch64"]: | ||
releases["linux"].append({'arch':'386','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
elif arch == "x86_64": | ||
releases["linux"].append({'arch':'amd64','version': version, 'download_url': download_url, 'sha256': sha256}) | ||
with open("version.json", 'w', encoding="utf-8") as file: | ||
json.dump(releases, file, indent=4) | ||
|
||
def is_matched(line): | ||
line = line.lower() | ||
return any(sub in line for sub in ["macos", "darwin","windows", "win32", "win64","linux"]) and (line.endswith(".tar.gz") or line.endswith(".zip")) | ||
|
||
if __name__ == "__main__": | ||
get_info() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
local util = require("util") | ||
--- Returns some pre-installed information, such as version number, download address, local files, etc. | ||
--- If checksum is provided, vfox will automatically check it for you. | ||
--- @param ctx table | ||
--- @field ctx.version string User-input version | ||
--- @return table Version information | ||
function PLUGIN:PreInstall(ctx) | ||
local version = ctx.version | ||
return { | ||
--- Version number | ||
version = "xxx", | ||
--- remote URL or local file path [optional] | ||
url = "xxx", | ||
--- SHA256 checksum [optional] | ||
sha256 = "xxx", | ||
--- md5 checksum [optional] | ||
md5 = "xxx", | ||
--- sha1 checksum [optional] | ||
sha1 = "xxx", | ||
--- sha512 checksum [optional] | ||
sha512 = "xx", | ||
--- additional need files [optional] | ||
addition = { | ||
{ | ||
--- additional file name ! | ||
name = "xxx", | ||
--- remote URL or local file path [optional] | ||
url = "xxx", | ||
--- SHA256 checksum [optional] | ||
sha256 = "xxx", | ||
--- md5 checksum [optional] | ||
md5 = "xxx", | ||
--- sha1 checksum [optional] | ||
sha1 = "xxx", | ||
--- sha512 checksum [optional] | ||
sha512 = "xx", | ||
} | ||
} | ||
} | ||
if #util.RELEASES == 0 then | ||
self:Available(ctx) | ||
end | ||
local releases = util.RELEASES | ||
for _, release in ipairs(releases) do | ||
if release.version == ctx.version then | ||
return release | ||
end | ||
end | ||
return {} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,70 @@ | ||
local http = require("http") | ||
local json = require("json") | ||
|
||
local util = {} | ||
|
||
function util:DoSomeThing() | ||
print("Do some thing") | ||
util.__index = util | ||
local utilSingleton = setmetatable({}, util) | ||
|
||
utilSingleton.BASE_URL = "https://cmake.org/files/" | ||
utilSingleton.RELEASES ={} | ||
|
||
function util:compare_versions(v1o, v2o) | ||
local v1 = v1o.version | ||
local v2 = v2o.version | ||
local v1_parts = {} | ||
for part in string.gmatch(v1, "[^.]+") do | ||
table.insert(v1_parts, tonumber(part)) | ||
end | ||
|
||
local v2_parts = {} | ||
for part in string.gmatch(v2, "[^.]+") do | ||
table.insert(v2_parts, tonumber(part)) | ||
end | ||
|
||
for i = 1, math.max(#v1_parts, #v2_parts) do | ||
local v1_part = v1_parts[i] or 0 | ||
local v2_part = v2_parts[i] or 0 | ||
if v1_part > v2_part then | ||
return true | ||
elseif v1_part < v2_part then | ||
return false | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
function util:getInfo() | ||
local result = {} | ||
local resp, err = http.get({ | ||
url = "https://fastly.jsdelivr.net/gh/ahai-code/vfox-cmake@main/assets/version.json" | ||
}) | ||
|
||
if err ~= nil then | ||
error("Failed to get information: " .. err) | ||
end | ||
if resp.status_code ~= 200 then | ||
error("Failed to get information: status_code =>" .. resp.status_code) | ||
end | ||
|
||
local respInfo = json.decode(resp.body)[RUNTIME.osType] | ||
|
||
for _, info in pairs(respInfo) do | ||
for _, obj in ipairs(info) do | ||
if obj.arch=="" then | ||
table.insert(result, {version = obj.version,note=""}) | ||
table.insert(utilSingleton.RELEASES,{version = obj.version,url=obj.download_url,sha256=obj.sha256}) | ||
elseif obj.arch == RUNTIME.archType then | ||
table.insert(result, {version = obj.version,note=""}) | ||
table.insert(utilSingleton.RELEASES,{version = obj.version,url=obj.download_url,sha256=obj.sha256}) | ||
end | ||
end | ||
end | ||
table.sort(result, function(a, b) | ||
return util:compare_versions(a,b) | ||
end) | ||
return result | ||
end | ||
|
||
return util | ||
return utilSingleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters