Move packagist check to a Haskell binary

This commit is contained in:
Eugen Wissner 2023-08-04 21:33:21 +02:00
parent 1bc410d86d
commit 028f64d25a
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
5 changed files with 93 additions and 7 deletions

2
.gitignore vendored
View File

@ -14,7 +14,6 @@
*.lz
*.pk3
*.run
*.Z
*.deb
*.jar
*~
@ -26,3 +25,4 @@
/vendor/
/.bundle/
/pkg/
/dist-newstyle/

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
# Revision history for slackbuilder
## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world.

46
app/Main.hs Normal file
View File

@ -0,0 +1,46 @@
module Main
( main
) where
import Data.Aeson.TH (defaultOptions, deriveJSON)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Text (Text)
import qualified Data.Text.IO as Text.IO
import Data.Vector (Vector)
import qualified Data.Vector as Vector
import Network.HTTP.Req
( runReq
, defaultHttpConfig
, req
, GET(..)
, https
, jsonResponse
, NoReqBody(..)
, (/:)
, responseBody
)
import Data.Maybe (fromMaybe)
newtype PackagistPackage = PackagistPackage
{ version :: Text
} deriving (Eq, Show)
$(deriveJSON defaultOptions ''PackagistPackage)
newtype PackagistResponse = PackagistResponse
{ packages :: HashMap Text (Vector PackagistPackage)
} deriving (Eq, Show)
$(deriveJSON defaultOptions ''PackagistResponse)
main :: IO ()
main = do
packagistResponse <- runReq defaultHttpConfig $
let uri = https "repo.packagist.org" /: "p2" /: "composer" /: "composer.json"
in req GET uri NoReqBody jsonResponse mempty
let packagistPackages = packages $ responseBody packagistResponse
Text.IO.putStrLn $ fromMaybe ""
$ HashMap.lookup "composer/composer" packagistPackages
>>= fmap (version . fst) . Vector.uncons

View File

@ -77,12 +77,7 @@ module SlackBuilder
end
def latest
full_name = [@vendor, @name].join '/'
uri = URI "https://repo.packagist.org/p2/#{full_name}.json"
response = Net::HTTP.get uri, {
'content-type' => 'application/json'
}
JSON.parse(response)['packages'][full_name].first['version']
`./bin/slackbuilder #{@vendor} #{@name}`.strip
end
end

40
slackbuilder.cabal Normal file
View File

@ -0,0 +1,40 @@
cabal-version: 2.4
name: slackbuilder
version: 0.1.0.0
-- A short (one-line) description of the package.
-- synopsis:
-- A longer description of the package.
-- description:
bug-reports: https://git.caraus.tech/OSS/slackbuilder/issues
license: MPL-2.0
license-files: LICENSE
copyright: (c) 2023 Eugen Wissner
author: Eugen Wissner
maintainer: belka@caraus.de
category: Build
extra-source-files: CHANGELOG.md
executable slackbuilder
main-is: Main.hs
-- Modules included in this executable, other than Main.
-- other-modules:
default-extensions:
OverloadedStrings
TemplateHaskell
build-depends:
aeson ^>= 2.2.0,
base ^>= 4.16.4.0,
req ^>=3.13,
text ^>= 2.0,
unordered-containers ^>= 0.2.19,
vector ^>= 0.13.0
hs-source-dirs: app
default-language: Haskell2010