Skip to content
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
16 changes: 8 additions & 8 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: |
echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "VERSION=$(echo ${{ github.ref }} | cut -d'/' -f3 | cut -c2-)" >> $GITHUB_ENV
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Lua
uses: leafo/gh-actions-lua@v8
Expand All @@ -30,14 +30,14 @@ jobs:
- name: Generate manifest
run: |
sudo lua -e '
require("metadata");
local dkjson = require("dkjson");
PLUGIN.downloadUrl = "https://github.com/${{ github.repository }}/releases/download/v${{ env.VERSION }}/${{ env.REPO_NAME }}-${{ env.VERSION }}.zip";
local str = dkjson.encode(PLUGIN);
require("metadata");
local dkjson = require("dkjson");
PLUGIN.downloadUrl = "https://github.com/${{ github.repository }}/releases/download/v${{ env.VERSION }}/${{ env.REPO_NAME }}-${{ env.VERSION }}.zip";
local str = dkjson.encode(PLUGIN);
print(str)' > manifest.json
cat manifest.json
- name: Upload JSON file
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: manifest
path: manifest.json
Expand All @@ -50,9 +50,9 @@ jobs:
echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "VERSION=$(echo ${{ github.ref }} | cut -d'/' -f3 | cut -c2-)" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Download JSON file
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: manifest
- name: Compress build files
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ vfox add php
# install an available version
vfox search php
# or specific version
vfox install [email protected]
vfox install [email protected]

# or nts version
vfox install [email protected]
```

## Prerequirements
Expand Down
80 changes: 50 additions & 30 deletions hooks/available.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,65 @@ function PLUGIN:Available(ctx)
end

function GetReleaseListForWindows()
local resp, err = http.get({
url = WIN_URL
})
local doc = html.parse(resp.body)

local result = {}
doc:find('a'):each(function(i, selection)
local versionStr = selection:text()
if util.filter_windows_version(versionStr) then
local versions = util.split_string(versionStr, '-')
if util.compare_versions(versions[2], "5.3.2") >= 0 then
table.insert(result, {
version = versions[2],
name = versionStr,
})
local urls = { WIN_RELEASES_URL, WIN_RELEASES_URL_LTS }

for _, url in ipairs(urls) do
local resp, err = http.get({ url = url })

if resp then
local doc = html.parse(resp.body)
local versions = {}
doc:find('a'):each(function(i, selection)
local versionStr = selection:text()
table.insert(versions, versionStr)
end)
-- TODO like this because for some reason sorting it at the end resets is_from_lts to false
table.sort(versions, function(a, b)
return util.compare_versions(a, b) > 0
end)
for _, versionStr in ipairs(versions) do
if util.filter_windows_version(versionStr) then
local versions = util.split_string(versionStr, '-')
if util.compare_versions(versions[2], "5.3.2") >= 0 then
local entry = {
version = (versions[3] ~= "nts") and versions[2] or versions[2] .. "-nts",
name = versionStr
}

entry.is_from_lts = (url == WIN_RELEASES_URL_LTS)
table.insert(result, entry)
end
end
end
end
end)
table.sort(result, function(a, b)
return util.compare_versions(a.version, b.version) > 0
end)
end

return result
end

function GetReleaseListForLinux()
local resp, err = http.get({
url = URL .. '/releases'
})
local doc = html.parse(resp.body)

local result = {}
doc:find("#layout-content h2"):each(function(i, selection)
local versionStr = selection:text()
if util.compare_versions(versionStr, "5.3.2") >= 0 then
table.insert(result, {
version = versionStr,
})
local urls = { RELEASES_URL, RELEASES_URL_LTS }

for _, url in ipairs(urls) do
local resp, err = http.get({ url = url })
local is_from_lts = (url == RELEASES_URL_LTS)

if resp then
local doc = html.parse(resp.body)
local query = "#layout-content " .. (is_from_lts and "h3" or "h2")
doc:find(query):each(function(i, selection)
local versionStr = is_from_lts and selection:attr("id") or selection:text()
versionStr = versionStr:gsub("^v", "")
if util.compare_versions(versionStr, "5.3.2") >= 0 then
table.insert(result, {
version = versionStr,
})
end
end)
end
end)
end

table.sort(result, function(a, b)
return util.compare_versions(a.version, b.version) > 0
Expand Down
25 changes: 24 additions & 1 deletion hooks/post_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,35 @@ function InstallComposerForWin(path)
error(err)
end

local code = os.execute(path .. '\\php.exe ' .. setup .. ' --install-dir=' .. path)
local phpPath = path .. "\\php.exe"
local setupPath = setup
local installPath = path
local execString = phpPath .. ' ' .. setupPath .. ' --install-dir=' .. installPath


if RUNTIME.osType == 'windows' then
phpPath = "\"" .. phpPath .. "\""
setupPath = "\"" .. setupPath .. "\""
installPath = "\"" .. installPath .. "\""

local winPrefix = ''

util.write_file(path .. '\\composer_install.bat', winPrefix .. phpPath .. ' ' .. setupPath .. ' --install-dir=' .. installPath)

execString = path .. '\\composer_install.bat'
end

local code = os.execute(execString)
if code ~= 0 then
error('Failed to install composer.')
end

os.remove(setup)

if RUNTIME.osType == 'windows' then
os.remove(path .. '\\composer_install.bat')
end

util.write_file(path .. '\\composer.bat', '@php "%~dp0composer.phar" %*')
end

Expand Down
10 changes: 7 additions & 3 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ require('constants')
--- @return table Version information
function PLUGIN:PreInstall(ctx)
local version = ctx.version

local lists = self:Available({})
if version == 'latest' or version == '' then
version = lists[1].version
end
end

local versions = {}
for _, value in pairs(lists) do
Expand All @@ -40,9 +39,14 @@ function PLUGIN:PreInstall(ctx)
end

function GetReleaseForWindows(versions)
url = WIN_RELEASES_URL .. versions.name

if (versions.is_from_lts) then
url = WIN_RELEASES_URL_LTS .. versions.name
end
return {
version = versions.version,
url = WIN_URL .. versions.name,
url = url,
}
end

Expand Down
7 changes: 5 additions & 2 deletions lib/constants.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
URL = 'https://www.php.net/'
WIN_URL = 'https://windows.php.net/downloads/releases/archives/'
URL = 'https://www.php.net'
RELEASES_URL = URL .. '/releases/'
RELEASES_URL_LTS = URL .. '/downloads.php'
WIN_RELEASES_URL = 'https://windows.php.net/downloads/releases/archives/'
WIN_RELEASES_URL_LTS = 'https://windows.php.net/downloads/releases/'
1 change: 0 additions & 1 deletion lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ end

function util.filter_windows_version(version)
return util.starts_with(version, 'php')
and string.find(version, 'nts')
and not util.starts_with(version, 'php-debug')
and not util.starts_with(version, 'php-devel')
and not util.starts_with(version, 'php-test')
Expand Down
2 changes: 1 addition & 1 deletion metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PLUGIN = {}
--- Plugin name
PLUGIN.name = "php"
--- Plugin version
PLUGIN.version = "0.2.0"
PLUGIN.version = "0.2.1"
--- Plugin homepage
PLUGIN.homepage = "https://github.com/version-fox/vfox-php"
--- Plugin license, please choose a correct license according to your needs.
Expand Down