diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index f44d298..786873c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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 @@ -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 @@ -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 diff --git a/README.md b/README.md index 27f7c33..1d804f2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ vfox add php # install an available version vfox search php # or specific version -vfox install php@8.3.3 +vfox install php@8.4.5 + +# or nts version +vfox install php@8.4.5-nts ``` ## Prerequirements diff --git a/hooks/available.lua b/hooks/available.lua index 6a7a19c..59e5027 100644 --- a/hooks/available.lua +++ b/hooks/available.lua @@ -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 diff --git a/hooks/post_install.lua b/hooks/post_install.lua index 6cc7f9f..9e11736 100644 --- a/hooks/post_install.lua +++ b/hooks/post_install.lua @@ -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 diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 61c9031..f9fa16e 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -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 @@ -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 diff --git a/lib/constants.lua b/lib/constants.lua index a442863..ce2e09a 100644 --- a/lib/constants.lua +++ b/lib/constants.lua @@ -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/' diff --git a/lib/util.lua b/lib/util.lua index 563c992..6b62ab5 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -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') diff --git a/metadata.lua b/metadata.lua index 28ef7d2..21ccf90 100644 --- a/metadata.lua +++ b/metadata.lua @@ -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.