Compare commits
81 Commits
ec704e267b
...
master
Author | SHA1 | Date | |
---|---|---|---|
731a36d700
|
|||
8908b8ae93
|
|||
1d81fea1a3
|
|||
e2debec6d7
|
|||
d043ba8844
|
|||
e1ece39147
|
|||
15cf346c61
|
|||
468852410e
|
|||
b5e6e3a2d6
|
|||
2f46303a6d
|
|||
c7e300dc91
|
|||
bb0748b400 | |||
6290be859d
|
|||
f395d57b33
|
|||
8168804d71
|
|||
d9bfd2941c
|
|||
ebbdb6f0f7
|
|||
f758ea7904
|
|||
00cc58f87e
|
|||
2a78256933
|
|||
ae63ff0cc0
|
|||
5b4caa8ff7
|
|||
3dde41e0d4
|
|||
74da0eb391
|
|||
6ead225e88
|
|||
1418e0ae46
|
|||
4f74c2ec10
|
|||
14cc805dcf
|
|||
42b9b671e1
|
|||
e0ca80db32
|
|||
4ce20e3dd9
|
|||
6d0248b4f8
|
|||
c81cabfcbf
|
|||
3b7b15f381
|
|||
f8ef93fde7
|
|||
6ba319c3b6
|
|||
ddda240e40
|
|||
8351be053c
|
|||
a98a6f8574
|
|||
47f27394de
|
|||
7c9c890056
|
|||
7e59a8460d
|
|||
bc3ba48d85
|
|||
3d81917627
|
|||
cd28e6fb90
|
|||
16c7063224
|
|||
cd15b25db1
|
|||
e5bde183a5
|
|||
4c06ae274b
|
|||
c8643a2fd4
|
|||
45472a9088
|
|||
2802194063
|
|||
7edb811dc2
|
|||
a25655c2b2
|
|||
34d7dbd68f
|
|||
49cbda6027
|
|||
eb68629653
|
|||
6a063b2cc4
|
|||
e9504fb8e5
|
|||
ef0a5b5958
|
|||
49d6718fee
|
|||
3414a69bc8 | |||
9770cc8829 | |||
0023fe0337 | |||
24e62c3439 | |||
64233c4c63 | |||
396a536b3a | |||
f51a0418ff | |||
fa6d93c5ca | |||
6c0e2c2d24 | |||
58a1b8864c
|
|||
8a69240d88
|
|||
3a6d17952b
|
|||
4105ffa91f
|
|||
5e161c3dad
|
|||
f3beee3e19
|
|||
7b5598a02e
|
|||
d5df676df7
|
|||
f4b7883cf2
|
|||
69b24c6cfa | |||
7c499bd3f7 |
37
.gitea/workflows/build.yml
Normal file
37
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,37 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
audit:
|
||||
runs-on: buildenv
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: hlint src lib tests
|
||||
|
||||
test:
|
||||
runs-on: buildenv
|
||||
steps:
|
||||
- name: Set up environment
|
||||
run: |
|
||||
apt-get update -y
|
||||
apt-get upgrade -y
|
||||
apt-get install -y pkg-config liblzma-dev
|
||||
- uses: actions/checkout@v4
|
||||
- run: cabal update
|
||||
- run: cabal test --test-show-details=streaming
|
||||
|
||||
release:
|
||||
runs-on: buildenv
|
||||
steps:
|
||||
- name: Set up environment
|
||||
run: |
|
||||
apt-get update -y
|
||||
apt-get upgrade -y
|
||||
apt-get install -y pkg-config liblzma-dev
|
||||
- uses: actions/checkout@v4
|
||||
- run: cabal update
|
||||
- run: cabal build
|
29
.gitea/workflows/deploy.yaml
Normal file
29
.gitea/workflows/deploy.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: buildenv
|
||||
steps:
|
||||
- name: Set up environment
|
||||
run: |
|
||||
apt-get update -y
|
||||
apt-get upgrade -y
|
||||
apt-get install -y pkg-config liblzma-dev
|
||||
- uses: actions/checkout@v4
|
||||
- run: cabal update
|
||||
- run: cabal build
|
||||
- name: Archive
|
||||
run: |
|
||||
DISTRIBUTION=$(echo $GITHUB_REF_NAME | awk '{ gsub(/^v/, "slackbuilder-"); print $0 }')
|
||||
cabal install --installdir=$DISTRIBUTION/bin --install-method=copy
|
||||
strip $DISTRIBUTION/bin/slackbuilder
|
||||
tar Jcvf $DISTRIBUTION.tar.xz $DISTRIBUTION
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
files: "*.tar.xz"
|
||||
token: ${{ secrets.API_KEY }}
|
2
.hlint.yaml
Normal file
2
.hlint.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
arguments:
|
||||
- -XQuasiQuotes
|
41
.rubocop.yml
41
.rubocop.yml
@ -1,41 +0,0 @@
|
||||
AllCops:
|
||||
Exclude:
|
||||
- 'vendor/**/*'
|
||||
- '.git/**/*'
|
||||
- 'slackbuilds/**/*'
|
||||
- 'bin/bundle'
|
||||
- 'bin/cap*'
|
||||
- 'bin/rake'
|
||||
- 'bin/rspec'
|
||||
- 'bin/rubocop'
|
||||
- 'bin/setup'
|
||||
- 'bin/spring'
|
||||
- 'bin/update'
|
||||
- 'pkg/**/*'
|
||||
|
||||
TargetRubyVersion: '3.0'
|
||||
NewCops: enable
|
||||
SuggestExtensions: false
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
# False-Positive: non-string-variable + 'some string'
|
||||
Style/StringConcatenation:
|
||||
Enabled: false
|
||||
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
EnforcedStyle: indented
|
||||
|
||||
Layout/MultilineOperationIndentation:
|
||||
EnforcedStyle: indented
|
||||
|
||||
Layout/ArgumentAlignment:
|
||||
EnforcedStyle: with_fixed_indentation
|
||||
|
||||
Layout/EndAlignment:
|
||||
EnforcedStyleAlignWith: variable
|
||||
|
||||
Metrics/BlockLength:
|
||||
AllowedMethods:
|
||||
- namespace
|
15
Gemfile
15
Gemfile
@ -1,15 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
|
||||
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
||||
|
||||
gem 'rake', '~> 13.0'
|
||||
gem 'rubocop', '~> 1.53.1', require: false
|
||||
|
||||
gem 'progressbar', '~> 1.11'
|
||||
gem 'term-ansicolor', '~> 1.7'
|
48
Gemfile.lock
48
Gemfile.lock
@ -1,48 +0,0 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.2)
|
||||
json (2.6.3)
|
||||
language_server-protocol (3.17.0.3)
|
||||
parallel (1.23.0)
|
||||
parser (3.2.2.3)
|
||||
ast (~> 2.4.1)
|
||||
racc
|
||||
progressbar (1.13.0)
|
||||
racc (1.7.1)
|
||||
rainbow (3.1.1)
|
||||
rake (13.0.6)
|
||||
regexp_parser (2.8.1)
|
||||
rexml (3.2.6)
|
||||
rubocop (1.53.1)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (>= 3.17.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.2.2.3)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8, < 3.0)
|
||||
rexml (>= 3.2.5, < 4.0)
|
||||
rubocop-ast (>= 1.28.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 2.4.0, < 3.0)
|
||||
rubocop-ast (1.29.0)
|
||||
parser (>= 3.2.1.0)
|
||||
ruby-progressbar (1.13.0)
|
||||
sync (0.5.0)
|
||||
term-ansicolor (1.7.1)
|
||||
tins (~> 1.0)
|
||||
tins (1.32.1)
|
||||
sync
|
||||
unicode-display_width (2.4.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
progressbar (~> 1.11)
|
||||
rake (~> 13.0)
|
||||
rubocop (~> 1.53.1)
|
||||
term-ansicolor (~> 1.7)
|
||||
|
||||
BUNDLED WITH
|
||||
2.2.33
|
79
README.md
Normal file
79
README.md
Normal file
@ -0,0 +1,79 @@
|
||||
# SlackBuilder
|
||||
|
||||
SlackBuilder is a tool which aims to help to update Slackware packages.
|
||||
It checks for the latest version of an upstream package and can modify
|
||||
SlackBuild meta information accordingly.
|
||||
|
||||
## Features
|
||||
|
||||
- Querying various sources (like registries) for the latest upstream version.
|
||||
Currently supported sources are:
|
||||
- GitHub
|
||||
- Packagist
|
||||
- Remote text file containing a version number (like the LATEST file).
|
||||
- Updating package version and checksum in the .info file;
|
||||
Updating version variables in the .SlackBuild
|
||||
- Updating packages with multiple sources. One source is assumed to be the main
|
||||
source and match the version of the package. Other sources are just updated to
|
||||
the latest version available for them.
|
||||
- Modifying or just reuploading source tarballs to a different destination.
|
||||
SlackBuilder can download the original source tarball, optionally extract and
|
||||
modify its contents, and upload it to another server. It can be used for
|
||||
example to download package dependencies to ship them all within a single
|
||||
archive, so the package can be built offline.
|
||||
|
||||
## Build instructions
|
||||
|
||||
SlackBuilder is a Haskell program and can be built and run using the
|
||||
Cabal build tool and package manager:
|
||||
|
||||
```sh
|
||||
cabal build
|
||||
```
|
||||
|
||||
After that you can run slackbuilder using Cabal and `cabal run slackbuilder`.
|
||||
Or you can install the program locally with `cabal install` and run it just
|
||||
as `slackbuilder` assuming `~/.cabal/bin` is on your PATH.
|
||||
|
||||
# Usage
|
||||
|
||||
## Configuration
|
||||
|
||||
There is a sample configuration file under `config/config.toml.example`.
|
||||
The sample contains comments describing each supported option.
|
||||
Just copy this file to `config/config.toml` and modify as needed.
|
||||
|
||||
Each package that should be updated automatically needs a special
|
||||
description which contains links to the upstream repositories and
|
||||
instructions how the sources should be prepared.
|
||||
|
||||
Unfortunately the only format currently supported for the package
|
||||
descriptions is Haskell source code. But I'm planning to make it
|
||||
possible to describe the packages without recompiling the slackbuilder
|
||||
itself.
|
||||
|
||||
For the time being `src/Main.hs` contains descriptions of my
|
||||
slackbuilds, that can be used as an example and a start point.
|
||||
|
||||
## Command line options
|
||||
|
||||
SlackBuilder is called with a command as its first argument:
|
||||
|
||||
```sh
|
||||
slackbuilder COMMAND
|
||||
```
|
||||
|
||||
Currently supported commands are listed below.
|
||||
|
||||
### check
|
||||
|
||||
`check` checks whether there are updates available. It prints the name of each
|
||||
known package together with its version. If the package version is not the
|
||||
latest known version, the version the package can be updated to is printed as
|
||||
well.
|
||||
|
||||
### up2date
|
||||
|
||||
Performs the package updates for packages the can be updated. `up2date` accepts
|
||||
an optional argument specifying the package that should be updated if only one
|
||||
package should be updated and not all.
|
191
Rakefile
191
Rakefile
@ -1,191 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'digest/md5'
|
||||
require 'net/http'
|
||||
require 'open3'
|
||||
require_relative 'config/config'
|
||||
require_relative 'lib/package'
|
||||
require_relative 'lib/download'
|
||||
require_relative 'lib/up2date'
|
||||
|
||||
task :dmd, [:version] do |_, arguments|
|
||||
raise 'Version is not specified.' unless arguments.key? :version
|
||||
|
||||
dub_version = '1.33.0'
|
||||
dscanner_version = '0.15.2'
|
||||
dcd_version = '0.15.2'
|
||||
|
||||
SlackBuilder::DmdTools.update_dmd arguments[:version]
|
||||
SlackBuilder::DmdTools.update_tools arguments[:version], dub_version, dscanner_version, dcd_version
|
||||
end
|
||||
|
||||
task :hhvm, [:version] do |_, arguments|
|
||||
raise 'Version is not specified.' unless arguments.key? :version
|
||||
|
||||
checksum = {}
|
||||
checksum[:hhvm] = SlackBuilder.clone 'https://github.com/facebook/hhvm.git',
|
||||
"development/hhvm/hhvm-#{arguments[:version]}.tar.xz", 'HHVM-'
|
||||
|
||||
package = Package.new 'development/hhvm',
|
||||
version: arguments[:version],
|
||||
homepage: 'https://hhvm.com/',
|
||||
requires: %w[tbb glog libdwarf libmemcached dobule-conversion]
|
||||
|
||||
write_info package,
|
||||
downloads: [
|
||||
Download.new(SlackBuilder.hosted_sources("/hhvm/hhvm-#{package.version}.tar.xz"), checksum[:hhvm], is64: true)
|
||||
]
|
||||
|
||||
update_slackbuild_version 'development/hhvm', package.version
|
||||
end
|
||||
|
||||
task :webex do
|
||||
tarball = 'slackbuilds/network/webex/Webex.deb'
|
||||
uri = 'https://binaries.webex.com/WebexDesktop-Ubuntu-Official-Package/Webex.deb'
|
||||
checksum = SlackBuilder.download URI(uri), tarball
|
||||
|
||||
last_stdout, = Open3.pipeline_r ['ar', 'p', tarball, 'control.tar.gz'], ['tar', 'zxO', './control']
|
||||
version = last_stdout.read.lines
|
||||
.find { |line| line.start_with? 'Version: ' }
|
||||
.split.last
|
||||
|
||||
package = Package.new 'network/webex',
|
||||
version: version,
|
||||
homepage: 'https://www.webex.com'
|
||||
|
||||
write_info package,
|
||||
downloads: [Download.new(uri, checksum, is64: true)]
|
||||
|
||||
update_slackbuild_version 'network/webex', package.version
|
||||
commit 'network/webex', package.version
|
||||
end
|
||||
|
||||
task 'rdiff-backup', [:version] do |_, arguments|
|
||||
raise 'Version is not specified.' unless arguments.key? :version
|
||||
|
||||
package = Package.new 'system/rdiff-backup',
|
||||
version: arguments[:version],
|
||||
homepage: 'https://rdiff-backup.net/',
|
||||
requires: ['librsync']
|
||||
|
||||
uri = "https://github.com/rdiff-backup/rdiff-backup/releases/download/v#{arguments[:version]}/rdiff-backup-#{arguments[:version]}.tar.gz"
|
||||
tarball = "system/rdiff-backup/rdiff-backup-#{arguments[:version]}.tar.gz"
|
||||
checksum = SlackBuilder.download_and_deploy URI(uri), tarball
|
||||
download = "https://download.dlackware.com/hosted-sources/rdiff-backup/rdiff-backup-#{arguments[:version]}.tar.gz"
|
||||
|
||||
write_info package, downloads: [Download.new(download, checksum)]
|
||||
update_slackbuild_version 'system/rdiff-backup', arguments[:version]
|
||||
|
||||
commit 'system/rdiff-backup', arguments[:version]
|
||||
end
|
||||
|
||||
module SlackBuilder
|
||||
class Updater
|
||||
include Rake::FileUtilsExt
|
||||
|
||||
def update(version)
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
class UniversalCtags < Updater
|
||||
def update(version)
|
||||
package = create_package version
|
||||
|
||||
uri = "https://github.com/universal-ctags/ctags/archive/#{version}/ctags-#{version}.tar.gz"
|
||||
tarball = "slackbuilds/development/universal-ctags/ctags-#{version}.tar.gz"
|
||||
checksum = SlackBuilder.download URI(uri), tarball
|
||||
download = "https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{version}.tar.gz"
|
||||
|
||||
write_info package, downloads: [Download.new(download, checksum)]
|
||||
update_slackbuild_version 'development/universal-ctags', version
|
||||
sh 'scp', tarball, "#{CONFIG[:remote_path]}/universal-ctags"
|
||||
|
||||
commit 'development/universal-ctags', version
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_package(version)
|
||||
Package.new 'development/universal-ctags',
|
||||
version: version,
|
||||
homepage: 'https://ctags.io/',
|
||||
requires: ['%README%']
|
||||
end
|
||||
end
|
||||
|
||||
class Composer < Updater
|
||||
def update(version)
|
||||
package = Package.new 'development/composer',
|
||||
version: version,
|
||||
homepage: 'https://getcomposer.org/'
|
||||
|
||||
uri = "https://getcomposer.org/download/#{version}/composer.phar"
|
||||
checksum = SlackBuilder.download URI(uri), 'slackbuilds/development/composer/composer.phar'
|
||||
write_info package, downloads: [Download.new(uri, checksum)]
|
||||
update_slackbuild_version 'development/composer', version
|
||||
|
||||
commit 'development/composer', version
|
||||
end
|
||||
end
|
||||
|
||||
class JitsiMeetDesktop < Updater
|
||||
def update(version)
|
||||
package = Package.new 'network/jitsi-meet-desktop',
|
||||
version: version,
|
||||
homepage: 'https://jitsi.org/'
|
||||
uri = "https://github.com/jitsi/jitsi-meet-electron/releases/download/v#{version}/jitsi-meet-x86_64.AppImage"
|
||||
checksum = SlackBuilder.download URI(uri), 'slackbuilds/network/jitsi-meet-desktop/jitsi-meet-x86_64.AppImage'
|
||||
|
||||
write_info package, downloads: [Download.new(uri, checksum, is64: true)]
|
||||
update_slackbuild_version 'network/jitsi-meet-desktop', version
|
||||
commit 'network/jitsi-meet-desktop', version
|
||||
end
|
||||
end
|
||||
|
||||
class PHP < Updater
|
||||
def update(version)
|
||||
package = Package.new 'development/php82',
|
||||
version: version,
|
||||
homepage: 'https://www.php.net/',
|
||||
requires: ['postgresql']
|
||||
|
||||
uri = "https://www.php.net/distributions/php-#{version}.tar.xz"
|
||||
tarball = "slackbuilds/development/php82/php-#{version}.tar.xz"
|
||||
checksum = SlackBuilder.download URI(uri), tarball
|
||||
|
||||
write_info package, downloads: [Download.new(uri, checksum)]
|
||||
update_slackbuild_version 'development/php82', version
|
||||
|
||||
commit 'development/php82', version
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
AUTO_UPDATABLE = {
|
||||
'universal-ctags' => [SlackBuilder::GitHub.new('universal-ctags', 'ctags'), SlackBuilder::UniversalCtags.new],
|
||||
'composer' => [SlackBuilder::Packagist.new('composer', 'composer'), SlackBuilder::Composer.new],
|
||||
'php82' => [SlackBuilder::GitHub.new('php', 'php-src', 'php'), SlackBuilder::PHP.new],
|
||||
'rdiff-backup' => [SlackBuilder::GitHub.new('rdiff-backup', 'rdiff-backup', 'rdiff-backup')],
|
||||
'librsync' => [SlackBuilder::GitHub.new('librsync', 'librsync')],
|
||||
'jitsi-meet-desktop' => [
|
||||
SlackBuilder::GitHub.new('jitsi', 'jitsi-meet-electron'),
|
||||
SlackBuilder::JitsiMeetDesktop.new
|
||||
],
|
||||
'dmd' => [SlackBuilder::LatestText.new('https://downloads.dlang.org/releases/LATEST')]
|
||||
}.freeze
|
||||
|
||||
task :up2date do
|
||||
AUTO_UPDATABLE.each do |key, value|
|
||||
repository, updater = value
|
||||
latest_version = SlackBuilder.check_for_latest key, repository
|
||||
next if latest_version.nil? || updater.nil?
|
||||
|
||||
puts "Would like to update #{key} to #{latest_version} (y/N)? "
|
||||
updater.update latest_version if $stdin.gets.chomp.downcase.start_with? 'y'
|
||||
end
|
||||
end
|
140
app/Main.hs
140
app/Main.hs
@ -1,140 +0,0 @@
|
||||
module Main
|
||||
( main
|
||||
) where
|
||||
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Options.Applicative (execParser)
|
||||
import SlackBuilder.CommandLine
|
||||
import SlackBuilder.Config
|
||||
import SlackBuilder.Trans
|
||||
import SlackBuilder.Updater
|
||||
import qualified Toml
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as Text.IO
|
||||
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
||||
import SlackBuilder.Download
|
||||
import qualified SlackBuilder.Package as Package
|
||||
import Text.URI (mkURI, URI)
|
||||
import Text.URI.QQ (uri)
|
||||
import Data.Foldable (for_)
|
||||
import qualified Text.URI as URI
|
||||
import GHC.Records (HasField(..))
|
||||
import System.FilePath ((</>), (<.>))
|
||||
|
||||
data Package = Package
|
||||
{ latest :: Package.Updater
|
||||
, category :: Text
|
||||
, name :: Text
|
||||
, homepage :: Maybe URI
|
||||
, requires :: [Text]
|
||||
}
|
||||
|
||||
autoUpdatable :: [Package]
|
||||
autoUpdatable =
|
||||
[ Package
|
||||
{ latest =
|
||||
let ghArguments = GhArguments{ owner = "universal-ctags", name = "ctags", transform = Nothing}
|
||||
latest' = latestGitHub ghArguments pure
|
||||
templateTail =
|
||||
[ Package.StaticPlaceholder "/ctags-"
|
||||
, Package.VersionPlaceholder
|
||||
, Package.StaticPlaceholder ".tar.gz"
|
||||
]
|
||||
template = Package.DownloadTemplate
|
||||
$ Package.StaticPlaceholder "https://github.com/universal-ctags/ctags/archive/" :| templateTail
|
||||
in Package.Updater latest' template
|
||||
, category = "development"
|
||||
, name = "universal-ctags"
|
||||
, homepage = Just [uri|https://ctags.io/|]
|
||||
, requires = pure "%README%"
|
||||
}
|
||||
]
|
||||
|
||||
up2Date :: SlackBuilderT ()
|
||||
up2Date = for_ autoUpdatable go
|
||||
where
|
||||
go package@Package{ latest = Package.Updater getLatest _ } =
|
||||
getLatest >>= mapM_ (updatePackage package)
|
||||
|
||||
updatePackage :: Package -> Text -> SlackBuilderT ()
|
||||
updatePackage Package{..} version = do
|
||||
maintainer' <- SlackBuilderT $ asks maintainer
|
||||
let packagePath = category <> "/" <> name
|
||||
package' = Package.PackageInfo
|
||||
{ version = version
|
||||
, requires = requires
|
||||
, path = Text.unpack packagePath
|
||||
, homepage = maybe "" URI.render homepage
|
||||
, maintainer = Package.Maintainer
|
||||
{ name = getField @"name" maintainer'
|
||||
, email = getField @"email" maintainer'
|
||||
}
|
||||
}
|
||||
Package.Updater _ downloadTemplate = latest
|
||||
|
||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||
let tarball = "slackbuilds/development/universal-ctags/ctags-#{version}.tar.gz"
|
||||
checksum <- fromMaybe undefined <$> download uri' tarball
|
||||
download' <- liftIO
|
||||
$ mkURI
|
||||
$ Text.replace "#{version}" version
|
||||
"https://download.dlackware.com/hosted-sources/universal-ctags/ctags-#{version}.tar.gz"
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
let infoFilePath = repository' </> Text.unpack packagePath
|
||||
</> (Text.unpack name <.> "info")
|
||||
|
||||
liftIO $ Text.IO.writeFile infoFilePath
|
||||
$ Package.infoTemplate package' [Package.Download download' checksum False]
|
||||
updateSlackBuildVersion packagePath version
|
||||
|
||||
remotePath' <- SlackBuilderT $ asks remotePath
|
||||
uploadCommand (Text.pack tarball) $ remotePath' <> "/universal-ctags"
|
||||
|
||||
commit packagePath version
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
programCommand <- execParser slackBuilderParser
|
||||
settings <- Toml.decodeFile settingsCodec "config/config.toml"
|
||||
latestVersion <- flip runReaderT settings
|
||||
$ runSlackBuilderT
|
||||
$ executeCommand programCommand
|
||||
|
||||
Text.IO.putStrLn $ fromMaybe "" latestVersion
|
||||
where
|
||||
executeCommand = \case
|
||||
PackagistCommand packagistArguments ->
|
||||
latestPackagist packagistArguments
|
||||
TextCommand textArguments -> latestText textArguments
|
||||
GhCommand ghArguments@GhArguments{ transform }
|
||||
-> latestGitHub ghArguments $ chooseTransformFunction transform
|
||||
SlackBuildCommand packagePath version ->
|
||||
updateSlackBuildVersion packagePath version >> pure Nothing
|
||||
CommitCommand packagePath version ->
|
||||
commit packagePath version >> pure Nothing
|
||||
ExistsCommand urlPath -> pure . Text.pack . show
|
||||
<$> remoteFileExists urlPath
|
||||
ArchiveCommand repo nameVersion tarball tagPrefix ->
|
||||
cloneAndArchive repo nameVersion tarball tagPrefix >> pure Nothing
|
||||
DownloadCommand url target
|
||||
| Just uri' <- mkURI url -> fmap (Text.pack . show)
|
||||
<$> download uri' target
|
||||
| otherwise -> pure Nothing
|
||||
CloneCommand repo tarball tagPrefix -> fmap (Text.pack . show)
|
||||
<$> clone repo tarball tagPrefix
|
||||
DownloadAndDeployCommand uri' tarball -> fmap (Text.pack . show)
|
||||
<$> downloadAndDeploy uri' tarball
|
||||
Up2DateCommand -> up2Date >> pure Nothing
|
||||
chooseTransformFunction (Just "php") = phpTransform
|
||||
chooseTransformFunction (Just "rdiff-backup") = Text.stripPrefix "v"
|
||||
chooseTransformFunction _ = stripPrefix "v"
|
||||
stripPrefix prefix string = Just
|
||||
$ fromMaybe string
|
||||
$ Text.stripPrefix prefix string
|
||||
phpTransform version
|
||||
| (majorPrefix, _patchVersion) <- Text.breakOnEnd "." version
|
||||
, majorPrefix == "php-8.2." = Just $ Text.drop (Text.length "php-") version
|
||||
| otherwise = Nothing
|
@ -1,103 +0,0 @@
|
||||
module SlackBuilder.CommandLine
|
||||
( GhArguments(..)
|
||||
, SlackBuilderCommand(..)
|
||||
, PackagistArguments(..)
|
||||
, TextArguments(..)
|
||||
, slackBuilderParser
|
||||
) where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Options.Applicative
|
||||
( Parser
|
||||
, ParserInfo(..)
|
||||
, metavar
|
||||
, argument
|
||||
, str
|
||||
, info
|
||||
, fullDesc
|
||||
, subparser
|
||||
, command, optional
|
||||
)
|
||||
|
||||
data SlackBuilderCommand
|
||||
= PackagistCommand PackagistArguments
|
||||
| TextCommand TextArguments
|
||||
| GhCommand GhArguments
|
||||
| SlackBuildCommand Text Text
|
||||
| CommitCommand Text Text
|
||||
| ExistsCommand Text
|
||||
| ArchiveCommand Text Text String Text
|
||||
| DownloadCommand Text String
|
||||
| CloneCommand Text Text Text
|
||||
| DownloadAndDeployCommand Text Text
|
||||
| Up2DateCommand
|
||||
deriving (Eq, Show)
|
||||
|
||||
data PackagistArguments = PackagistArguments
|
||||
{ vendor :: Text
|
||||
, name :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data GhArguments = GhArguments
|
||||
{ owner :: Text
|
||||
, name :: Text
|
||||
, transform :: Maybe Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
newtype TextArguments = TextArguments Text
|
||||
deriving (Eq, Show)
|
||||
|
||||
packagistArguments :: Parser PackagistArguments
|
||||
packagistArguments = PackagistArguments
|
||||
<$> argument str (metavar "VENDOR")
|
||||
<*> argument str (metavar"NAME")
|
||||
|
||||
textArguments :: Parser TextArguments
|
||||
textArguments = TextArguments <$> argument str (metavar "URL")
|
||||
|
||||
ghArguments :: Parser GhArguments
|
||||
ghArguments = GhArguments
|
||||
<$> argument str (metavar "OWNER")
|
||||
<*> argument str (metavar "NAME")
|
||||
<*> optional (argument str (metavar "TRANSFORM"))
|
||||
|
||||
slackBuilderParser :: ParserInfo SlackBuilderCommand
|
||||
slackBuilderParser = info slackBuilderCommand fullDesc
|
||||
|
||||
slackBuilderCommand :: Parser SlackBuilderCommand
|
||||
slackBuilderCommand = subparser
|
||||
$ command "packagist" (info (PackagistCommand <$> packagistArguments) mempty)
|
||||
<> command "text" (info (TextCommand <$> textArguments) mempty)
|
||||
<> command "github" (info (GhCommand <$> ghArguments) mempty)
|
||||
<> command "slackbuild" (info slackBuildCommand mempty)
|
||||
<> command "commit" (info commitCommand mempty)
|
||||
<> command "exists" (info existsCommand mempty)
|
||||
<> command "archive" (info archiveCommand mempty)
|
||||
<> command "download" (info downloadCommand mempty)
|
||||
<> command "clone" (info cloneCommand mempty)
|
||||
<> command "deploy" (info deployCommand mempty)
|
||||
<> command "up2date" (info up2DateCommand mempty)
|
||||
where
|
||||
slackBuildCommand = SlackBuildCommand
|
||||
<$> argument str (metavar "PATH")
|
||||
<*> argument str (metavar "VERSION")
|
||||
commitCommand = CommitCommand
|
||||
<$> argument str (metavar "PATH")
|
||||
<*> argument str (metavar "VERSION")
|
||||
existsCommand = ExistsCommand <$> argument str (metavar "PATH")
|
||||
archiveCommand = ArchiveCommand
|
||||
<$> argument str (metavar "REPO")
|
||||
<*> argument str (metavar "NAME_VERSION")
|
||||
<*> argument str (metavar "TARBALL")
|
||||
<*> argument str (metavar "TAG_PREFIX")
|
||||
downloadCommand = DownloadCommand
|
||||
<$> argument str (metavar "URI")
|
||||
<*> argument str (metavar "TARGET")
|
||||
cloneCommand = CloneCommand
|
||||
<$> argument str (metavar "REPO")
|
||||
<*> argument str (metavar "TARBALL")
|
||||
<*> argument str (metavar "TAG_PREFIX")
|
||||
deployCommand = DownloadAndDeployCommand
|
||||
<$> argument str (metavar "URI")
|
||||
<*> argument str (metavar "TARBALL")
|
||||
up2DateCommand = pure Up2DateCommand
|
@ -1,208 +0,0 @@
|
||||
module SlackBuilder.Download
|
||||
( clone
|
||||
, cloneAndArchive
|
||||
, commit
|
||||
, download
|
||||
, downloadAndDeploy
|
||||
, hostedSources
|
||||
, remoteFileExists
|
||||
, updateSlackBuildVersion
|
||||
, uploadCommand
|
||||
) where
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as Text.IO
|
||||
import SlackBuilder.Config
|
||||
import SlackBuilder.Trans
|
||||
import Control.Monad.Trans.Reader (asks)
|
||||
import Control.Monad.IO.Class (MonadIO(liftIO))
|
||||
import System.IO (IOMode(..), withFile)
|
||||
import System.FilePath ((</>), (<.>), takeBaseName, splitPath, joinPath)
|
||||
import System.Process
|
||||
( CreateProcess(..)
|
||||
, StdStream(..)
|
||||
, proc
|
||||
, readCreateProcessWithExitCode
|
||||
, callProcess
|
||||
)
|
||||
import System.Exit (ExitCode(..))
|
||||
import Control.Monad (unless)
|
||||
import Text.URI (URI(..), mkURI)
|
||||
import Network.HTTP.Req
|
||||
( useHttpsURI
|
||||
, HEAD(..)
|
||||
, NoReqBody(..)
|
||||
, req
|
||||
, runReq
|
||||
, defaultHttpConfig
|
||||
, ignoreResponse
|
||||
, responseStatusCode
|
||||
, HttpConfig(..)
|
||||
, GET(..)
|
||||
, reqBr
|
||||
)
|
||||
import Data.Functor ((<&>))
|
||||
import Network.HTTP.Client (BodyReader, Response(..), brRead)
|
||||
import Conduit
|
||||
( ConduitT
|
||||
, yield
|
||||
, runConduitRes
|
||||
, sinkFile
|
||||
, (.|)
|
||||
, ZipSink(..)
|
||||
, await
|
||||
, sourceFile
|
||||
)
|
||||
import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate)
|
||||
import Data.Void (Void)
|
||||
|
||||
updateSlackBuildVersion :: Text -> Text -> SlackBuilderT ()
|
||||
updateSlackBuildVersion packagePath version = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
let name = Text.unpack $ snd $ Text.breakOnEnd "/" packagePath
|
||||
slackbuildFilename = repository'
|
||||
</> Text.unpack packagePath
|
||||
</> (name <.> "SlackBuild")
|
||||
slackbuildContents <- liftIO $ Text.IO.readFile slackbuildFilename
|
||||
let (contentsHead, contentsTail) = Text.dropWhile (/= '\n')
|
||||
<$> Text.breakOn "VERSION=${VERSION:-" slackbuildContents
|
||||
|
||||
liftIO $ Text.IO.writeFile slackbuildFilename
|
||||
$ contentsHead <> "VERSION=${VERSION:-" <> version <> "}" <> contentsTail
|
||||
|
||||
commit :: Text -> Text -> SlackBuilderT ()
|
||||
commit packagePath version = do
|
||||
branch' <- SlackBuilderT $ Text.unpack <$> asks branch
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
let message = Text.unpack
|
||||
$ packagePath <> ": Updated for version " <> version
|
||||
|
||||
(checkoutExitCode, _, _) <- liftIO
|
||||
$ withFile "/dev/null" WriteMode
|
||||
$ testCheckout repository' branch'
|
||||
|
||||
unless (checkoutExitCode == ExitSuccess)
|
||||
$ liftIO
|
||||
$ callProcess "git" ["-C", repository', "checkout", "-b", branch', "master"]
|
||||
liftIO
|
||||
$ callProcess "git" ["-C", repository', "add", Text.unpack packagePath]
|
||||
>> callProcess "git" ["-C", repository', "commit", "-S", "-m", message]
|
||||
where
|
||||
testCheckout repository' branch' nullHandle =
|
||||
let createCheckoutProcess = (proc "git" ["-C", repository', "checkout", branch'])
|
||||
{ std_in = NoStream
|
||||
, std_err = UseHandle nullHandle
|
||||
}
|
||||
in readCreateProcessWithExitCode createCheckoutProcess ""
|
||||
|
||||
hostedSources :: Text -> SlackBuilderT URI
|
||||
hostedSources absoluteURL = SlackBuilderT (asks downloadURL)
|
||||
>>= liftIO . mkURI . (<> absoluteURL)
|
||||
|
||||
remoteFileExists :: Text -> SlackBuilderT Bool
|
||||
remoteFileExists url = hostedSources url
|
||||
>>= traverse (runReq httpConfig . go . fst) . useHttpsURI
|
||||
<&> maybe False ((== 200) . responseStatusCode)
|
||||
where
|
||||
httpConfig = defaultHttpConfig
|
||||
{ httpConfigCheckResponse = const $ const $ const Nothing
|
||||
}
|
||||
go uri = req HEAD uri NoReqBody ignoreResponse mempty
|
||||
|
||||
uploadCommand :: Text -> Text -> SlackBuilderT ()
|
||||
uploadCommand localPath remotePath' = do
|
||||
remoteRoot <- SlackBuilderT $ asks remotePath
|
||||
liftIO $ callProcess "scp" $ Text.unpack <$>
|
||||
[ "slackbuilds/" <> localPath
|
||||
, remoteRoot <> remotePath'
|
||||
]
|
||||
|
||||
cloneAndArchive :: Text -> Text -> FilePath -> Text -> SlackBuilderT ()
|
||||
cloneAndArchive repo nameVersion tarball tagPrefix = do
|
||||
let (_, version) = Text.breakOnEnd "-" nameVersion
|
||||
nameVersion' = Text.unpack nameVersion
|
||||
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
liftIO $ callProcess "rm" ["-rf", nameVersion']
|
||||
|
||||
liftIO $ callProcess "git" ["clone", Text.unpack repo, nameVersion']
|
||||
liftIO $ callProcess "git"
|
||||
[ "-C"
|
||||
, nameVersion'
|
||||
, "checkout"
|
||||
, Text.unpack $ tagPrefix <> version
|
||||
]
|
||||
liftIO $ callProcess "git"
|
||||
[ "-C"
|
||||
, nameVersion'
|
||||
, "submodule"
|
||||
, "update"
|
||||
, "--init"
|
||||
, "--recursive"
|
||||
]
|
||||
|
||||
liftIO $ callProcess "tar"
|
||||
[ "Jcvf"
|
||||
, repository' </> tarball
|
||||
, nameVersion'
|
||||
]
|
||||
liftIO $ callProcess "rm" ["-rf", nameVersion']
|
||||
|
||||
responseBodySource :: MonadIO m => Response BodyReader -> ConduitT i ByteString m ()
|
||||
responseBodySource = bodyReaderSource . responseBody
|
||||
where
|
||||
bodyReaderSource br = liftIO (brRead br) >>= go br
|
||||
go br bs = unless (ByteString.null bs) $ yield bs >> bodyReaderSource br
|
||||
|
||||
sinkHash :: Monad m => ConduitT ByteString Void m (Digest MD5)
|
||||
sinkHash = sink hashInit
|
||||
where
|
||||
sink ctx = await
|
||||
>>= maybe (pure $ hashFinalize ctx) (sink . hashUpdate ctx)
|
||||
|
||||
download :: URI -> FilePath -> SlackBuilderT (Maybe (Digest MD5))
|
||||
download uri target = traverse (runReq defaultHttpConfig . go . fst)
|
||||
$ useHttpsURI uri
|
||||
where
|
||||
go uri' = reqBr GET uri' NoReqBody mempty readResponse
|
||||
readResponse :: Response BodyReader -> IO (Digest MD5)
|
||||
readResponse response = runConduitRes
|
||||
$ responseBodySource response
|
||||
.| getZipSink (ZipSink (sinkFile target) *> ZipSink sinkHash)
|
||||
|
||||
clone :: Text -> Text -> Text -> SlackBuilderT (Maybe (Digest MD5))
|
||||
clone repo tarball tagPrefix = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
let tarballPath = Text.unpack tarball
|
||||
nameVersion = Text.pack $ takeBaseName tarballPath
|
||||
remotePath = Text.pack $ joinPath $ ("/" :) $ drop 1 $ splitPath tarballPath
|
||||
localPath = repository' </> tarballPath
|
||||
remoteFileExists' <- remoteFileExists remotePath
|
||||
|
||||
if remoteFileExists'
|
||||
then
|
||||
hostedSources remotePath >>= flip download localPath
|
||||
else
|
||||
let go = sourceFile localPath .| sinkHash
|
||||
in cloneAndArchive repo nameVersion tarballPath tagPrefix
|
||||
>> uploadCommand tarball remotePath
|
||||
>> liftIO (runConduitRes go) <&> Just
|
||||
|
||||
downloadAndDeploy :: Text -> Text -> SlackBuilderT (Maybe (Digest MD5))
|
||||
downloadAndDeploy uri tarball = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
let tarballPath = Text.unpack tarball
|
||||
remotePath = Text.pack $ joinPath $ ("/" :) $ drop 1 $ splitPath tarballPath
|
||||
localPath = repository' </> tarballPath
|
||||
remoteFileExists' <- remoteFileExists remotePath
|
||||
|
||||
if remoteFileExists'
|
||||
then
|
||||
hostedSources remotePath >>= flip download localPath
|
||||
else do
|
||||
checksum <- liftIO (mkURI uri) >>= flip download localPath
|
||||
uploadCommand tarball remotePath
|
||||
pure checksum
|
@ -1,158 +0,0 @@
|
||||
module SlackBuilder.Updater
|
||||
( latestGitHub
|
||||
, latestPackagist
|
||||
, latestText
|
||||
) where
|
||||
|
||||
import SlackBuilder.Config
|
||||
import qualified Data.Aeson as Aeson
|
||||
import Data.Aeson ((.:))
|
||||
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 as Text
|
||||
import qualified Data.Text.Encoding as Text.Encoding
|
||||
import Data.Vector (Vector, (!?))
|
||||
import qualified Data.Vector as Vector
|
||||
import Network.HTTP.Req
|
||||
( header
|
||||
, runReq
|
||||
, defaultHttpConfig
|
||||
, req
|
||||
, GET(..)
|
||||
, https
|
||||
, jsonResponse
|
||||
, NoReqBody(..)
|
||||
, (/:)
|
||||
, responseBody
|
||||
, useHttpsURI
|
||||
, bsResponse
|
||||
, POST(..)
|
||||
, ReqBodyJson(..)
|
||||
)
|
||||
import Text.URI (mkURI)
|
||||
import SlackBuilder.CommandLine
|
||||
import SlackBuilder.Trans
|
||||
import qualified Data.Aeson.KeyMap as KeyMap
|
||||
import GHC.Records (HasField(..))
|
||||
import Control.Monad.Trans.Reader (asks)
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
|
||||
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)
|
||||
|
||||
newtype GhRefNode = GhRefNode
|
||||
{ name :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhRefNode)
|
||||
|
||||
newtype GhRef = GhRef
|
||||
{ nodes :: Vector GhRefNode
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhRef)
|
||||
|
||||
newtype GhRepository = GhRepository
|
||||
{ refs :: GhRef
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhRepository)
|
||||
|
||||
newtype GhData = GhData
|
||||
{ repository :: GhRepository
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance Aeson.FromJSON GhData where
|
||||
parseJSON (Aeson.Object keyMap)
|
||||
| Just data' <- KeyMap.lookup "data" keyMap =
|
||||
GhData <$> Aeson.withObject "GhData" (.: "repository") data'
|
||||
parseJSON _ = fail "data key not found in the response"
|
||||
|
||||
data GhVariables = GhVariables
|
||||
{ name :: Text
|
||||
, owner :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhVariables)
|
||||
|
||||
data GhQuery = GhQuery
|
||||
{ query :: Text
|
||||
, variables :: GhVariables
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhQuery)
|
||||
|
||||
latestPackagist :: PackagistArguments -> SlackBuilderT (Maybe Text)
|
||||
latestPackagist PackagistArguments{..} = do
|
||||
packagistResponse <- runReq defaultHttpConfig $
|
||||
let uri = https "repo.packagist.org" /: "p2"
|
||||
/: vendor
|
||||
/: name <> ".json"
|
||||
in req GET uri NoReqBody jsonResponse mempty
|
||||
let packagistPackages = packages $ responseBody packagistResponse
|
||||
fullName = Text.intercalate "/" [vendor, name]
|
||||
|
||||
pure $ HashMap.lookup fullName packagistPackages
|
||||
>>= fmap (version . fst) . Vector.uncons
|
||||
|
||||
latestText :: TextArguments -> SlackBuilderT (Maybe Text)
|
||||
latestText (TextArguments textArguments) = do
|
||||
uri <- liftIO $ useHttpsURI <$> mkURI textArguments
|
||||
packagistResponse <- traverse (runReq defaultHttpConfig) $ go . fst <$> uri
|
||||
|
||||
pure $ Text.strip . Text.Encoding.decodeASCII . responseBody
|
||||
<$> packagistResponse
|
||||
where
|
||||
go uri = req GET uri NoReqBody bsResponse mempty
|
||||
|
||||
latestGitHub
|
||||
:: GhArguments
|
||||
-> (Text -> Maybe Text)
|
||||
-> SlackBuilderT (Maybe Text)
|
||||
latestGitHub GhArguments{..} versionTransform = do
|
||||
ghToken' <- SlackBuilderT $ asks ghToken
|
||||
ghResponse <- runReq defaultHttpConfig $
|
||||
let uri = https "api.github.com" /: "graphql"
|
||||
query = GhQuery
|
||||
{ query = githubQuery
|
||||
, variables = GhVariables
|
||||
{ owner = owner
|
||||
, name = name
|
||||
}
|
||||
}
|
||||
authorizationHeader = header "authorization"
|
||||
$ Text.Encoding.encodeUtf8
|
||||
$ "Bearer " <> ghToken'
|
||||
in req POST uri (ReqBodyJson query) jsonResponse
|
||||
$ authorizationHeader <> header "User-Agent" "SlackBuilder"
|
||||
let ghNodes = nodes
|
||||
$ refs
|
||||
$ (getField @"repository" :: GhData -> GhRepository)
|
||||
$ responseBody ghResponse
|
||||
refs' = Vector.reverse
|
||||
$ Vector.catMaybes
|
||||
$ versionTransform . getField @"name" <$> ghNodes
|
||||
pure $ refs' !? 0
|
||||
where
|
||||
githubQuery =
|
||||
"query ($name: String!, $owner: String!) {\n\
|
||||
\ repository(name: $name, owner: $owner) {\n\
|
||||
\ refs(last: 10, refPrefix: \"refs/tags/\", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {\n\
|
||||
\ nodes {\n\
|
||||
\ id,\n\
|
||||
\ name\n\
|
||||
\ }\n\
|
||||
\ }\n\
|
||||
\ }\n\
|
||||
\}"
|
29
bin/rubocop
29
bin/rubocop
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# This file was generated by Bundler.
|
||||
#
|
||||
# The application 'rubocop' is installed as part of a gem, and
|
||||
# this file is here to facilitate running it.
|
||||
#
|
||||
|
||||
require "pathname"
|
||||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
||||
Pathname.new(__FILE__).realpath)
|
||||
|
||||
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
||||
|
||||
if File.file?(bundle_binstub)
|
||||
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
||||
load(bundle_binstub)
|
||||
else
|
||||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
||||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
||||
end
|
||||
end
|
||||
|
||||
require "rubygems"
|
||||
require "bundler/setup"
|
||||
|
||||
load Gem.bin_path("rubocop", "rubocop")
|
@ -1,7 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
CONFIG = {
|
||||
remote_path: 'example.com:/srv/httpd/some/path',
|
||||
download_url: 'https://example.com/some/path',
|
||||
repository: '../slackbuilds'
|
||||
}.freeze
|
@ -1,9 +1,35 @@
|
||||
gh_token = ""
|
||||
repository = "./slackbuilds"
|
||||
branch = "user/nick/updates"
|
||||
download_url = "https://example.com/some/path"
|
||||
remote_path = "example.com:/srv/httpd/some/path"
|
||||
## Global options
|
||||
|
||||
# Accessing GitHub APIs is only possible using a personal access token. The
|
||||
# token doesn't need any scopes set since it is used to query public
|
||||
# repositories.
|
||||
gh_token = ""
|
||||
|
||||
# Relative path to a cloned SBo repository.
|
||||
repository = "./slackbuilds"
|
||||
|
||||
# After one package is updated a commit is created on this branch. The branch is
|
||||
# not pushed or reset automatically.
|
||||
branch = "user/nick/updates"
|
||||
|
||||
# If some packages use custom sources and these sources a generated during the
|
||||
# update, this option specifies the base URL where the sources can be downloaded
|
||||
# afterwads. The full URL written into the .info file contains download_url,
|
||||
# followed by the package name and source file name. This option should probably
|
||||
# be configured consistently with the remote_path.
|
||||
download_url = "https://example.com/some/path"
|
||||
|
||||
# If a package updater generates a source tarball, the tarball is uploaded with
|
||||
# a command given in this parameter. The parameter is a array where the first
|
||||
# element is the command with the following elements being the command
|
||||
# arguments. The command supports 2 placeholders:
|
||||
# %s - Path to the source archive.
|
||||
# %c - Package category.
|
||||
upload_command = ["scp", "%s", "example.com:/srv/httpd/some/path/%c"]
|
||||
|
||||
## Maintainer specific options
|
||||
[maintainer]
|
||||
name = "Maintainer Name"
|
||||
email = "maintainer@example.com"
|
||||
|
||||
# Whether the git commits should be signed with a GPG signature using the
|
||||
# default key.
|
||||
signature = false
|
||||
|
@ -1,25 +1,57 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | Configuration file.
|
||||
module SlackBuilder.Config
|
||||
( Settings(..)
|
||||
( CloneSettings(..)
|
||||
, DownloaderSettings(..)
|
||||
, Settings(..)
|
||||
, MaintainerSettings(..)
|
||||
, PackageSettings(..)
|
||||
, settingsCodec
|
||||
) where
|
||||
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Data.Text (Text)
|
||||
import Toml ((.=))
|
||||
import qualified Toml
|
||||
import GHC.Records (HasField(..))
|
||||
|
||||
data Settings = Settings
|
||||
{ ghToken :: !Text
|
||||
, repository :: !FilePath
|
||||
, branch :: Text
|
||||
, downloadURL :: Text
|
||||
, remotePath :: Text
|
||||
, uploadCommand :: NonEmpty Text
|
||||
, maintainer :: MaintainerSettings
|
||||
, packages :: [PackageSettings]
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data MaintainerSettings = MaintainerSettings
|
||||
{ name :: !Text
|
||||
, email :: !Text
|
||||
newtype MaintainerSettings = MaintainerSettings
|
||||
{ signature :: Bool
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data DownloaderSettings = DownloaderSettings
|
||||
{ name :: Text
|
||||
, is64 :: Bool
|
||||
, version :: Text
|
||||
, template :: Maybe Text
|
||||
, clone :: Maybe CloneSettings
|
||||
, github :: Maybe (Text, Text)
|
||||
, packagist :: Maybe (Text, Text)
|
||||
, text :: Maybe (Text, [String])
|
||||
, repackage :: Maybe [String]
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data PackageSettings = PackageSettings
|
||||
{ downloader :: DownloaderSettings
|
||||
, downloaders :: [DownloaderSettings]
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data CloneSettings = CloneSettings
|
||||
{ remote :: Text
|
||||
, tagTemplate :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
settingsCodec :: Toml.TomlCodec Settings
|
||||
@ -28,10 +60,36 @@ settingsCodec = Settings
|
||||
<*> Toml.string "repository" .= repository
|
||||
<*> Toml.text "branch" .= branch
|
||||
<*> Toml.text "download_url" .= downloadURL
|
||||
<*> Toml.text "remote_path" .= remotePath
|
||||
<*> Toml.arrayNonEmptyOf Toml._Text "upload_command" .= uploadCommand
|
||||
<*> Toml.table maintainerSettingsCodec "maintainer" .= maintainer
|
||||
<*> Toml.list packageSettingsCodec "package" .= packages
|
||||
|
||||
maintainerSettingsCodec :: Toml.TomlCodec MaintainerSettings
|
||||
maintainerSettingsCodec = MaintainerSettings
|
||||
<$> Toml.bool "signature" .= signature
|
||||
|
||||
downloaderSettingsCodec :: Toml.TomlCodec DownloaderSettings
|
||||
downloaderSettingsCodec = DownloaderSettings
|
||||
<$> Toml.text "name" .= name
|
||||
<*> Toml.text "email" .= email
|
||||
<*> Toml.bool "is64" .= is64
|
||||
<*> Toml.text "version" .= version
|
||||
<*> Toml.dioptional (Toml.text "template") .= template
|
||||
<*> Toml.dioptional (Toml.table cloneSettingsCodec "clone") .= clone
|
||||
<*> Toml.dioptional (Toml.table githubCodec "github") .= github
|
||||
<*> Toml.dioptional (Toml.table packagistCodec "packagist") .= packagist
|
||||
<*> Toml.dioptional (Toml.table textCodec "text") .= text
|
||||
<*> Toml.dioptional (Toml.arrayOf Toml._String "repackage") .= repackage
|
||||
where
|
||||
githubCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
|
||||
packagistCodec = Toml.pair (Toml.text "owner") (Toml.text "name")
|
||||
textCodec = Toml.pair (Toml.text "url") (Toml.arrayOf Toml._String "picker")
|
||||
|
||||
packageSettingsCodec :: Toml.TomlCodec PackageSettings
|
||||
packageSettingsCodec = PackageSettings
|
||||
<$> downloaderSettingsCodec .= getField @"downloader"
|
||||
<*> Toml.list downloaderSettingsCodec "downloader" .= downloaders
|
||||
|
||||
cloneSettingsCodec :: Toml.TomlCodec CloneSettings
|
||||
cloneSettingsCodec = CloneSettings
|
||||
<$> Toml.text "remote" .= remote
|
||||
<*> Toml.text "tag_template" .= tagTemplate
|
||||
|
360
lib/SlackBuilder/Download.hs
Normal file
360
lib/SlackBuilder/Download.hs
Normal file
@ -0,0 +1,360 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | Contains routines for downloading, cloning and uploading sources.
|
||||
module SlackBuilder.Download
|
||||
( cloneAndUpload
|
||||
, extractRemote
|
||||
, commit
|
||||
, createLzmaTarball
|
||||
, download
|
||||
, hostedSources
|
||||
, remoteFileExists
|
||||
, responseBodySource
|
||||
, reqGet
|
||||
, sinkFileAndHash
|
||||
, sinkHash
|
||||
, updateSlackBuildVersion
|
||||
, uploadSource
|
||||
) where
|
||||
|
||||
import qualified Codec.Compression.Lzma as Lzma
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import qualified Data.ByteString.Char8 as Char8
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import qualified Data.List.NonEmpty as NonEmpty
|
||||
import Data.NonNull (toNullable)
|
||||
import Data.Foldable (find)
|
||||
import Data.Map.Strict (Map)
|
||||
import qualified Data.Map.Strict as Map
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as Text.IO
|
||||
import SlackBuilder.Config
|
||||
import SlackBuilder.Trans
|
||||
import Control.Monad.Trans.Reader (asks)
|
||||
import Control.Monad.IO.Class (MonadIO(liftIO))
|
||||
import System.Directory (createDirectory, removePathForcibly)
|
||||
import System.IO (IOMode(..), withFile)
|
||||
import System.FilePath ((</>), (<.>), takeFileName, takeDirectory, stripExtension)
|
||||
import System.Process
|
||||
( CreateProcess(..)
|
||||
, StdStream(..)
|
||||
, proc
|
||||
, readCreateProcessWithExitCode
|
||||
, callProcess
|
||||
)
|
||||
import System.Exit (ExitCode(..))
|
||||
import Control.Monad (unless, void)
|
||||
import Text.URI (URI(..))
|
||||
import qualified Text.URI as URI
|
||||
import Network.HTTP.Req
|
||||
( useHttpsURI
|
||||
, useURI
|
||||
, HEAD(..)
|
||||
, NoReqBody(..)
|
||||
, req
|
||||
, runReq
|
||||
, defaultHttpConfig
|
||||
, ignoreResponse
|
||||
, responseStatusCode
|
||||
, MonadHttp
|
||||
, HttpConfig(..)
|
||||
, GET(..)
|
||||
, reqBr
|
||||
)
|
||||
import Data.Functor ((<&>))
|
||||
import Network.HTTP.Client (BodyReader, Response(..), brRead)
|
||||
import Conduit
|
||||
( ConduitT
|
||||
, MonadResource
|
||||
, yield
|
||||
, runConduitRes
|
||||
, sinkFile
|
||||
, (.|)
|
||||
, ZipSink(..)
|
||||
, await
|
||||
, sourceFile
|
||||
, leftover
|
||||
, awaitNonNull
|
||||
)
|
||||
import Data.Conduit.Tar (FileInfo(..), tarFilePath, untar)
|
||||
import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate)
|
||||
import Data.Void (Void)
|
||||
import qualified Data.Conduit.Zlib as Zlib
|
||||
import Control.Monad.Catch (MonadThrow(..))
|
||||
import Data.Maybe (fromMaybe)
|
||||
|
||||
updateSlackBuildVersion :: Text -> Text -> Map Text Text -> SlackBuilderT ()
|
||||
updateSlackBuildVersion packagePath version additionalDownloads = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
let name = Text.unpack $ snd $ Text.breakOnEnd "/" packagePath
|
||||
slackbuildFilename = repository'
|
||||
</> Text.unpack packagePath
|
||||
</> (name <.> "SlackBuild")
|
||||
slackbuildContents <- liftIO $ Text.IO.readFile slackbuildFilename
|
||||
let slackbuildLines = replaceLine . updateLineVariable "VERSION" version
|
||||
<$> Text.lines slackbuildContents
|
||||
|
||||
liftIO $ Text.IO.writeFile slackbuildFilename $ Text.unlines slackbuildLines
|
||||
where
|
||||
replaceLine line = Map.foldrWithKey updateLineDependencyVersion line additionalDownloads
|
||||
updateLineDependencyVersion dependencyName = updateLineVariable
|
||||
$ dependencyName <> "_VERSION"
|
||||
updateLineVariable variableName variableValue line
|
||||
| Text.isPrefixOf (variableName <> "=") line =
|
||||
variableName <> "=${" <> variableName <> ":-" <> variableValue <> "}"
|
||||
| otherwise = line
|
||||
|
||||
commit :: Text -> Text -> SlackBuilderT ()
|
||||
commit packagePath version = do
|
||||
branch' <- SlackBuilderT $ Text.unpack <$> asks branch
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
signature' <- SlackBuilderT $ asks $ signature . maintainer
|
||||
let message = Text.unpack
|
||||
$ packagePath <> ": Updated for version " <> version
|
||||
mainCommitArguments = ["-C", repository', "commit", "-m", message]
|
||||
commitArguments =
|
||||
if signature'
|
||||
then mainCommitArguments <> ["-S"]
|
||||
else mainCommitArguments
|
||||
|
||||
(checkoutExitCode, _, _) <- liftIO
|
||||
$ withFile "/dev/null" WriteMode
|
||||
$ testCheckout repository' branch'
|
||||
|
||||
unless (checkoutExitCode == ExitSuccess)
|
||||
$ liftIO
|
||||
$ callProcess "git" ["-C", repository', "checkout", "-b", branch', "master"]
|
||||
liftIO
|
||||
$ callProcess "git" ["-C", repository', "add", Text.unpack packagePath]
|
||||
>> callProcess "git" commitArguments
|
||||
where
|
||||
testCheckout repository' branch' nullHandle =
|
||||
let createCheckoutProcess = (proc "git" ["-C", repository', "checkout", branch'])
|
||||
{ std_in = NoStream
|
||||
, std_err = UseHandle nullHandle
|
||||
}
|
||||
in readCreateProcessWithExitCode createCheckoutProcess ""
|
||||
|
||||
hostedSources :: NonEmpty Text -> SlackBuilderT URI
|
||||
hostedSources urlPathPieces = do
|
||||
downloadURL' <- SlackBuilderT (asks downloadURL) >>= URI.mkURI
|
||||
urlPathPieces' <- traverse URI.mkPathPiece urlPathPieces
|
||||
|
||||
let updatedPath = case URI.uriPath downloadURL' of
|
||||
Just (_, existingPath) ->
|
||||
NonEmpty.append existingPath urlPathPieces'
|
||||
Nothing -> urlPathPieces'
|
||||
pure $ downloadURL'{ uriPath = Just (False, updatedPath) }
|
||||
|
||||
remoteFileExists :: NonEmpty Text -> SlackBuilderT Bool
|
||||
remoteFileExists urlPathPieces = hostedSources urlPathPieces
|
||||
>>= traverse (runReq httpConfig . go . fst) . useHttpsURI
|
||||
<&> maybe False ((== 200) . responseStatusCode)
|
||||
where
|
||||
httpConfig = defaultHttpConfig
|
||||
{ httpConfigCheckResponse = const $ const $ const Nothing
|
||||
}
|
||||
go uri = req HEAD uri NoReqBody ignoreResponse mempty
|
||||
|
||||
cloneAndArchive :: Text -> FilePath -> Text -> SlackBuilderT ()
|
||||
cloneAndArchive repo tarballPath tagPrefix = do
|
||||
let version = snd $ Text.breakOnEnd "-"
|
||||
$ Text.pack $ takeFileName tarballPath
|
||||
|
||||
repositoryTarballPath <- relativeToRepository tarballPath
|
||||
repositoryArchivePath <- relativeToRepository $ tarballPath <.> "tar.xz"
|
||||
liftIO
|
||||
$ removePathForcibly repositoryTarballPath
|
||||
>> callProcess "git"
|
||||
[ "clone"
|
||||
, Text.unpack repo
|
||||
, repositoryTarballPath
|
||||
]
|
||||
>> callProcess "git"
|
||||
[ "-C"
|
||||
, repositoryTarballPath
|
||||
, "checkout"
|
||||
, Text.unpack $ tagPrefix <> version
|
||||
]
|
||||
>> callProcess "git"
|
||||
[ "-C"
|
||||
, repositoryTarballPath
|
||||
, "submodule"
|
||||
, "update"
|
||||
, "--init"
|
||||
, "--recursive"
|
||||
]
|
||||
>> createLzmaTarball repositoryTarballPath repositoryArchivePath
|
||||
>> removePathForcibly repositoryTarballPath
|
||||
|
||||
-- | Takes a directory as input and a file name as output and creates a tar.xz
|
||||
-- archive from the given directory.
|
||||
createLzmaTarball :: FilePath -> FilePath -> IO (Digest MD5)
|
||||
createLzmaTarball input output = runConduitRes $ yield input
|
||||
.| void tarFilePath
|
||||
.| compressLzma
|
||||
.| sinkFileAndHash output
|
||||
|
||||
responseBodySource :: MonadIO m => Response BodyReader -> ConduitT i ByteString m ()
|
||||
responseBodySource = bodyReaderSource . responseBody
|
||||
where
|
||||
bodyReaderSource br = liftIO (brRead br) >>= go br
|
||||
go br bs = unless (ByteString.null bs) $ yield bs >> bodyReaderSource br
|
||||
|
||||
sinkHash :: Monad m => ConduitT ByteString Void m (Digest MD5)
|
||||
sinkHash = sink hashInit
|
||||
where
|
||||
sink ctx = await
|
||||
>>= maybe (pure $ hashFinalize ctx) (sink . hashUpdate ctx)
|
||||
|
||||
cloneAndUpload :: Text -> FilePath -> Text -> SlackBuilderT (URI, Digest MD5)
|
||||
cloneAndUpload repo tarballPath tagPrefix = do
|
||||
let tarballFileName = takeFileName tarballPath <.> "tar.xz"
|
||||
packageName = takeFileName $ takeDirectory tarballPath
|
||||
remoteArchivePath = Text.pack $ packageName </> tarballFileName
|
||||
urlPathPieces = Text.pack <$> packageName :| [tarballFileName]
|
||||
|
||||
localPath <- relativeToRepository tarballFileName
|
||||
remoteResultURI <- hostedSources urlPathPieces
|
||||
remoteFileExists' <- remoteFileExists urlPathPieces
|
||||
|
||||
if remoteFileExists'
|
||||
then (remoteResultURI,) . snd
|
||||
<$> download remoteResultURI (takeDirectory localPath)
|
||||
else
|
||||
let go = sourceFile localPath .| sinkHash
|
||||
in cloneAndArchive repo tarballPath tagPrefix
|
||||
>> uploadSource localPath remoteArchivePath
|
||||
>> liftIO (runConduitRes go) <&> (remoteResultURI,)
|
||||
|
||||
-- | Given a path to a local file and a remote path uploads the file using
|
||||
-- the settings given in the configuration file.
|
||||
--
|
||||
-- The remote path is given relative to the path in the configuration.
|
||||
uploadSource :: FilePath -> Text -> SlackBuilderT ()
|
||||
uploadSource localPath remotePath' = do
|
||||
uploadCommand' :| uploadArguments <- SlackBuilderT $ asks uploadCommand
|
||||
let uploadArguments' = Text.unpack
|
||||
. Text.replace "%s" (Text.pack localPath)
|
||||
. Text.replace "%c" remotePath'
|
||||
<$> uploadArguments
|
||||
|
||||
liftIO $ callProcess (Text.unpack uploadCommand') uploadArguments'
|
||||
|
||||
-- | Downlaods a file into the directory. Returns name of the downloaded file
|
||||
-- and checksum.
|
||||
--
|
||||
-- The filename is read from the disposition header or from the URL if the
|
||||
-- Content-Disposition is missing.
|
||||
download :: URI -> FilePath -> SlackBuilderT (FilePath, Digest MD5)
|
||||
download uri packagePath = runReq defaultHttpConfig go
|
||||
where
|
||||
go
|
||||
| Just uriPath <- URI.uriPath uri =
|
||||
reqGet uri
|
||||
$ readResponse
|
||||
$ Text.unpack
|
||||
$ URI.unRText
|
||||
$ NonEmpty.last
|
||||
$ snd uriPath
|
||||
| otherwise = throwM $ UnsupportedUrlType uri
|
||||
readResponse :: FilePath -> Response BodyReader -> IO (FilePath, Digest MD5)
|
||||
readResponse downloadFileName response = do
|
||||
let attachmentName = dispositionAttachment response
|
||||
targetFileName = fromMaybe downloadFileName attachmentName
|
||||
target = packagePath </> fromMaybe downloadFileName attachmentName
|
||||
digest <- runConduitRes
|
||||
$ responseBodySource response
|
||||
.| sinkFileAndHash target
|
||||
pure (targetFileName, digest)
|
||||
|
||||
-- | Writes a file to the destination path and accumulates its MD5 checksum.
|
||||
sinkFileAndHash :: MonadResource m => FilePath -> ConduitT ByteString Void m (Digest MD5)
|
||||
sinkFileAndHash target = getZipSink
|
||||
$ ZipSink (sinkFile target) *> ZipSink sinkHash
|
||||
|
||||
compressLzma :: MonadIO m => ConduitT ByteString ByteString m ()
|
||||
compressLzma = liftIO (Lzma.compressIO Lzma.defaultCompressParams) >>= go
|
||||
where
|
||||
go (Lzma.CompressInputRequired flush supplyInput) = do
|
||||
next <- await
|
||||
result <- case next of
|
||||
Just input
|
||||
| ByteString.null input -> liftIO flush
|
||||
| otherwise -> liftIO $ supplyInput input
|
||||
Nothing -> liftIO $ supplyInput mempty
|
||||
go result
|
||||
go (Lzma.CompressOutputAvailable output stream) = yield output
|
||||
>> liftIO stream >>= go
|
||||
go Lzma.CompressStreamEnd = pure ()
|
||||
|
||||
decompressLzma :: (MonadThrow m, MonadIO m) => ConduitT ByteString ByteString m ()
|
||||
decompressLzma = liftIO (Lzma.decompressIO Lzma.defaultDecompressParams) >>= go
|
||||
where
|
||||
go (Lzma.DecompressInputRequired processor) = do
|
||||
next <- awaitNonNull
|
||||
result <- case next of
|
||||
Just input -> liftIO $ processor (toNullable input)
|
||||
Nothing -> liftIO $ processor mempty
|
||||
go result
|
||||
go (Lzma.DecompressOutputAvailable output stream) = yield output
|
||||
>> liftIO stream
|
||||
>>= go
|
||||
go (Lzma.DecompressStreamEnd output) = leftover output
|
||||
go (Lzma.DecompressStreamError lzmaReturn) = throwM
|
||||
$ LzmaDecompressionFailed lzmaReturn
|
||||
|
||||
-- | Downloads a compressed tar archive and extracts its contents on the fly to
|
||||
-- a directory.
|
||||
--
|
||||
-- If the download contains the disposition header and the attachment type was
|
||||
-- recognized as tar archive, returns the attachment name from the
|
||||
-- disposition header without the extension. So if the disposition header
|
||||
-- is "attachment; filename=package-1.2.3.tar.gz", returns "package-1.2.3".
|
||||
extractRemote :: URI -> FilePath -> SlackBuilderT (Maybe FilePath)
|
||||
extractRemote uri' packagePath =
|
||||
runReq defaultHttpConfig $ go packagePath
|
||||
where
|
||||
go toTarget = reqGet uri' $ readResponse toTarget
|
||||
readResponse :: FilePath -> Response BodyReader -> IO (Maybe FilePath)
|
||||
readResponse toTarget response = do
|
||||
let attachmentName = dispositionAttachment response
|
||||
(decompress, attachmentDirectory) =
|
||||
case attachmentName of
|
||||
Just attachmentName'
|
||||
| Just directoryName' <- stripExtension ".tar.gz" attachmentName' ->
|
||||
(Zlib.ungzip, Just directoryName')
|
||||
| Just directoryName' <- stripExtension ".tar.xz" attachmentName' ->
|
||||
(decompressLzma, Just directoryName')
|
||||
_ -> (pure (), Nothing)
|
||||
runConduitRes $ responseBodySource response
|
||||
.| decompress
|
||||
.| untar (withDecompressedFile toTarget)
|
||||
pure attachmentDirectory
|
||||
withDecompressedFile toTarget FileInfo{..}
|
||||
| Char8.last filePath /= '/' =
|
||||
sinkFile (toTarget </> Char8.unpack filePath)
|
||||
| otherwise = liftIO (createDirectory (toTarget </> Char8.unpack filePath))
|
||||
|
||||
dispositionAttachment :: Response BodyReader -> Maybe FilePath
|
||||
dispositionAttachment response
|
||||
= fmap (Char8.unpack . snd . Char8.breakEnd (== '=') . snd)
|
||||
$ find ((== "Content-Disposition") . fst)
|
||||
$ responseHeaders response
|
||||
|
||||
reqGet :: (MonadThrow m, MonadHttp m)
|
||||
=> URI
|
||||
-> (Response BodyReader -> IO a)
|
||||
-> m a
|
||||
reqGet uri bodyReader =
|
||||
case useURI uri of
|
||||
Just urlWithOptions
|
||||
| Left (httpsURI, httpsOptions) <- urlWithOptions ->
|
||||
reqBr GET httpsURI NoReqBody httpsOptions bodyReader
|
||||
| Right (httpsURI, httpsOptions) <- urlWithOptions ->
|
||||
reqBr GET httpsURI NoReqBody httpsOptions bodyReader
|
||||
_ -> throwM $ UnsupportedUrlType uri
|
166
lib/SlackBuilder/Info.hs
Normal file
166
lib/SlackBuilder/Info.hs
Normal file
@ -0,0 +1,166 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | Info file parsing and printing.
|
||||
module SlackBuilder.Info
|
||||
( PackageInfo(..)
|
||||
, generate
|
||||
, parseInfoFile
|
||||
, readInfoFile
|
||||
) where
|
||||
|
||||
import Control.Applicative (Alternative(..))
|
||||
import Control.Monad.Combinators (sepBy)
|
||||
import qualified Data.ByteArray as ByteArray
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import qualified Data.ByteString.Char8 as Char8
|
||||
import Data.Maybe (mapMaybe)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.Encoding as Text
|
||||
import qualified Data.Text.Lazy as Lazy.Text
|
||||
import qualified Data.Text.Lazy.Builder as Text.Builder
|
||||
import qualified Data.Text.Lazy.Builder as Text (Builder)
|
||||
import Crypto.Hash (Digest, MD5, digestFromByteString)
|
||||
import Data.Void (Void)
|
||||
import Data.Word (Word8)
|
||||
import Numeric (readHex, showHex)
|
||||
import Text.Megaparsec (Parsec, count, eof, parse, takeWhile1P)
|
||||
import Text.Megaparsec.Byte (hspace1, space, string, hexDigitChar)
|
||||
import Text.URI
|
||||
( URI(..)
|
||||
, parserBs
|
||||
, render
|
||||
)
|
||||
import qualified Data.Word8 as Word8
|
||||
import SlackBuilder.Trans
|
||||
( SlackBuilderT(..)
|
||||
, SlackBuilderException(..)
|
||||
, relativeToRepository
|
||||
)
|
||||
import System.FilePath ((</>), (<.>))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Conduit (MonadThrow(throwM))
|
||||
import Control.Monad (void)
|
||||
|
||||
type GenParser = Parsec Void ByteString
|
||||
|
||||
-- | Data used to generate an .info file.
|
||||
data PackageInfo = PackageInfo
|
||||
{ pkgname :: String
|
||||
, version :: Text
|
||||
, homepage :: Text
|
||||
, downloads :: [URI]
|
||||
, checksums :: [Digest MD5]
|
||||
, downloadX64 :: [URI]
|
||||
, checksumX64 :: [Digest MD5]
|
||||
, requires :: [ByteString]
|
||||
, maintainer :: Text
|
||||
, email :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
variableEntry :: ByteString -> GenParser ByteString
|
||||
variableEntry variable = string (Char8.append variable "=\"")
|
||||
*> takeWhile1P Nothing (0x22 /=)
|
||||
<* string "\"\n"
|
||||
|
||||
variableSeparator :: GenParser ()
|
||||
variableSeparator = void $ some $ hspace1 <|> void (string "\\\n")
|
||||
|
||||
packageDownloads :: ByteString -> GenParser [URI]
|
||||
packageDownloads variableName = string (variableName <> "=\"")
|
||||
*> sepBy parserBs variableSeparator
|
||||
<* string "\"\n"
|
||||
|
||||
hexDigit :: GenParser Word8
|
||||
hexDigit = count 2 hexDigitChar
|
||||
>>= extractNumber . readHex . fmap (toEnum . fromIntegral)
|
||||
where
|
||||
extractNumber [(number, "")] = pure number
|
||||
extractNumber _ = fail "Unable to convert a 2-digit hexadecimal number"
|
||||
|
||||
packageChecksum :: GenParser ByteString
|
||||
packageChecksum = ByteString.pack <$> count 16 hexDigit
|
||||
|
||||
packageChecksums :: ByteString -> GenParser [ByteString]
|
||||
packageChecksums variableName = string (variableName <> "=\"")
|
||||
*> sepBy packageChecksum variableSeparator
|
||||
<* string "\"\n"
|
||||
|
||||
packageRequires :: GenParser [ByteString]
|
||||
packageRequires = string "REQUIRES=\""
|
||||
*> sepBy (packageName <|> string "%README%") space
|
||||
<* string "\"\n"
|
||||
|
||||
packageName :: GenParser ByteString
|
||||
packageName = takeWhile1P Nothing isNameToken
|
||||
where
|
||||
isNameToken x = Word8.isAlphaNum x
|
||||
|| x == Word8._hyphen
|
||||
|| x == Word8._underscore
|
||||
|| x == Word8._period
|
||||
|
||||
parseInfoFile :: GenParser PackageInfo
|
||||
parseInfoFile = PackageInfo . Char8.unpack
|
||||
<$> packagePrgnam
|
||||
<*> (Text.decodeUtf8 <$> variableEntry "VERSION")
|
||||
<*> (Text.decodeUtf8 <$> variableEntry "HOMEPAGE")
|
||||
<*> packageDownloads "DOWNLOAD"
|
||||
<*> (mapMaybe digestFromByteString <$> packageChecksums "MD5SUM")
|
||||
<*> packageDownloads "DOWNLOAD_x86_64"
|
||||
<*> (mapMaybe digestFromByteString <$> packageChecksums "MD5SUM_x86_64")
|
||||
<*> packageRequires
|
||||
<*> (Text.decodeUtf8 <$> variableEntry "MAINTAINER")
|
||||
<*> (Text.decodeUtf8 <$> variableEntry "EMAIL")
|
||||
<* eof
|
||||
where
|
||||
packagePrgnam = (string "PKGNAM" <|> string "PRGNAM")
|
||||
>> string "=\""
|
||||
*> packageName
|
||||
<* "\"\n"
|
||||
|
||||
readInfoFile :: Text -> Text -> SlackBuilderT PackageInfo
|
||||
readInfoFile category packageName' = do
|
||||
let packageName'' = Text.unpack packageName'
|
||||
|
||||
infoPath <- relativeToRepository
|
||||
$ Text.unpack category </> packageName'' </> packageName'' <.> "info"
|
||||
infoContents <- liftIO $ ByteString.readFile infoPath
|
||||
|
||||
either (throwM . MalformedInfoFile) pure
|
||||
$ parse parseInfoFile infoPath infoContents
|
||||
|
||||
generate :: PackageInfo -> Text
|
||||
generate pkg = Lazy.Text.toStrict $ Text.Builder.toLazyText builder
|
||||
where
|
||||
digestToText = Text.pack . foldr hexAppender "" . ByteArray.unpack
|
||||
hexAppender x acc
|
||||
| x > 15 = showHex x acc
|
||||
| otherwise = '0' : showHex x acc
|
||||
builder = "PRGNAM=\"" <> Text.Builder.fromString (pkgname pkg) <> "\"\n"
|
||||
<> "VERSION=\"" <> Text.Builder.fromText (version pkg) <> "\"\n"
|
||||
<> "HOMEPAGE=\"" <> Text.Builder.fromText (homepage pkg) <> "\"\n"
|
||||
<> downloadEntry
|
||||
<> generateMultiEntry "MD5SUM" (digestToText <$> checksums pkg)
|
||||
<> generateMultiEntry "DOWNLOAD_x86_64" (render <$> downloadX64 pkg)
|
||||
<> generateMultiEntry "MD5SUM_x86_64" (digestToText <$> checksumX64 pkg)
|
||||
<> "REQUIRES=\"" <> fromByteStringWords (requires pkg) <> "\"\n"
|
||||
<> "MAINTAINER=\"" <> Text.Builder.fromText (maintainer pkg) <> "\"\n"
|
||||
<> "EMAIL=\"" <> Text.Builder.fromText (email pkg) <> "\"\n"
|
||||
fromByteStringWords = Text.Builder.fromText
|
||||
. Text.unwords . fmap Text.decodeUtf8
|
||||
downloadEntry
|
||||
| null $ downloads pkg
|
||||
, not $ null $ downloadX64 pkg = "DOWNLOAD=\"UNSUPPORTED\"\n"
|
||||
| otherwise = generateMultiEntry "DOWNLOAD" $ render <$> downloads pkg
|
||||
|
||||
generateMultiEntry :: Text -> [Text] -> Text.Builder
|
||||
generateMultiEntry name entries = Text.Builder.fromText name
|
||||
<> "=\""
|
||||
<> Text.Builder.fromText (Text.intercalate separator entries)
|
||||
<> "\"\n"
|
||||
where
|
||||
padLength = Text.length name + 2
|
||||
separator = " \\\n" <> Text.replicate padLength " "
|
307
lib/SlackBuilder/LatestVersionCheck.hs
Normal file
307
lib/SlackBuilder/LatestVersionCheck.hs
Normal file
@ -0,0 +1,307 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | This module contains implementations to check the latest version of a
|
||||
-- package hosted by a specific service.
|
||||
module SlackBuilder.LatestVersionCheck
|
||||
( PackageOwner(..)
|
||||
, TextArguments(..)
|
||||
, latestGitHub
|
||||
, latestPackagist
|
||||
, latestText
|
||||
, match
|
||||
) where
|
||||
|
||||
import SlackBuilder.Config
|
||||
import qualified Data.Aeson as Aeson
|
||||
import Data.Aeson ((.:))
|
||||
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 as Text
|
||||
import qualified Data.Text.Encoding as Text.Encoding
|
||||
import Data.Vector (Vector, (!?))
|
||||
import qualified Data.Vector as Vector
|
||||
import Network.HTTP.Req
|
||||
( header
|
||||
, runReq
|
||||
, defaultHttpConfig
|
||||
, req
|
||||
, GET(..)
|
||||
, https
|
||||
, jsonResponse
|
||||
, NoReqBody(..)
|
||||
, (/:)
|
||||
, responseBody
|
||||
, POST(..)
|
||||
, ReqBodyJson(..)
|
||||
, JsonResponse
|
||||
)
|
||||
import Text.URI (mkURI)
|
||||
import SlackBuilder.Trans
|
||||
import qualified Data.Aeson.KeyMap as KeyMap
|
||||
import GHC.Records (HasField(..))
|
||||
import Control.Monad.Trans.Reader (asks)
|
||||
import Data.Char (isAlpha)
|
||||
import SlackBuilder.Download (responseBodySource, reqGet)
|
||||
import Network.HTTP.Client (BodyReader, Response(..))
|
||||
import Conduit (decodeUtf8C, (.|), linesUnboundedC, sinkNull, runConduit)
|
||||
import qualified Data.Conduit.List as CL
|
||||
import Data.Conduit.Process (sourceProcessWithStreams, proc)
|
||||
import Data.Maybe (listToMaybe, mapMaybe)
|
||||
|
||||
data PackageOwner = PackageOwner
|
||||
{ owner :: Text
|
||||
, name :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data MatchState = MatchState
|
||||
{ ignoring :: !Bool
|
||||
, matched :: !Text
|
||||
, pattern' :: ![MatchToken]
|
||||
} deriving (Eq, Show)
|
||||
|
||||
data MatchToken
|
||||
= OpenParenMatchToken
|
||||
| CloseParenMatchToken
|
||||
| SymbolMatchToken Char
|
||||
| AtLeastMatchToken [Char]
|
||||
| OneOfMatchToken [Char]
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- | Matches a string (for example a version name or CVS tag) against a pattern.
|
||||
-- Returns the matched part of the string or 'Nothing' if there is not match.
|
||||
--
|
||||
-- The pattern is just a list of characters with some special characters and
|
||||
-- sequences.
|
||||
--
|
||||
-- * ( ) - The text in parentheses is matched but no saved in the resulting
|
||||
-- string.
|
||||
-- * \\d - Matches zero or more digits.
|
||||
-- * \\D - Matches one or more digits.
|
||||
-- * \\. - Matches zero or more digits or dots.
|
||||
-- * \\\\ - Matches a back slash.
|
||||
-- * * - Matches everything.
|
||||
-- * [ ] - Match one of the characters inbetween. The characters are
|
||||
-- matched verbatim.
|
||||
--
|
||||
-- For example the following expression matches tags like @v1.2.3@, but returns
|
||||
-- only @1.2.3@.
|
||||
--
|
||||
-- @
|
||||
-- (v)\\.
|
||||
-- @
|
||||
match :: Text -> Text -> Maybe Text
|
||||
match fullPattern = go startState
|
||||
where
|
||||
startState = MatchState
|
||||
{ ignoring = False
|
||||
, matched = mempty
|
||||
, pattern' = parsePattern fullPattern
|
||||
}
|
||||
go :: MatchState -> Text -> Maybe Text
|
||||
-- There is no input, look at the remaining tokens.
|
||||
go MatchState{ pattern' = [], matched } "" = Just matched
|
||||
go state@MatchState{ pattern' = OpenParenMatchToken : tokens } input' =
|
||||
go (state{ ignoring = True, pattern' = tokens }) input'
|
||||
go state@MatchState{ pattern' = CloseParenMatchToken : tokens } input' =
|
||||
go (state{ ignoring = False, pattern' = tokens }) input'
|
||||
go state@MatchState{ pattern' = SymbolMatchToken patternCharacter : tokens } input'
|
||||
| Just (nextCharacter, leftOver) <- Text.uncons input'
|
||||
, patternCharacter == nextCharacter =
|
||||
go (matchSymbolToken state{ pattern' = tokens } nextCharacter) leftOver
|
||||
| otherwise = Nothing
|
||||
go state@MatchState{ pattern' = OneOfMatchToken chars : tokens } input'
|
||||
| Just (nextCharacter, leftOver) <- Text.uncons input'
|
||||
, nextCharacter `elem` chars =
|
||||
go (matchSymbolToken state nextCharacter) leftOver
|
||||
| otherwise =
|
||||
go (state{ pattern' = tokens }) input'
|
||||
go state@MatchState{ pattern' = AtLeastMatchToken chars : tokens } input'
|
||||
| Just (nextCharacter, leftOver) <- Text.uncons input'
|
||||
, nextCharacter `elem` chars =
|
||||
go (matchSymbolToken state{ pattern' = OneOfMatchToken chars : tokens } nextCharacter) leftOver
|
||||
| otherwise = Nothing
|
||||
-- All tokens are processed, but there is still some input left.
|
||||
go MatchState{ pattern' = [] } _ = Nothing
|
||||
matchSymbolToken state nextCharacter
|
||||
| getField @"ignoring" state = state
|
||||
| otherwise = state
|
||||
{ matched = Text.snoc (getField @"matched" state) nextCharacter
|
||||
}
|
||||
|
||||
parsePattern :: Text -> [MatchToken]
|
||||
parsePattern input'
|
||||
| Just (firstChar, remaining) <- Text.uncons input'
|
||||
, firstChar == '\\' =
|
||||
case Text.uncons remaining of
|
||||
Nothing -> []
|
||||
Just ('d', remaining') -> OneOfMatchToken digits
|
||||
: parsePattern remaining'
|
||||
Just ('D', remaining') -> AtLeastMatchToken digits
|
||||
: parsePattern remaining'
|
||||
Just ('.', remaining') -> AtLeastMatchToken ('.' : digits)
|
||||
: parsePattern remaining'
|
||||
Just ('\\', remaining') -> SymbolMatchToken '\\'
|
||||
: parsePattern remaining'
|
||||
Just (_, remaining') -> parsePattern remaining'
|
||||
| Just (firstChar, remaining) <- Text.uncons input'
|
||||
, firstChar == '['
|
||||
, Just lastBracket <- Text.findIndex (== ']') remaining
|
||||
= OneOfMatchToken (Text.unpack $ Text.take lastBracket remaining)
|
||||
: parsePattern (Text.drop (succ lastBracket) remaining)
|
||||
| Just (firstChar, remaining) <- Text.uncons input' =
|
||||
let token =
|
||||
case firstChar of
|
||||
'*' -> OneOfMatchToken (toEnum <$> [32 .. 127])
|
||||
'(' -> OpenParenMatchToken
|
||||
')' -> CloseParenMatchToken
|
||||
s -> SymbolMatchToken s
|
||||
in token : parsePattern remaining
|
||||
| otherwise = []
|
||||
where
|
||||
digits = toEnum <$> [fromEnum '0' .. fromEnum '9']
|
||||
|
||||
-- * Packagist
|
||||
|
||||
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)
|
||||
|
||||
latestPackagist :: PackageOwner -> SlackBuilderT (Maybe Text)
|
||||
latestPackagist PackageOwner{..} = do
|
||||
packagistResponse <- runReq defaultHttpConfig $
|
||||
let uri = https "repo.packagist.org" /: "p2"
|
||||
/: owner
|
||||
/: name <> ".json"
|
||||
in req GET uri NoReqBody jsonResponse mempty
|
||||
let packagistPackages = getField @"packages"
|
||||
$ Network.HTTP.Req.responseBody (packagistResponse :: JsonResponse PackagistResponse)
|
||||
fullName = Text.intercalate "/" [owner, name]
|
||||
|
||||
pure $ HashMap.lookup fullName packagistPackages
|
||||
>>= fmap (getField @"version" . fst) . Vector.uncons
|
||||
|
||||
-- * Remote text file
|
||||
|
||||
data TextArguments = TextArguments
|
||||
{ textURL :: Text
|
||||
, versionPicker :: [String]
|
||||
}
|
||||
|
||||
latestText :: TextArguments -> Text -> SlackBuilderT (Maybe Text)
|
||||
latestText TextArguments{..} pattern' = do
|
||||
uri' <- mkURI textURL
|
||||
versions <- case versionPicker of
|
||||
(command : arguments) ->
|
||||
runReq defaultHttpConfig $ reqGet uri' $ readResponse command arguments
|
||||
[] -> runReq defaultHttpConfig $ reqGet uri' go
|
||||
pure $ listToMaybe $ mapMaybe (match pattern') versions
|
||||
where
|
||||
readResponse :: String -> [String] -> Response BodyReader -> IO [Text]
|
||||
readResponse command arguments response = do
|
||||
let createProcess' = proc command arguments
|
||||
(_, stdout', _) <- sourceProcessWithStreams createProcess' (responseBodySource response) stdoutReader sinkNull
|
||||
pure stdout'
|
||||
stdoutReader = decodeUtf8C .| linesUnboundedC .| CL.consume
|
||||
go response = runConduit $ responseBodySource response .| stdoutReader
|
||||
|
||||
-- * GitHub
|
||||
|
||||
newtype GhRefNode = GhRefNode
|
||||
{ name :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhRefNode)
|
||||
|
||||
newtype GhRef = GhRef
|
||||
{ nodes :: Vector GhRefNode
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhRef)
|
||||
|
||||
newtype GhRepository = GhRepository
|
||||
{ refs :: GhRef
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhRepository)
|
||||
|
||||
newtype GhData = GhData
|
||||
{ repository :: GhRepository
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance Aeson.FromJSON GhData where
|
||||
parseJSON (Aeson.Object keyMap)
|
||||
| Just data' <- KeyMap.lookup "data" keyMap =
|
||||
GhData <$> Aeson.withObject "GhData" (.: "repository") data'
|
||||
parseJSON _ = fail "data key not found in the response"
|
||||
|
||||
data GhVariables = GhVariables
|
||||
{ name :: Text
|
||||
, owner :: Text
|
||||
, prefix :: Maybe Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhVariables)
|
||||
|
||||
data GhQuery = GhQuery
|
||||
{ query :: Text
|
||||
, variables :: GhVariables
|
||||
} deriving (Eq, Show)
|
||||
|
||||
$(deriveJSON defaultOptions ''GhQuery)
|
||||
|
||||
latestGitHub
|
||||
:: PackageOwner
|
||||
-> Text
|
||||
-> SlackBuilderT (Maybe Text)
|
||||
latestGitHub PackageOwner{..} pattern' = do
|
||||
ghToken' <- SlackBuilderT $ asks ghToken
|
||||
ghResponse <- runReq defaultHttpConfig $
|
||||
let uri = https "api.github.com" /: "graphql"
|
||||
prefix = Text.takeWhile isAlpha
|
||||
$ Text.filter (liftA2 (&&) (/= ')') (/= '(')) pattern'
|
||||
query = GhQuery
|
||||
{ query = githubQuery
|
||||
, variables = GhVariables
|
||||
{ owner = owner
|
||||
, name = name
|
||||
, prefix = if Text.null prefix then Nothing else Just $ prefix <> "*"
|
||||
}
|
||||
}
|
||||
authorizationHeader = header "authorization"
|
||||
$ Text.Encoding.encodeUtf8
|
||||
$ "Bearer " <> ghToken'
|
||||
in req POST uri (ReqBodyJson query) jsonResponse
|
||||
$ authorizationHeader <> header "User-Agent" "SlackBuilder"
|
||||
let ghNodes = nodes
|
||||
$ refs
|
||||
$ (getField @"repository" :: GhData -> GhRepository)
|
||||
$ Network.HTTP.Req.responseBody ghResponse
|
||||
refs' = Vector.catMaybes
|
||||
$ match pattern' . getField @"name" <$> ghNodes
|
||||
pure $ refs' !? 0
|
||||
where
|
||||
githubQuery =
|
||||
"query ($name: String!, $owner: String!, $prefix: String) {\n\
|
||||
\ repository(name: $name, owner: $owner) {\n\
|
||||
\ refs(first: 10, query: $prefix, refPrefix: \"refs/tags/\", orderBy: {\n\
|
||||
\ field: TAG_COMMIT_DATE, direction: DESC\n\
|
||||
\ }) {\n\
|
||||
\ nodes {\n\
|
||||
\ id,\n\
|
||||
\ name\n\
|
||||
\ }\n\
|
||||
\ }\n\
|
||||
\ }\n\
|
||||
\}"
|
@ -1,115 +1,81 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | Contains data describing packages, methods to update them and to request
|
||||
-- information about them.
|
||||
module SlackBuilder.Package
|
||||
( DownloadPlaceholder(..)
|
||||
( DataBaseEntry(..)
|
||||
, Download(..)
|
||||
, DownloadTemplate(..)
|
||||
, PackageInfo(..)
|
||||
, Maintainer(..)
|
||||
, PackageDescription(..)
|
||||
, PackageUpdateData(..)
|
||||
, Updater(..)
|
||||
, infoTemplate
|
||||
, renderDownloadWithVersion
|
||||
, renderTextWithVersion
|
||||
) where
|
||||
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import Text.URI (URI(..))
|
||||
import qualified Text.URI as URI
|
||||
import Crypto.Hash (Digest, MD5)
|
||||
import GHC.Records (HasField(..))
|
||||
import System.FilePath (takeBaseName)
|
||||
import Data.List (partition)
|
||||
import SlackBuilder.Trans
|
||||
import Control.Monad.Catch (MonadThrow)
|
||||
import Data.Map (Map)
|
||||
|
||||
-- | Contains information how a package can be updated.
|
||||
data PackageDescription = PackageDescription
|
||||
{ latest :: Updater
|
||||
, downloaders :: Map Text Updater
|
||||
, name :: Text
|
||||
}
|
||||
|
||||
data PackageUpdateData = PackageUpdateData
|
||||
{ description :: PackageDescription
|
||||
, category :: Text
|
||||
, version :: Text
|
||||
}
|
||||
|
||||
-- | Download URI with the MD5 checksum of the target.
|
||||
data Download = Download
|
||||
{ download :: URI
|
||||
, md5sum :: Digest MD5
|
||||
, is64 :: Bool
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Data used to generate an .info file.
|
||||
data PackageInfo = PackageInfo
|
||||
{ path :: FilePath
|
||||
, version :: Text
|
||||
, homepage :: Text
|
||||
, requires :: [Text]
|
||||
, maintainer :: Maintainer
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Package maintainer information.
|
||||
data Maintainer = Maintainer
|
||||
{ name :: Text
|
||||
, email :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Appears in the download URI template and specifies which part of the URI
|
||||
-- should be replaced with the package version.
|
||||
data DownloadPlaceholder
|
||||
= StaticPlaceholder Text
|
||||
| VersionPlaceholder
|
||||
deriving Eq
|
||||
|
||||
instance Show DownloadPlaceholder
|
||||
where
|
||||
show (StaticPlaceholder staticPlaceholder) = Text.unpack staticPlaceholder
|
||||
show VersionPlaceholder = "{version}"
|
||||
|
||||
-- | List of URI components, including version placeholders.
|
||||
newtype DownloadTemplate = DownloadTemplate (NonEmpty DownloadPlaceholder)
|
||||
deriving Eq
|
||||
newtype DownloadTemplate = DownloadTemplate
|
||||
{ unDownloadTemplate :: Text
|
||||
} deriving Eq
|
||||
|
||||
instance Show DownloadTemplate
|
||||
where
|
||||
show (DownloadTemplate components) = concatMap show components
|
||||
show = Text.unpack . unDownloadTemplate
|
||||
|
||||
-- | Replaces placeholders in the URL template with the given version.
|
||||
renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
|
||||
renderDownloadWithVersion (DownloadTemplate components) version =
|
||||
URI.mkURI $ foldr f "" components
|
||||
where
|
||||
f (StaticPlaceholder staticPlaceholder) = (staticPlaceholder <>)
|
||||
f VersionPlaceholder = (version <>)
|
||||
renderDownloadWithVersion (DownloadTemplate template) version =
|
||||
URI.mkURI $ renderTextWithVersion template version
|
||||
|
||||
-- | Replaces placeholders in the text with the given version.
|
||||
renderTextWithVersion :: Text -> Text -> Text
|
||||
renderTextWithVersion template version = Text.replace "{version}" version template
|
||||
|
||||
-- | Function used to get the latest version of a source.
|
||||
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate
|
||||
data Updater = Updater
|
||||
{ detectLatest :: SlackBuilderT (Maybe Text)
|
||||
, is64 :: Bool
|
||||
, getVersion :: Text -> Text -> SlackBuilderT Download
|
||||
}
|
||||
|
||||
packageName :: PackageInfo -> Text
|
||||
packageName PackageInfo{ path } = Text.pack $ takeBaseName path
|
||||
data DataBaseEntry = DataBaseEntry
|
||||
{ name :: Text
|
||||
, version :: Text
|
||||
, arch :: Text
|
||||
, build :: Text
|
||||
} deriving Eq
|
||||
|
||||
infoTemplate :: PackageInfo -> [Download] -> Text
|
||||
infoTemplate package downloads =
|
||||
let (downloads64, downloads32) = partition (getField @"is64") downloads
|
||||
(download32, md5sum32, download64, md5sum64) = downloadEntries downloads64 downloads32
|
||||
|
||||
in Text.unlines
|
||||
[ "PRGNAM=\"" <> packageName package <> "\""
|
||||
, "VERSION=\"" <> getField @"version" package <> "\""
|
||||
, "HOMEPAGE=\"" <> getField @"homepage" package <> "\""
|
||||
, "DOWNLOAD=\"" <> download32 <> "\""
|
||||
, "MD5SUM=\"" <> md5sum32 <> "\""
|
||||
, "DOWNLOAD_x86_64=\"" <> download64 <> "\""
|
||||
, "MD5SUM_x86_64=\"" <> md5sum64 <> "\""
|
||||
, "REQUIRES=\"" <> Text.unwords (getField @"requires" package) <> "\""
|
||||
, "MAINTAINER=\"" <> getField @"name" (getField @"maintainer" package) <> "\""
|
||||
, "EMAIL=\"" <> getField @"email" (getField @"maintainer" package) <> "\""
|
||||
]
|
||||
|
||||
downloadEntries :: [Download] -> [Download] -> (Text, Text, Text, Text)
|
||||
downloadEntries downloads64 downloads32 =
|
||||
let download32 =
|
||||
if null downloads32 && not (null downloads64)
|
||||
then
|
||||
"UNSUPPORTED"
|
||||
else
|
||||
Text.intercalate " \\\n "
|
||||
$ URI.render . getField @"download" <$> downloads32
|
||||
|
||||
md5sum32 = Text.intercalate " \\\n "
|
||||
$ Text.pack . show . getField @"md5sum" <$> downloads32
|
||||
download64 = Text.intercalate " \\\n "
|
||||
$ URI.render . getField @"download" <$> downloads64
|
||||
md5sum64 = Text.intercalate " \\\n "
|
||||
$ Text.pack . show . getField @"md5sum" <$> downloads64
|
||||
|
||||
in (download32, md5sum32, download64, md5sum64)
|
||||
instance Show DataBaseEntry
|
||||
where
|
||||
show DataBaseEntry{..} = Text.unpack
|
||||
$ Text.intercalate "-" [name, version, arch, build]
|
||||
|
@ -1,15 +1,75 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | Transformers and exceptions.
|
||||
module SlackBuilder.Trans
|
||||
( SlackBuilderT(..)
|
||||
( SlackBuilderException(..)
|
||||
, SlackBuilderT(..)
|
||||
, relativeToRepository
|
||||
) where
|
||||
|
||||
import Control.Monad.Trans.Reader (ReaderT(..))
|
||||
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
||||
import Data.ByteString (ByteString)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import SlackBuilder.Config
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
|
||||
import Control.Exception (Exception(..))
|
||||
import System.FilePath ((</>))
|
||||
import Text.URI (URI)
|
||||
import qualified Text.URI as URI
|
||||
import qualified Codec.Compression.Lzma as Lzma
|
||||
import Text.Megaparsec (ParseErrorBundle(..), errorBundlePretty)
|
||||
import Conduit (Void)
|
||||
|
||||
data SlackBuilderException
|
||||
= UpdaterNotFound Text
|
||||
| UnsupportedUrlType URI
|
||||
| LzmaDecompressionFailed Lzma.LzmaRet
|
||||
| MalformedInfoFile (ParseErrorBundle ByteString Void)
|
||||
deriving Show
|
||||
|
||||
instance Exception SlackBuilderException
|
||||
where
|
||||
displayException (UpdaterNotFound updateName) = Text.unpack
|
||||
$ Text.concat ["Requested package \"", updateName, "\" was not found"]
|
||||
displayException (UnsupportedUrlType givenURI) = Text.unpack
|
||||
$ "Only https URLs are supported, got: " <> URI.render givenURI
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetOK) =
|
||||
"Operation completed successfully"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetStreamEnd) =
|
||||
"End of stream was reached"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetUnsupportedCheck) =
|
||||
"Cannot calculate the integrity check"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetGetCheck) =
|
||||
"Integrity check type is now available"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetMemError) =
|
||||
"Cannot allocate memory"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetMemlimitError) =
|
||||
"Memory usage limit was reached"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetFormatError) =
|
||||
"File format not recognized"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetOptionsError) =
|
||||
"Invalid or unsupported options"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetDataError) =
|
||||
"Data is corrupt"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetBufError) =
|
||||
"No progress is possible"
|
||||
displayException (LzmaDecompressionFailed Lzma.LzmaRetProgError) =
|
||||
"Programming error"
|
||||
displayException (MalformedInfoFile errorBundle) =
|
||||
errorBundlePretty errorBundle
|
||||
|
||||
newtype SlackBuilderT a = SlackBuilderT
|
||||
{ runSlackBuilderT :: ReaderT Settings IO a
|
||||
}
|
||||
|
||||
relativeToRepository :: FilePath -> SlackBuilderT FilePath
|
||||
relativeToRepository filePath =
|
||||
(</> filePath) <$> SlackBuilderT (asks repository)
|
||||
|
||||
instance Functor SlackBuilderT
|
||||
where
|
||||
fmap f (SlackBuilderT slackBuilderT) = SlackBuilderT $ f <$> slackBuilderT
|
||||
@ -27,3 +87,12 @@ instance Monad SlackBuilderT
|
||||
instance MonadIO SlackBuilderT
|
||||
where
|
||||
liftIO = SlackBuilderT . liftIO
|
||||
|
||||
instance MonadThrow SlackBuilderT
|
||||
where
|
||||
throwM = SlackBuilderT . throwM
|
||||
|
||||
instance MonadCatch SlackBuilderT
|
||||
where
|
||||
catch (SlackBuilderT action) handler =
|
||||
SlackBuilderT $ catch action $ runSlackBuilderT . handler
|
||||
|
@ -1,57 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../config/config'
|
||||
require_relative 'package'
|
||||
require 'net/http'
|
||||
require 'pathname'
|
||||
require 'progressbar'
|
||||
require 'term/ansicolor'
|
||||
|
||||
module SlackBuilder
|
||||
extend Rake::FileUtilsExt
|
||||
|
||||
def self.clone(repo, tarball, tag_prefix = 'v')
|
||||
`./bin/slackbuilder clone #{repo} #{tarball} #{tag_prefix}`
|
||||
end
|
||||
|
||||
def self.download(uri, target)
|
||||
`./bin/slackbuilder download #{uri} #{target}`.strip
|
||||
end
|
||||
|
||||
def self.hosted_sources(absolute_url)
|
||||
CONFIG[:download_url] + absolute_url
|
||||
end
|
||||
|
||||
def self.remote_file_exists?(url)
|
||||
`./bin/slackbuilder exists #{url}`.strip == 'True'
|
||||
end
|
||||
|
||||
def self.download_and_deploy(uri, tarball)
|
||||
`./bin/slackbuilder deploy #{uri} #{tarball}`.strip
|
||||
end
|
||||
|
||||
private_class_method def self.upload_command(local_path, remote_path)
|
||||
['scp', "slackbuilds/#{local_path}", CONFIG[:remote_path] + remote_path]
|
||||
end
|
||||
|
||||
private_class_method def self.clone_and_archive(repo, name_version, tarball, tag_prefix = 'v')
|
||||
sh './bin/slackbuilder', 'archive', repo, name_version, tarball, tag_prefix
|
||||
end
|
||||
end
|
||||
|
||||
def write_info(package, downloads:)
|
||||
File.write "slackbuilds/#{package.path}/#{package.name}.info",
|
||||
info_template(package, downloads)
|
||||
end
|
||||
|
||||
def update_slackbuild_version(package_path, version)
|
||||
sh './bin/slackbuilder', 'slackbuild', package_path, version
|
||||
end
|
||||
|
||||
def commit(package_path, version)
|
||||
sh './bin/slackbuilder', 'commit', package_path, version
|
||||
end
|
102
lib/package.rb
102
lib/package.rb
@ -1,102 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Package
|
||||
attr_reader :path, :version, :homepage, :requires
|
||||
|
||||
def initialize(path, version:, homepage:, requires: [])
|
||||
@path = path
|
||||
@version = version
|
||||
@homepage = homepage
|
||||
@requires = requires
|
||||
end
|
||||
|
||||
def name
|
||||
File.basename @path
|
||||
end
|
||||
|
||||
def name_version
|
||||
"#{name}-#{@version}"
|
||||
end
|
||||
|
||||
def self.parse(path, info_contents)
|
||||
current_line = String.new ''
|
||||
variables = {}
|
||||
|
||||
info_contents.each_line(chomp: true) do |file_line|
|
||||
current_line << file_line.delete_suffix('\\')
|
||||
next if file_line.end_with? '\\'
|
||||
|
||||
variables.store(*parse_pair(current_line))
|
||||
current_line.clear
|
||||
end
|
||||
from_hash path, variables
|
||||
end
|
||||
|
||||
private_class_method def self.parse_pair(current_line)
|
||||
variable_name, variable_value = current_line.split '='
|
||||
[variable_name, variable_value[1...-1].split]
|
||||
end
|
||||
|
||||
private_class_method def self.from_hash(path, variables)
|
||||
Package.new path,
|
||||
version: variables['VERSION'].join,
|
||||
homepage: variables['HOMEPAGE'].join,
|
||||
requires: variables['REQUIRES']
|
||||
end
|
||||
end
|
||||
|
||||
class Download
|
||||
attr_reader :download, :md5sum
|
||||
|
||||
def initialize(download, md5sum, is64: false)
|
||||
@download = download
|
||||
@md5sum = md5sum
|
||||
@is64 = is64
|
||||
end
|
||||
|
||||
def is64?
|
||||
@is64
|
||||
end
|
||||
end
|
||||
|
||||
def info_template(package, downloads)
|
||||
downloads64, downloads32 = downloads.partition(&:is64?)
|
||||
download32, md5sum32, download64, md5sum64 = download_entries downloads64, downloads32
|
||||
|
||||
<<~INFO_FILE
|
||||
PRGNAM="#{package.name}"
|
||||
VERSION="#{package.version}"
|
||||
HOMEPAGE="#{package.homepage}"
|
||||
DOWNLOAD="#{download32}"
|
||||
MD5SUM="#{md5sum32}"
|
||||
DOWNLOAD_x86_64="#{download64}"
|
||||
MD5SUM_x86_64="#{md5sum64}"
|
||||
REQUIRES="#{requires_entry package.requires}"
|
||||
MAINTAINER="Eugene Wissner"
|
||||
EMAIL="belka@caraus.de"
|
||||
INFO_FILE
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def requires_entry(requires)
|
||||
requires * ' '
|
||||
end
|
||||
|
||||
def download_entries(downloads64, downloads32)
|
||||
download32 =
|
||||
if downloads32.empty? && !downloads64.empty?
|
||||
'UNSUPPORTED'
|
||||
else
|
||||
downloads32.map(&:download) * " \\\n "
|
||||
end
|
||||
md5sum32 = downloads32.map(&:md5sum) * " \\\n "
|
||||
download64 = downloads64.map(&:download) * " \\\n "
|
||||
md5sum64 = downloads64.map(&:md5sum) * " \\\n "
|
||||
|
||||
[download32, md5sum32, download64, md5sum64]
|
||||
end
|
@ -1,87 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'net/http'
|
||||
require 'json'
|
||||
require_relative '../config/config'
|
||||
require 'term/ansicolor'
|
||||
|
||||
module SlackBuilder
|
||||
extend Term::ANSIColor
|
||||
|
||||
# Remote repository for a single package.
|
||||
class Repository
|
||||
# Request the latest tag in the given repository.
|
||||
def latest
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
# Reads the list fo tags from the GitHub API.
|
||||
class GitHub < Repository
|
||||
def initialize(owner, name, version_transform = nil)
|
||||
super()
|
||||
|
||||
@owner = owner
|
||||
@name = name
|
||||
@version_transform = version_transform
|
||||
end
|
||||
|
||||
def latest
|
||||
`./bin/slackbuilder github #{@owner} #{@name} #{@version_transform}`.strip
|
||||
end
|
||||
end
|
||||
|
||||
# Request the latest version from the packagist API.
|
||||
class Packagist < Repository
|
||||
def initialize(vendor, name)
|
||||
super()
|
||||
|
||||
@vendor = vendor
|
||||
@name = name
|
||||
end
|
||||
|
||||
def latest
|
||||
`./bin/slackbuilder packagist #{@vendor} #{@name}`.strip
|
||||
end
|
||||
end
|
||||
|
||||
# Reads a remote LATEST file.
|
||||
class LatestText < Repository
|
||||
def initialize(latest_url)
|
||||
super()
|
||||
|
||||
@latest_url = latest_url
|
||||
end
|
||||
|
||||
def latest
|
||||
`./bin/slackbuilder text #{@latest_url}`.strip
|
||||
end
|
||||
end
|
||||
|
||||
module_function
|
||||
|
||||
# Checks if there is a new version for the package and returns the latest
|
||||
# version if an update is available, otherwise returns nil.
|
||||
def check_for_latest(package_name, repository)
|
||||
package = find_package_info package_name
|
||||
latest_version = repository.latest
|
||||
|
||||
if package.version == latest_version
|
||||
puts green "#{package_name} is up to date (Version #{package.version})."
|
||||
nil
|
||||
else
|
||||
puts red "#{package_name}: Current version is #{package.version}, #{latest_version} is available."
|
||||
latest_version
|
||||
end
|
||||
end
|
||||
|
||||
private_class_method def find_package_info(package_name)
|
||||
package_path = Pathname.new Dir.glob("#{CONFIG[:repository]}/*/#{package_name}").first
|
||||
package_category = package_path.dirname.basename.to_s
|
||||
Package.parse("#{package_category}/#{package_name}", File.read("#{package_path}/#{package_name}.info"))
|
||||
end
|
||||
end
|
@ -1,4 +0,0 @@
|
||||
PackageKit is a DBUS abstraction layer that allows the session user to manage
|
||||
packages in a secure way using a cross-distro, cross-architecture API.
|
||||
|
||||
The script requires bash-completion from extra.
|
@ -1,11 +0,0 @@
|
||||
--- a/meson.build 2022-12-01 19:47:48.000000000 +0100
|
||||
+++ b/meson.build 2022-12-05 13:10:39.303777801 +0100
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
elogind = []
|
||||
if get_option('elogind')
|
||||
- elogind = dependency('elogind', version: '>=229.4')
|
||||
+ elogind = dependency('libelogind', version: '>=229.4')
|
||||
add_project_arguments ('-DHAVE_SYSTEMD_SD_LOGIN_H=1', language: 'c')
|
||||
endif
|
||||
|
@ -1,120 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Slackware build script for packagekit
|
||||
#
|
||||
# Copyright 2022 Eugene Wissner, Germany, Dachau
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use of this script, with or without modification, is
|
||||
# permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of this script must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
cd $(dirname $0) ; CWD=$(pwd)
|
||||
|
||||
PRGNAM=packagekit
|
||||
VERSION=${VERSION:-1.2.6}
|
||||
BUILD=${BUILD:-1}
|
||||
TAG=${TAG:-_SBo}
|
||||
PKGTYPE=${PKGTYPE:-tgz}
|
||||
|
||||
SRCNAM=PackageKit
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
case "$( uname -m )" in
|
||||
i?86) ARCH=i586 ;;
|
||||
arm*) ARCH=arm ;;
|
||||
*) ARCH=$( uname -m ) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# If the variable PRINT_PACKAGE_NAME is set, then this script will report what
|
||||
# the name of the created package would be, and then exit. This information
|
||||
# could be useful to other scripts.
|
||||
if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
|
||||
echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TMP=${TMP:-/tmp}
|
||||
PKG=$TMP/package-$PRGNAM
|
||||
OUTPUT=${OUTPUT:-/tmp}
|
||||
|
||||
if [ "$ARCH" = "i586" ]; then
|
||||
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
|
||||
LIBDIRSUFFIX=""
|
||||
elif [ "$ARCH" = "i686" ]; then
|
||||
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
|
||||
LIBDIRSUFFIX=""
|
||||
elif [ "$ARCH" = "x86_64" ]; then
|
||||
SLKCFLAGS="-O2 -fPIC"
|
||||
LIBDIRSUFFIX="64"
|
||||
else
|
||||
SLKCFLAGS="-O2"
|
||||
LIBDIRSUFFIX=""
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
rm -rf $PKG
|
||||
mkdir -p $TMP $PKG $OUTPUT
|
||||
cd $TMP
|
||||
rm -rf $SRCNAM-$VERSION
|
||||
tar xvf $CWD/$SRCNAM-$VERSION.tar.xz
|
||||
cd $SRCNAM-$VERSION
|
||||
chown -R root:root .
|
||||
find -L . \
|
||||
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
|
||||
-o -perm 511 \) -exec chmod 755 {} \; -o \
|
||||
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
|
||||
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
|
||||
|
||||
patch -p1 --verbose -i $CWD/meson_elogind.patch
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
CFLAGS="$SLKCFLAGS" \
|
||||
CXXFLAGS="$SLKCFLAGS" \
|
||||
meson .. \
|
||||
--buildtype=release \
|
||||
--infodir=/usr/info \
|
||||
--libdir=/usr/lib${LIBDIRSUFFIX} \
|
||||
--localstatedir=/var \
|
||||
--prefix=/usr \
|
||||
--sysconfdir=/etc \
|
||||
-Dstrip=true \
|
||||
-Dsystemd=false \
|
||||
-Doffline_update=false \
|
||||
-Delogind=true \
|
||||
-Dpackaging_backend=slack
|
||||
"${NINJA:=ninja}"
|
||||
DESTDIR=$PKG $NINJA install
|
||||
cd ..
|
||||
|
||||
mv $PKG/usr/share/man $PKG/usr/man
|
||||
find $PKG/usr/man -type f -exec gzip -9 {} \;
|
||||
for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
|
||||
|
||||
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
|
||||
cp -a \
|
||||
AUTHORS COPYING HACKING MAINTAINERS NEWS README RELEASE \
|
||||
$PKG/usr/doc/$PRGNAM-$VERSION
|
||||
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
|
||||
|
||||
mkdir -p $PKG/install
|
||||
cat $CWD/slack-desc > $PKG/install/slack-desc
|
||||
|
||||
cd $PKG
|
||||
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
|
@ -1,11 +0,0 @@
|
||||
PRGNAM="packagekit"
|
||||
VERSION="1.2.6"
|
||||
HOMEPAGE="https://www.freedesktop.org/software/PackageKit/"
|
||||
DOWNLOAD="https://www.freedesktop.org/software/PackageKit/releases/PackageKit-1.2.6.tar.xz"
|
||||
MD5SUM="71f855b4ac809b642ec911ce12dd8010"
|
||||
DOWNLOAD_x86_64=""
|
||||
MD5SUM_x86_64=""
|
||||
REQUIRES=""
|
||||
MAINTAINER="Eugene Wissner"
|
||||
EMAIL="belka@caraus.de"
|
||||
PackageKit-1.2.6.tar.xz
|
@ -1,19 +0,0 @@
|
||||
# HOW TO EDIT THIS FILE:
|
||||
# The "handy ruler" below makes it easier to edit a package description. Line
|
||||
# up the first '|' above the ':' following the base package name, and the '|'
|
||||
# on the right side marks the last column you can put a character in. You must
|
||||
# make exactly 11 lines for the formatting to be correct. It's also
|
||||
# customary to leave one space after the ':'.
|
||||
|
||||
|-----handy-ruler------------------------------------------------------|
|
||||
packagekit: PackageKit (A DBUS packaging abstraction layer)
|
||||
packagekit:
|
||||
packagekit: PackageKit is a DBUS abstraction layer that allows the session user to
|
||||
packagekit: packages in a secure way using a cross-distro, cross-architecture API.
|
||||
packagekit:
|
||||
packagekit: Homepage: https://www.freedesktop.org/software/PackageKit/
|
||||
packagekit:
|
||||
packagekit:
|
||||
packagekit:
|
||||
packagekit:
|
||||
packagekit:
|
@ -1,85 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rake'
|
||||
require_relative '../lib/download'
|
||||
|
||||
module SlackBuilder
|
||||
module DmdTools
|
||||
extend Rake::FileUtilsExt
|
||||
|
||||
def self.update_dmd(version)
|
||||
tarball_name = "dmd.#{version}.linux.tar.xz"
|
||||
|
||||
uri = URI "http://downloads.dlang.org/releases/2.x/#{version}/#{tarball_name}"
|
||||
checksum = SlackBuilder.download(uri, "slackbuilds/development/dmd/#{tarball_name}")
|
||||
|
||||
package = Package.new 'development/dmd', version: version,
|
||||
homepage: 'https://dlang.org'
|
||||
|
||||
write_info package, downloads: [Download.new(uri.to_s, checksum)]
|
||||
|
||||
update_slackbuild_version 'development/dmd', package.version
|
||||
commit 'development/dmd', version
|
||||
end
|
||||
|
||||
def self.update_tools(version, dub_version, dscanner_version, dcd_version)
|
||||
checksum = collect_checksums(version, dub_version, dscanner_version, dcd_version)
|
||||
|
||||
package = Package.new 'development/d-tools',
|
||||
version: version,
|
||||
homepage: 'https://dlang.org',
|
||||
requires: ['dmd']
|
||||
|
||||
write_tools_info package, dub_version, dscanner_version, dcd_version, checksum
|
||||
update_tools_versions dub_version, dscanner_version, dcd_version
|
||||
|
||||
update_slackbuild_version 'development/d-tools', package.version
|
||||
commit 'development/d-tools', package.version
|
||||
end
|
||||
|
||||
private_class_method def self.write_tools_info(package, dub_version, dscanner_version, dcd_version, checksum)
|
||||
write_info package,
|
||||
downloads: [
|
||||
Download.new(SlackBuilder.hosted_sources("/d-tools/dub-#{dub_version}.tar.gz"), checksum[:dub]),
|
||||
Download.new(SlackBuilder.hosted_sources("/d-tools/tools-#{package.version}.tar.gz"), checksum[:tools]),
|
||||
Download.new(
|
||||
SlackBuilder.hosted_sources("/d-tools/D-Scanner-#{dscanner_version}.tar.xz"), checksum[:dscanner]
|
||||
),
|
||||
Download.new(SlackBuilder.hosted_sources("/d-tools/DCD-#{dcd_version}.tar.xz"), checksum[:dcd])
|
||||
]
|
||||
end
|
||||
|
||||
private_class_method def self.collect_checksums(version, dub_version, dscanner_version, dcd_version)
|
||||
checksum = {}
|
||||
|
||||
uri = URI "https://codeload.github.com/dlang/tools/tar.gz/v#{version}"
|
||||
checksum[:tools] = SlackBuilder.download_and_deploy uri, "development/d-tools/tools-#{version}.tar.gz"
|
||||
|
||||
uri = URI "https://codeload.github.com/dlang/dub/tar.gz/v#{dub_version}"
|
||||
checksum[:dub] = SlackBuilder.download_and_deploy uri, "development/d-tools/dub-#{dub_version}.tar.gz"
|
||||
|
||||
checksum[:dscanner] = SlackBuilder.clone 'https://github.com/dlang-community/D-Scanner.git',
|
||||
"development/d-tools/D-Scanner-#{dscanner_version}.tar.xz"
|
||||
checksum[:dcd] = SlackBuilder.clone 'https://github.com/dlang-community/DCD.git',
|
||||
"development/d-tools/DCD-#{dcd_version}.tar.xz"
|
||||
|
||||
checksum
|
||||
end
|
||||
|
||||
private_class_method def self.update_tools_versions(dub_version, dscanner_version, dcd_version)
|
||||
slackbuild_filename = 'slackbuilds/development/d-tools/d-tools.SlackBuild'
|
||||
slackbuild_contents = File.read(slackbuild_filename)
|
||||
.gsub(/^DUB_VERSION=\${DUB_VERSION:-.+/,
|
||||
"DUB_VERSION=${DUB_VERSION:-#{dub_version}}")
|
||||
.gsub(/^DSCANNER_VERSION=\${DSCANNER_VERSION:-.+/,
|
||||
"DSCANNER_VERSION=${DSCANNER_VERSION:-#{dscanner_version}}")
|
||||
.gsub(/^DCD_VERSION=\${DCD_VERSION:-.+/,
|
||||
"DCD_VERSION=${DCD_VERSION:-#{dcd_version}}")
|
||||
File.open(slackbuild_filename, 'w') { |file| file.puts slackbuild_contents }
|
||||
end
|
||||
end
|
||||
end
|
@ -1,104 +0,0 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'pathname'
|
||||
|
||||
namespace :hhvm do
|
||||
def filter_set_hhvm_third_party_source_args(tokens)
|
||||
args = tokens[0]
|
||||
allowed_arguments = tokens[1..].each_slice(2)
|
||||
.filter do |key, _value|
|
||||
!key.end_with?('_URL') && !key.end_with?('_HASH')
|
||||
end
|
||||
|
||||
allowed_arguments
|
||||
.flatten
|
||||
.prepend(" #{args}")
|
||||
.join("\n ")
|
||||
end
|
||||
|
||||
def split_set_hhvm_third_party_source_args(section_content)
|
||||
section_content
|
||||
.split("\n")
|
||||
.map do |line|
|
||||
hash_index = line.index '#'
|
||||
line = line[...hash_index] unless hash_index.nil?
|
||||
|
||||
line.strip
|
||||
end
|
||||
end
|
||||
|
||||
def rewrite_set_hhvm_third_party_source_args(contents)
|
||||
set_hhvm_start = contents.index 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS('
|
||||
return nil if set_hhvm_start.nil?
|
||||
|
||||
section_contents = contents[set_hhvm_start + 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS('.length..]
|
||||
set_hhvm_end = section_contents.index ')'
|
||||
|
||||
lines = split_set_hhvm_third_party_source_args section_contents[...set_hhvm_end]
|
||||
new_cmake_section = filter_set_hhvm_third_party_source_args lines.reject(&:blank?).join(' ').split
|
||||
|
||||
contents[...set_hhvm_start] +
|
||||
"SET_HHVM_THIRD_PARTY_SOURCE_ARGS(\n#{new_cmake_section}\n)\n" +
|
||||
section_contents[set_hhvm_end..]
|
||||
end
|
||||
|
||||
desc 'Generates diffs with removed download URLs'
|
||||
task :bundled_dependencies, [:version] do |_, arguments|
|
||||
run_on_source arguments[:version] do |third_party|
|
||||
c_make_lists = third_party + 'CMakeLists.txt'
|
||||
next unless c_make_lists.exist?
|
||||
|
||||
contents = c_make_lists.read
|
||||
rewritten_cmake = rewrite_set_hhvm_third_party_source_args contents
|
||||
next if rewritten_cmake.nil?
|
||||
|
||||
puts Open3.capture2('diff', '-Nur', c_make_lists.to_path, '-', stdin_data: rewritten_cmake).first
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Generated SlackBuild code to prepare bundled dependencies'
|
||||
task :bundled_code, [:version] do |_, arguments|
|
||||
run_on_source arguments[:version] do |third_party|
|
||||
c_make_lists = third_party + 'CMakeLists.txt'
|
||||
next unless c_make_lists.exist?
|
||||
|
||||
contents = c_make_lists.read
|
||||
set_hhvm_start = contents.index 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS('
|
||||
next if set_hhvm_start.nil?
|
||||
|
||||
set_hhvm_end = contents.index ')', set_hhvm_start
|
||||
set_hhvm_start += 'SET_HHVM_THIRD_PARTY_SOURCE_ARGS('.length
|
||||
set_hhvm_end -= 1
|
||||
contents = contents[set_hhvm_start..set_hhvm_end].split[1..].map(&:strip)
|
||||
|
||||
src = Pathname.new('third-party') +
|
||||
third_party.basename +
|
||||
"bundled_#{third_party.basename}-prefix" + 'src'
|
||||
bundled = src + "bundled_#{third_party.basename}"
|
||||
archive_name = contents[1][contents[1].rindex('/') + 1..-2]
|
||||
|
||||
puts "mkdir -p #{bundled}"
|
||||
puts "install -m 0644 -D $CWD/#{archive_name} #{src + archive_name}"
|
||||
puts "tar -zxvf $CWD/#{archive_name} -C #{bundled}"
|
||||
puts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_on_source(version, &block)
|
||||
package = Package.new 'development/hhvm',
|
||||
version: version,
|
||||
homepage: 'https://hhvm.com/',
|
||||
requires: %w[tbb glog libdwarf libmemcached dobule-conversion]
|
||||
repository = SlackBuilder.clone 'https://github.com/facebook/hhvm.git', package, 'HHVM-'
|
||||
|
||||
(repository + 'third-party').each_child do |third_party|
|
||||
block.call third_party
|
||||
end
|
||||
end
|
@ -1,52 +1,76 @@
|
||||
cabal-version: 2.4
|
||||
name: slackbuilder
|
||||
version: 1.0.0
|
||||
version: 1.0
|
||||
|
||||
synopsis: Slackware build scripts and configuration files.
|
||||
synopsis: Tool to automatically update Slackware build scripts.
|
||||
bug-reports: https://git.caraus.tech/OSS/slackbuilder/issues
|
||||
|
||||
license: MPL-2.0
|
||||
license-files: LICENSE
|
||||
copyright: (c) 2023 Eugen Wissner
|
||||
copyright: (c) 2023-2025 Eugen Wissner
|
||||
|
||||
author: Eugen Wissner
|
||||
maintainer: belka@caraus.de
|
||||
|
||||
category: Build
|
||||
extra-source-files: CHANGELOG.md
|
||||
extra-source-files:
|
||||
CHANGELOG.md
|
||||
README.md
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://git.caraus.tech/OSS/slackbuilder.git
|
||||
|
||||
common dependencies
|
||||
build-depends:
|
||||
base ^>= 4.16.4.0,
|
||||
cryptonite >= 0.30,
|
||||
filepath ^>= 1.4.2,
|
||||
aeson ^>= 2.2.0,
|
||||
base >= 4.16 && < 5,
|
||||
bytestring ^>= 0.12.0,
|
||||
conduit ^>= 1.3.5,
|
||||
conduit-extra ^>= 1.3,
|
||||
http-client ^>= 0.7,
|
||||
http-client-tls ^>= 0.3,
|
||||
containers ^>= 0.7,
|
||||
crypton ^>= 1.0,
|
||||
directory ^>= 1.3.8,
|
||||
exceptions >= 0.10,
|
||||
filepath ^>= 1.5,
|
||||
http-types ^>= 0.12.4,
|
||||
megaparsec ^>= 9.7,
|
||||
modern-uri ^>= 0.3.6,
|
||||
text ^>= 2.0
|
||||
default-language: Haskell2010
|
||||
memory ^>= 0.18,
|
||||
parser-combinators ^>= 1.3,
|
||||
process ^>= 1.6.18,
|
||||
req ^>= 3.13,
|
||||
tar-conduit ^>= 0.4,
|
||||
lzma ^>= 0.0.1,
|
||||
text ^>= 2.1,
|
||||
tomland ^>= 1.3.3,
|
||||
transformers ^>= 0.6.1,
|
||||
unordered-containers ^>= 0.2.20,
|
||||
vector ^>= 0.13.0,
|
||||
word8 ^>= 0.1.3
|
||||
default-language: GHC2024
|
||||
default-extensions:
|
||||
DataKinds
|
||||
DuplicateRecordFields
|
||||
LambdaCase
|
||||
NamedFieldPuns
|
||||
OverloadedStrings
|
||||
RecordWildCards
|
||||
QuasiQuotes
|
||||
TemplateHaskell
|
||||
TypeApplications
|
||||
|
||||
library slackbuilder-internal
|
||||
library
|
||||
import: dependencies
|
||||
exposed-modules:
|
||||
SlackBuilder.Config
|
||||
SlackBuilder.Download
|
||||
SlackBuilder.Info
|
||||
SlackBuilder.LatestVersionCheck
|
||||
SlackBuilder.Package
|
||||
SlackBuilder.Trans
|
||||
hs-source-dirs: lib
|
||||
build-depends:
|
||||
exceptions >= 0.10,
|
||||
tomland ^>= 1.3.3,
|
||||
transformers ^>= 0.5.6
|
||||
|
||||
ghc-options: -Wall
|
||||
build-depends:
|
||||
mono-traversable ^>= 1.0.17
|
||||
|
||||
executable slackbuilder
|
||||
import: dependencies
|
||||
@ -54,19 +78,12 @@ executable slackbuilder
|
||||
|
||||
other-modules:
|
||||
SlackBuilder.CommandLine
|
||||
SlackBuilder.Download
|
||||
SlackBuilder.Updater
|
||||
SlackBuilder.Update
|
||||
build-depends:
|
||||
aeson ^>= 2.2.0,
|
||||
bytestring ^>= 0.11.0,
|
||||
conduit ^>= 1.3.5,
|
||||
http-client ^>= 0.7,
|
||||
ansi-terminal ^>= 1.1,
|
||||
optparse-applicative ^>= 0.18.1,
|
||||
process ^>= 1.6.17,
|
||||
req ^>= 3.13,
|
||||
unordered-containers ^>= 0.2.19,
|
||||
vector ^>= 0.13.0
|
||||
hs-source-dirs: app
|
||||
slackbuilder
|
||||
hs-source-dirs: src
|
||||
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||
|
||||
@ -76,10 +93,15 @@ test-suite slackbuilder-test
|
||||
main-is: Spec.hs
|
||||
|
||||
other-modules:
|
||||
SlackBuilder.InfoSpec
|
||||
SlackBuilder.LatestVersionCheckSpec
|
||||
SlackBuilder.PackageSpec
|
||||
hs-source-dirs: tests
|
||||
build-depends:
|
||||
hspec >= 2.10.9 && < 2.12,
|
||||
slackbuilder-internal
|
||||
hspec-megaparsec ^>= 2.2,
|
||||
slackbuilder
|
||||
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||
build-tool-depends:
|
||||
hspec-discover:hspec-discover
|
||||
|
118
src/Main.hs
Normal file
118
src/Main.hs
Normal file
@ -0,0 +1,118 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
module Main
|
||||
( main
|
||||
) where
|
||||
|
||||
import Control.Monad.Catch (MonadThrow(..))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import qualified Data.Map as Map
|
||||
import Options.Applicative (execParser)
|
||||
import SlackBuilder.CommandLine
|
||||
import SlackBuilder.Config
|
||||
import SlackBuilder.Trans
|
||||
import SlackBuilder.LatestVersionCheck
|
||||
import SlackBuilder.Update
|
||||
import qualified Toml
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text.IO as Text
|
||||
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
||||
import SlackBuilder.Package (PackageDescription(..), renderTextWithVersion)
|
||||
import qualified SlackBuilder.Package as Package
|
||||
import Data.Foldable (find, traverse_)
|
||||
import GHC.Records (HasField(..))
|
||||
import System.Console.ANSI
|
||||
( setSGR
|
||||
, SGR(..)
|
||||
, ColorIntensity(..)
|
||||
, Color(..)
|
||||
, ConsoleLayer(..)
|
||||
)
|
||||
import Data.Maybe (mapMaybe)
|
||||
import qualified Text.URI as URI
|
||||
|
||||
autoUpdatable :: [PackageSettings] -> [PackageDescription]
|
||||
autoUpdatable = mapMaybe go
|
||||
where
|
||||
go PackageSettings{ downloader = setting, downloaders } = do
|
||||
latest' <- packageUpdaterFromSettings setting
|
||||
pure $ PackageDescription
|
||||
{ latest = latest'
|
||||
, name = getField @"name" setting
|
||||
, downloaders = Map.fromList $ mapMaybe forDownloader downloaders
|
||||
}
|
||||
forDownloader downloaderSettings@DownloaderSettings{ name } =
|
||||
(name,) <$> packageUpdaterFromSettings downloaderSettings
|
||||
|
||||
packageUpdaterFromSettings :: DownloaderSettings -> Maybe Package.Updater
|
||||
packageUpdaterFromSettings DownloaderSettings{..} = do
|
||||
getVersion' <- getVersionSettings
|
||||
detectLatest' <- detectLatestSettings
|
||||
Just Package.Updater
|
||||
{ detectLatest = detectLatest'
|
||||
, getVersion = getVersion'
|
||||
, is64 = is64
|
||||
}
|
||||
where
|
||||
detectLatestSettings
|
||||
| Just githubSettings <- github =
|
||||
let ghArguments = uncurry PackageOwner githubSettings
|
||||
in Just $ latestGitHub ghArguments version
|
||||
| Just packagistSettings <- packagist =
|
||||
let packagistArguments = uncurry PackageOwner packagistSettings
|
||||
in Just $ latestPackagist packagistArguments
|
||||
| Just textSettings <- text =
|
||||
let textArguments = uncurry TextArguments textSettings
|
||||
in Just $ latestText textArguments version
|
||||
| otherwise = Nothing
|
||||
getVersionSettings
|
||||
| Just template' <- template =
|
||||
Just $ repackageWithTemplate repackage $ Package.DownloadTemplate template'
|
||||
| Just CloneSettings{..} <- clone
|
||||
= flip cloneFromGit (renderTextWithVersion tagTemplate version)
|
||||
<$> URI.mkURI remote
|
||||
| otherwise = Nothing
|
||||
|
||||
up2Date :: Maybe Text -> SlackBuilderT ()
|
||||
up2Date selectedPackage = do
|
||||
packages' <- SlackBuilderT $ asks (getField @"packages")
|
||||
case selectedPackage of
|
||||
Nothing -> traverse_ (handleExceptions . go) $ autoUpdatable packages'
|
||||
Just packageName
|
||||
| Just foundPackage <- find ((packageName ==) . getField @"name") (autoUpdatable packages') ->
|
||||
go foundPackage
|
||||
| otherwise -> throwM $ UpdaterNotFound packageName
|
||||
where
|
||||
go package = getAndLogLatest package
|
||||
>>= mapM_ updatePackageIfRequired
|
||||
>> liftIO (putStrLn "")
|
||||
|
||||
check :: SlackBuilderT ()
|
||||
check = SlackBuilderT (asks (getField @"packages"))
|
||||
>>= traverse_ (handleExceptions . go) . autoUpdatable
|
||||
where
|
||||
go package = getAndLogLatest package
|
||||
>>= mapM_ checkUpdateAvailability
|
||||
>> liftIO (putStrLn "")
|
||||
|
||||
main :: IO ()
|
||||
main = execParser slackBuilderParser
|
||||
>>= handleExceptions . withCommandLine
|
||||
where
|
||||
withCommandLine programCommand = do
|
||||
settingsResult <- Toml.decodeFileEither settingsCodec configurationFile
|
||||
case settingsResult of
|
||||
Right settings -> flip runReaderT settings
|
||||
$ runSlackBuilderT
|
||||
$ executeCommand programCommand
|
||||
Left settingsErrors
|
||||
-> setSGR [SetColor Foreground Dull Red]
|
||||
>> putStrLn (configurationFile <> " parsing failed.")
|
||||
>> setSGR [Reset]
|
||||
>> Text.putStr (Toml.prettyTomlDecodeErrors settingsErrors)
|
||||
configurationFile = "config/config.toml"
|
||||
executeCommand = \case
|
||||
CheckCommand -> check
|
||||
Up2DateCommand packageName -> up2Date packageName
|
43
src/SlackBuilder/CommandLine.hs
Normal file
43
src/SlackBuilder/CommandLine.hs
Normal file
@ -0,0 +1,43 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
-- | Command line parser.
|
||||
module SlackBuilder.CommandLine
|
||||
( SlackBuilderCommand(..)
|
||||
, slackBuilderParser
|
||||
) where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Options.Applicative
|
||||
( Parser
|
||||
, ParserInfo(..)
|
||||
, metavar
|
||||
, argument
|
||||
, helper
|
||||
, str
|
||||
, info
|
||||
, fullDesc
|
||||
, subparser
|
||||
, command
|
||||
, optional, progDesc
|
||||
)
|
||||
|
||||
data SlackBuilderCommand
|
||||
= CheckCommand
|
||||
| Up2DateCommand (Maybe Text)
|
||||
|
||||
slackBuilderParser :: ParserInfo SlackBuilderCommand
|
||||
slackBuilderParser = info (helper <*> slackBuilderCommand) fullDesc
|
||||
|
||||
slackBuilderCommand :: Parser SlackBuilderCommand
|
||||
slackBuilderCommand = subparser
|
||||
$ command "check" checkCommand
|
||||
<> command "up2date" up2DateCommand
|
||||
where
|
||||
checkCommand = info checkP $ progDesc "Check all configured slackbuilds for updates"
|
||||
checkP = pure CheckCommand
|
||||
up2DateP = Up2DateCommand
|
||||
<$> optional (argument str (metavar "PKGNAM"))
|
||||
up2DateCommand = info up2DateP
|
||||
$ progDesc "Update a single or multiple slackbuild in the configured repository"
|
333
src/SlackBuilder/Update.hs
Normal file
333
src/SlackBuilder/Update.hs
Normal file
@ -0,0 +1,333 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
module SlackBuilder.Update
|
||||
( checkUpdateAvailability
|
||||
, cloneFromGit
|
||||
, downloadWithTemplate
|
||||
, getAndLogLatest
|
||||
, handleExceptions
|
||||
, listRepository
|
||||
, repackageWithTemplate
|
||||
, reuploadWithTemplate
|
||||
, updatePackageIfRequired
|
||||
) where
|
||||
|
||||
import Control.Exception (Exception(..), SomeException(..))
|
||||
import Control.Monad.Catch (MonadCatch(..), catches, Handler(..))
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Control.Monad.Trans.Reader (asks)
|
||||
import qualified Data.ByteString.Char8 as Char8
|
||||
import Data.Foldable (Foldable(..), find)
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
import qualified Data.List.NonEmpty as NonEmpty
|
||||
import Data.Maybe (fromJust, fromMaybe)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import qualified Data.Text.IO as Text.IO
|
||||
import GHC.Records (HasField(..))
|
||||
import qualified Network.HTTP.Req as Req
|
||||
import Network.HTTP.Client (HttpException(..), HttpExceptionContent(..), responseStatus)
|
||||
import System.FilePath
|
||||
( (</>)
|
||||
, (<.>)
|
||||
, dropExtension
|
||||
, takeBaseName
|
||||
, splitFileName
|
||||
, takeDirectory
|
||||
, takeFileName
|
||||
, dropTrailingPathSeparator
|
||||
)
|
||||
import System.Process
|
||||
( CmdSpec(..)
|
||||
, CreateProcess(..)
|
||||
, StdStream(..)
|
||||
, withCreateProcess
|
||||
, waitForProcess
|
||||
)
|
||||
import SlackBuilder.Config
|
||||
import SlackBuilder.Download
|
||||
import SlackBuilder.Info
|
||||
import SlackBuilder.Package (PackageDescription(..), PackageUpdateData(..))
|
||||
import qualified SlackBuilder.Package as Package
|
||||
import SlackBuilder.Trans
|
||||
import Text.URI (URI(..))
|
||||
import qualified Text.URI as URI
|
||||
import System.Directory
|
||||
( listDirectory
|
||||
, doesDirectoryExist
|
||||
, withCurrentDirectory
|
||||
, removeDirectoryRecursive
|
||||
)
|
||||
import System.Console.ANSI
|
||||
( setSGR
|
||||
, SGR(..)
|
||||
, ColorIntensity(..)
|
||||
, Color(..)
|
||||
, ConsoleLayer(..)
|
||||
)
|
||||
import Control.Monad (filterM, void)
|
||||
import Data.List (isPrefixOf, isSuffixOf, partition)
|
||||
import Data.Functor ((<&>))
|
||||
import Data.Bifunctor (Bifunctor(..))
|
||||
import Network.HTTP.Types (Status(..))
|
||||
|
||||
getAndLogLatest :: PackageDescription -> SlackBuilderT (Maybe PackageUpdateData)
|
||||
getAndLogLatest description = do
|
||||
let PackageDescription{ latest = Package.Updater{ detectLatest }, name } = description
|
||||
liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.")
|
||||
detectedVersion <- detectLatest
|
||||
category <- HashMap.lookup name <$> listRepository
|
||||
pure $ PackageUpdateData description
|
||||
<$> category
|
||||
<*> detectedVersion
|
||||
|
||||
checkUpdateAvailability :: PackageUpdateData -> SlackBuilderT (Maybe PackageInfo)
|
||||
checkUpdateAvailability PackageUpdateData{..} = do
|
||||
parsedInfoFile <- readInfoFile category $ getField @"name" description
|
||||
|
||||
if version == getField @"version" parsedInfoFile
|
||||
then liftIO $ do
|
||||
setSGR [SetColor Foreground Dull Green]
|
||||
Text.IO.putStrLn
|
||||
$ getField @"name" description <> " is up to date (Version " <> version <> ")."
|
||||
setSGR [Reset]
|
||||
pure Nothing
|
||||
else liftIO $ do
|
||||
setSGR [SetColor Foreground Dull Yellow]
|
||||
Text.IO.putStr
|
||||
$ "A new version of "
|
||||
<> getField @"name" description
|
||||
<> " " <> getField @"version" parsedInfoFile
|
||||
<> " is available (" <> version <> ")."
|
||||
setSGR [Reset]
|
||||
putStrLn ""
|
||||
pure $ Just parsedInfoFile
|
||||
|
||||
updatePackageIfRequired :: PackageUpdateData -> SlackBuilderT ()
|
||||
updatePackageIfRequired updateData
|
||||
= checkUpdateAvailability updateData
|
||||
>>= mapM_ (updatePackage updateData)
|
||||
|
||||
data DownloadUpdated = DownloadUpdated
|
||||
{ result :: Package.Download
|
||||
, version :: Text
|
||||
, is64 :: Bool
|
||||
} deriving (Eq, Show)
|
||||
|
||||
updateDownload :: Text -> Package.Updater -> SlackBuilderT DownloadUpdated
|
||||
updateDownload packagePath Package.Updater{..} = do
|
||||
latestDownloadVersion <- fromJust <$> detectLatest
|
||||
result <- getVersion packagePath latestDownloadVersion
|
||||
pure $ DownloadUpdated
|
||||
{ result = result
|
||||
, version = latestDownloadVersion
|
||||
, is64 = is64
|
||||
}
|
||||
|
||||
cloneFromGit :: URI -> Text -> Text -> Text -> SlackBuilderT Package.Download
|
||||
cloneFromGit repo tagPrefix packagePath version = do
|
||||
let downloadFileName = URI.unRText
|
||||
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath repo
|
||||
relativeTarball = Text.unpack packagePath
|
||||
</> (dropExtension (Text.unpack downloadFileName) <> "-" <> Text.unpack version)
|
||||
(uri', checksum) <- cloneAndUpload (URI.render repo) relativeTarball tagPrefix
|
||||
pure $ Package.Download
|
||||
{ md5sum = checksum
|
||||
, download = uri'
|
||||
}
|
||||
|
||||
repackageWithTemplate :: Maybe [String] -> Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
|
||||
repackageWithTemplate Nothing template' = downloadWithTemplate template'
|
||||
repackageWithTemplate (Just (cmd : arguments)) template' =
|
||||
reuploadWithTemplate' template' (RawCommand cmd arguments)
|
||||
repackageWithTemplate (Just []) template' = reuploadWithTemplate template'
|
||||
|
||||
downloadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
|
||||
downloadWithTemplate downloadTemplate packagePath version = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||
checksum <- download uri' $ repository' </> Text.unpack packagePath
|
||||
pure $ Package.Download uri' $ snd checksum
|
||||
|
||||
reuploadWithTemplate :: Package.DownloadTemplate -> Text -> Text -> SlackBuilderT Package.Download
|
||||
reuploadWithTemplate downloadTemplate packagePath version = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||
let packagePathRelativeToCurrent = repository' </> Text.unpack packagePath
|
||||
(downloadedFileName, checksum) <- download uri' packagePathRelativeToCurrent
|
||||
|
||||
download' <- handleReupload packagePath
|
||||
$ packagePathRelativeToCurrent </> downloadedFileName
|
||||
pure $ Package.Download download' checksum
|
||||
|
||||
reuploadWithTemplate' :: Package.DownloadTemplate -> CmdSpec -> Text -> Text -> SlackBuilderT Package.Download
|
||||
reuploadWithTemplate' downloadTemplate commands packagePath version = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
uri' <- liftIO $ Package.renderDownloadWithVersion downloadTemplate version
|
||||
let downloadFileName = Text.unpack
|
||||
$ URI.unRText
|
||||
$ NonEmpty.last $ snd $ fromJust $ URI.uriPath uri'
|
||||
packagePathRelativeToCurrent = repository' </> Text.unpack packagePath
|
||||
|
||||
changedArchiveRootName <- extractRemote uri' packagePathRelativeToCurrent
|
||||
let relativeTarball = packagePathRelativeToCurrent
|
||||
</> fromMaybe downloadFileName changedArchiveRootName
|
||||
(relativeTarball', checksum) <- prepareSource relativeTarball
|
||||
|
||||
download' <- handleReupload packagePath relativeTarball'
|
||||
pure $ Package.Download download' checksum
|
||||
where
|
||||
prepareSource tarballPath =
|
||||
liftIO (defaultCreateProcess tarballPath commands)
|
||||
>> liftIO (tarCompress tarballPath)
|
||||
<* liftIO (removeDirectoryRecursive tarballPath)
|
||||
tarCompress tarballPath =
|
||||
let archiveBaseFilename = takeFileName tarballPath
|
||||
appendTarExtension = (<.> "tar.xz")
|
||||
in fmap (appendTarExtension tarballPath,)
|
||||
$ withCurrentDirectory (takeDirectory tarballPath)
|
||||
$ createLzmaTarball archiveBaseFilename (appendTarExtension archiveBaseFilename)
|
||||
defaultCreateProcess cwd' cmdSpec
|
||||
= flip withCreateProcess (const . const . const waitForProcess)
|
||||
$ CreateProcess
|
||||
{ use_process_jobs = False
|
||||
, std_out = Inherit
|
||||
, std_in = NoStream
|
||||
, std_err = Inherit
|
||||
, new_session = False
|
||||
, env = Nothing
|
||||
, detach_console = False
|
||||
, delegate_ctlc = False
|
||||
, cwd = Just cwd'
|
||||
, create_new_console = False
|
||||
, create_group = False
|
||||
, cmdspec = cmdSpec
|
||||
, close_fds = True
|
||||
, child_user = Nothing
|
||||
, child_group = Nothing
|
||||
}
|
||||
|
||||
handleReupload :: Text -> String -> SlackBuilderT URI
|
||||
handleReupload packagePath relativeTarball = do
|
||||
liftIO $ putStrLn $ "Upload the source tarball " <> relativeTarball
|
||||
uploadSource relativeTarball category'
|
||||
|
||||
hostedSources $ NonEmpty.cons category'
|
||||
$ pure $ Text.pack $ takeFileName relativeTarball
|
||||
where
|
||||
category' = Text.pack $ takeBaseName $ Text.unpack packagePath
|
||||
|
||||
updatePackage :: PackageUpdateData -> PackageInfo -> SlackBuilderT ()
|
||||
updatePackage PackageUpdateData{..} info = do
|
||||
let packagePath = category <> "/" <> getField @"name" description
|
||||
latest' = getField @"latest" description
|
||||
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
mainDownload <- (, getField @"is64" latest')
|
||||
<$> getField @"getVersion" latest' packagePath version
|
||||
moreDownloads <- traverse (updateDownload packagePath)
|
||||
$ getField @"downloaders" description
|
||||
let (downloads64, allDownloads) = partition snd
|
||||
$ mainDownload
|
||||
: (liftA2 (,) (getField @"result") (getField @"is64") <$> toList moreDownloads)
|
||||
let infoFilePath = repository' </> Text.unpack packagePath
|
||||
</> (Text.unpack (getField @"name" description) <.> "info")
|
||||
package' = info
|
||||
{ version = version
|
||||
, downloads = getField @"download" . fst <$> allDownloads
|
||||
, checksums = getField @"md5sum" . fst <$> allDownloads
|
||||
, downloadX64 = getField @"download" . fst <$> downloads64
|
||||
, checksumX64 = getField @"md5sum" . fst <$> downloads64
|
||||
}
|
||||
liftIO $ Text.IO.writeFile infoFilePath $ generate package'
|
||||
updateSlackBuildVersion packagePath version
|
||||
$ getField @"version" <$> moreDownloads
|
||||
|
||||
commit packagePath version
|
||||
|
||||
listRepository :: SlackBuilderT (HashMap Text Text)
|
||||
listRepository = do
|
||||
repository' <- SlackBuilderT $ asks repository
|
||||
listing <- go repository' [] ""
|
||||
pure $ HashMap.fromList $ bimap Text.pack Text.pack <$> listing
|
||||
where
|
||||
go currentDirectory found accumulatedDirectory = do
|
||||
let fullDirectory = currentDirectory </> accumulatedDirectory
|
||||
contents <- liftIO $ listDirectory fullDirectory
|
||||
case find (isSuffixOf ".info") contents of
|
||||
Just _ ->
|
||||
let (category, packageName) = first dropTrailingPathSeparator
|
||||
$ splitFileName accumulatedDirectory
|
||||
in pure $ (packageName, category) : found
|
||||
Nothing ->
|
||||
let accumulatedDirectories = (accumulatedDirectory </>)
|
||||
<$> filter (not . isPrefixOf ".") contents
|
||||
directoryFilter = liftIO . doesDirectoryExist
|
||||
. (currentDirectory </>)
|
||||
in filterM directoryFilter accumulatedDirectories
|
||||
>>= traverse (go currentDirectory found) <&> concat
|
||||
|
||||
handleExceptions :: (MonadIO m, MonadCatch m) => forall a. m a -> m ()
|
||||
handleExceptions action = catches (void action)
|
||||
[ Handler handleHttp
|
||||
, Handler handleSome
|
||||
]
|
||||
where
|
||||
printException e
|
||||
= liftIO (setSGR [SetColor Foreground Dull Red])
|
||||
>> liftIO (putStrLn e)
|
||||
>> liftIO (setSGR [Reset])
|
||||
showStatus (Status code message) =
|
||||
Char8.pack (show code) <> " \"" <> message <> "\""
|
||||
showHttpExceptionContent (StatusCodeException response _) = Char8.unpack
|
||||
$ "The server returned "
|
||||
<> showStatus (responseStatus response)
|
||||
<> " response status code."
|
||||
showHttpExceptionContent (TooManyRedirects _) =
|
||||
"The server responded with too many redirects for a request."
|
||||
showHttpExceptionContent OverlongHeaders = "Too many total bytes in the HTTP header were returned by the server."
|
||||
showHttpExceptionContent TooManyHeaderFields = "Too many HTTP header fields were returned by the server."
|
||||
showHttpExceptionContent ResponseTimeout = "The server took too long to return a response."
|
||||
showHttpExceptionContent ConnectionTimeout = "Attempting to connect to the server timed out"
|
||||
showHttpExceptionContent (ConnectionFailure connectionException) = displayException connectionException
|
||||
showHttpExceptionContent (InvalidStatusLine statusLine) = Char8.unpack
|
||||
$ "The status line returned by the server could not be parsed: "
|
||||
<> statusLine <> "."
|
||||
showHttpExceptionContent (InvalidHeader headerLine) = Char8.unpack
|
||||
$ "The given response header line could not be parsed: "
|
||||
<> headerLine <> "."
|
||||
showHttpExceptionContent (InvalidRequestHeader headerLine) = Char8.unpack
|
||||
$ "The given request header is not compliant: "
|
||||
<> headerLine <> "."
|
||||
showHttpExceptionContent (InternalException interalException) = displayException interalException
|
||||
showHttpExceptionContent (ProxyConnectException _ _ status) = Char8.unpack
|
||||
$ showStatus status
|
||||
<> " status code was returned when trying to connect to the proxy server on the given host and port."
|
||||
showHttpExceptionContent NoResponseDataReceived = "No response data was received from the server at all."
|
||||
showHttpExceptionContent TlsNotSupported = "This HTTP client does not have support for secure connections."
|
||||
showHttpExceptionContent (WrongRequestBodyStreamSize _ _)
|
||||
= "The request body provided did not match the expected size."
|
||||
showHttpExceptionContent (ResponseBodyTooShort _ _) =
|
||||
"The returned response body is too short. Provides the expected size and actual size."
|
||||
showHttpExceptionContent InvalidChunkHeaders = "A chunked response body had invalid headers."
|
||||
showHttpExceptionContent IncompleteHeaders = "An incomplete set of response headers were returned."
|
||||
showHttpExceptionContent (InvalidDestinationHost hostLine) = Char8.unpack
|
||||
$ "The host we tried to connect to is invalid"
|
||||
<> hostLine <> "."
|
||||
showHttpExceptionContent (HttpZlibException zlibException) = displayException zlibException
|
||||
showHttpExceptionContent (InvalidProxyEnvironmentVariable environmentName environmentValue) = Text.unpack
|
||||
$ "Values in the proxy environment variable were invalid: "
|
||||
<> environmentName <> "=\"" <> environmentValue <> "\"."
|
||||
showHttpExceptionContent ConnectionClosed = "Attempted to use a Connection which was already closed"
|
||||
showHttpExceptionContent (InvalidProxySettings _) = "Proxy settings are not valid."
|
||||
handleHttp :: (MonadIO m, MonadCatch m) => Req.HttpException -> m ()
|
||||
handleHttp (Req.VanillaHttpException e)
|
||||
| HttpExceptionRequest _ exceptionContent <- e = printException
|
||||
$ showHttpExceptionContent exceptionContent
|
||||
| InvalidUrlException url reason <- e = printException $ url <> ": " <> reason
|
||||
handleHttp (Req.JsonHttpException e) = printException e
|
||||
handleSome :: (MonadIO m, MonadCatch m) => SomeException -> m ()
|
||||
handleSome = printException . show
|
150
tests/SlackBuilder/InfoSpec.hs
Normal file
150
tests/SlackBuilder/InfoSpec.hs
Normal file
@ -0,0 +1,150 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
module SlackBuilder.InfoSpec
|
||||
( spec
|
||||
) where
|
||||
|
||||
import Crypto.Hash (Digest, MD5, digestFromByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import Data.ByteString.Char8 (ByteString)
|
||||
import Data.Maybe (maybeToList)
|
||||
import qualified Data.Text.Encoding as Text
|
||||
import Data.Void (Void)
|
||||
import SlackBuilder.Info
|
||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||
import Test.Hspec.Megaparsec (parseSatisfies, shouldSucceedOn)
|
||||
import Text.Megaparsec (parse)
|
||||
import Text.Megaparsec.Error (ParseErrorBundle)
|
||||
import Text.URI (mkURI)
|
||||
|
||||
parseInfoFile'
|
||||
:: ByteString
|
||||
-> Either (ParseErrorBundle ByteString Void) PackageInfo
|
||||
parseInfoFile' = parse parseInfoFile ""
|
||||
|
||||
infoDownload0 :: ByteString
|
||||
infoDownload0 = "PRGNAM=\"pkgnam\"\n\
|
||||
\VERSION=\"1.2.3\"\n\
|
||||
\HOMEPAGE=\"homepage\"\n\
|
||||
\DOWNLOAD=\"\"\n\
|
||||
\MD5SUM=\"\"\n\
|
||||
\DOWNLOAD_x86_64=\"\"\n\
|
||||
\MD5SUM_x86_64=\"\"\n\
|
||||
\REQUIRES=\"\"\n\
|
||||
\MAINTAINER=\"Z\"\n\
|
||||
\EMAIL=\"test@example.com\"\n"
|
||||
|
||||
infoDownload1 :: ByteString
|
||||
infoDownload1 = "PRGNAM=\"pkgnam\"\n\
|
||||
\VERSION=\"1.2.3\"\n\
|
||||
\HOMEPAGE=\"homepage\"\n\
|
||||
\DOWNLOAD=\"https://dlackware.com/download.tar.gz\"\n\
|
||||
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10\"\n\
|
||||
\DOWNLOAD_x86_64=\"\"\n\
|
||||
\MD5SUM_x86_64=\"\"\n\
|
||||
\REQUIRES=\"\"\n\
|
||||
\MAINTAINER=\"Z\"\n\
|
||||
\EMAIL=\"test@example.com\"\n"
|
||||
|
||||
maybeToDoubleList :: forall a. Maybe a -> [a]
|
||||
maybeToDoubleList xs = [y | x <- maybeToList xs, y <- [x, x]]
|
||||
|
||||
checksumSample :: [Digest MD5]
|
||||
checksumSample = maybeToList $ digestFromByteString (ByteString.pack [1 .. 16])
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "parseInfoFile" $ do
|
||||
it "returns package on a valid input" $
|
||||
parseInfoFile' `shouldSucceedOn` infoDownload1
|
||||
|
||||
it "returns an array with one element if one download is given" $
|
||||
let condition = (== 1) . length . checksums
|
||||
in parseInfoFile' infoDownload1 `parseSatisfies` condition
|
||||
|
||||
it "translates checksum characters into the binary format" $
|
||||
let expected = ["0102030405060708090a0b0c0d0e0f10"]
|
||||
condition = (== expected) . fmap show . checksums
|
||||
in parseInfoFile' infoDownload1 `parseSatisfies` condition
|
||||
|
||||
it "accepts an empty downloads list" $
|
||||
parseInfoFile' `shouldSucceedOn` infoDownload0
|
||||
|
||||
it "parses a package name with a dot" $
|
||||
let given =
|
||||
"PRGNAM=\"pkgnam.yaml\"\n\
|
||||
\VERSION=\"1.2.3\"\n\
|
||||
\HOMEPAGE=\"homepage\"\n\
|
||||
\DOWNLOAD=\"https://dlackware.com/download.tar.gz\"\n\
|
||||
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10\"\n\
|
||||
\DOWNLOAD_x86_64=\"\"\n\
|
||||
\MD5SUM_x86_64=\"\"\n\
|
||||
\REQUIRES=\"\"\n\
|
||||
\MAINTAINER=\"Z\"\n\
|
||||
\EMAIL=\"test@example.com\"\n"
|
||||
in parseInfoFile' `shouldSucceedOn` given
|
||||
|
||||
it "parses to downloads in a single line" $
|
||||
let given =
|
||||
"PRGNAM=\"pkgnam.yaml\"\n\
|
||||
\VERSION=\"1.2.3\"\n\
|
||||
\HOMEPAGE=\"homepage\"\n\
|
||||
\DOWNLOAD=\"https://dlackware.com/download1.tar.gz https://dlackware.com/download2.tar.gz\"\n\
|
||||
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10 0102030405060708090a0b0c0d0e0f11\"\n\
|
||||
\DOWNLOAD_x86_64=\"\"\n\
|
||||
\MD5SUM_x86_64=\"\"\n\
|
||||
\REQUIRES=\"\"\n\
|
||||
\MAINTAINER=\"Z\"\n\
|
||||
\EMAIL=\"test@example.com\"\n"
|
||||
in parseInfoFile' `shouldSucceedOn` given
|
||||
|
||||
it "parses downloads continuing on the next line" $
|
||||
let given =
|
||||
"PRGNAM=\"pkgnam.yaml\"\n\
|
||||
\VERSION=\"1.2.3\"\n\
|
||||
\HOMEPAGE=\"homepage\"\n\
|
||||
\DOWNLOAD=\"https://dlackware.com/download1.tar.gz \\\n\
|
||||
\ https://dlackware.com/download2.tar.gz\"\n\
|
||||
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10 \\\n\
|
||||
\ 0102030405060708090a0b0c0d0e0f11\"\n\
|
||||
\DOWNLOAD_x86_64=\"\"\n\
|
||||
\MD5SUM_x86_64=\"\"\n\
|
||||
\REQUIRES=\"\"\n\
|
||||
\MAINTAINER=\"Z\"\n\
|
||||
\EMAIL=\"test@example.com\"\n"
|
||||
in parseInfoFile' `shouldSucceedOn` given
|
||||
|
||||
describe "generate" $ do
|
||||
it "generates an .info file without downloads" $
|
||||
let given = PackageInfo "pkgnam" "1.2.3" "homepage" [] [] [] [] [] "Z" "test@example.com"
|
||||
in generate given `shouldBe` Text.decodeUtf8 infoDownload0
|
||||
|
||||
it "splits multiple downloads into multiple lines" $
|
||||
let downloads' = maybeToDoubleList
|
||||
$ mkURI "https://dlackware.com/download.tar.gz"
|
||||
checksums' = maybeToDoubleList
|
||||
$ digestFromByteString (ByteString.pack [1.. 16])
|
||||
given = PackageInfo
|
||||
"pkgnam" "1.2.3" "homepage" downloads' checksums' [] [] [] "Z" "test@example.com"
|
||||
expected = "PRGNAM=\"pkgnam\"\n\
|
||||
\VERSION=\"1.2.3\"\n\
|
||||
\HOMEPAGE=\"homepage\"\n\
|
||||
\DOWNLOAD=\"https://dlackware.com/download.tar.gz \\\n\
|
||||
\ https://dlackware.com/download.tar.gz\"\n\
|
||||
\MD5SUM=\"0102030405060708090a0b0c0d0e0f10 \\\n\
|
||||
\ 0102030405060708090a0b0c0d0e0f10\"\n\
|
||||
\DOWNLOAD_x86_64=\"\"\n\
|
||||
\MD5SUM_x86_64=\"\"\n\
|
||||
\REQUIRES=\"\"\n\
|
||||
\MAINTAINER=\"Z\"\n\
|
||||
\EMAIL=\"test@example.com\"\n"
|
||||
in generate given `shouldBe` expected
|
||||
|
||||
it "prints the checksum as a sequence of hexadecimal numbers" $
|
||||
let downloads' = maybeToList
|
||||
$ mkURI "https://dlackware.com/download.tar.gz"
|
||||
given = PackageInfo
|
||||
"pkgnam" "1.2.3" "homepage" downloads' checksumSample [] [] [] "Z" "test@example.com"
|
||||
in generate given `shouldBe` Text.decodeUtf8 infoDownload1
|
53
tests/SlackBuilder/LatestVersionCheckSpec.hs
Normal file
53
tests/SlackBuilder/LatestVersionCheckSpec.hs
Normal file
@ -0,0 +1,53 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
module SlackBuilder.LatestVersionCheckSpec
|
||||
( spec
|
||||
) where
|
||||
|
||||
import SlackBuilder.LatestVersionCheck
|
||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "match" $ do
|
||||
it "matches an exact tag prefixed with v" $
|
||||
let expected = Just "2.6.0"
|
||||
actual = match "(v)2.6.0" "v2.6.0"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "matches a glob pattern prefixed with v" $
|
||||
let expected = Just "2.6.0"
|
||||
actual = match "(v)*" "v2.6.0"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "matches digits" $
|
||||
let expected = Just "2.6.0"
|
||||
actual = match "(v)2.6.\\d" "v2.6.0"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "matches digits and dots" $
|
||||
let expected = Just "2.6.0"
|
||||
actual = match "(v)\\." "v2.6.0"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "rejects unexpected suffix" $
|
||||
let expected = Nothing
|
||||
actual = match "(v)\\." "v2.6.0-rc1"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "rejects remaining umatched characters" $
|
||||
let expected = Nothing
|
||||
actual = match "2.6.0-rc1" "2.6.0"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "consumes the last token matching nothing" $
|
||||
let expected = Just "abc"
|
||||
actual = match "abc\\d\\d" "abc"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "matches at least one digit" $
|
||||
let expected = Nothing
|
||||
actual = match "1.\\D.3" "1..3"
|
||||
in actual `shouldBe` expected
|
@ -1,8 +1,11 @@
|
||||
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||
|
||||
module SlackBuilder.PackageSpec
|
||||
( spec
|
||||
) where
|
||||
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import SlackBuilder.Package
|
||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||
import Text.URI.QQ (uri)
|
||||
@ -11,17 +14,13 @@ spec :: Spec
|
||||
spec = do
|
||||
describe "renderDownloadWithVersion" $ do
|
||||
it "renders text as URL" $
|
||||
let given = DownloadTemplate
|
||||
$ pure
|
||||
$ StaticPlaceholder "https://example.com"
|
||||
let given = DownloadTemplate "https://example.com"
|
||||
actual = renderDownloadWithVersion given "1.2"
|
||||
expected = Just [uri|https://example.com|]
|
||||
in actual `shouldBe` expected
|
||||
|
||||
it "renders the components in order" $
|
||||
let given = DownloadTemplate
|
||||
$ StaticPlaceholder "https://example.com/"
|
||||
:| [VersionPlaceholder, StaticPlaceholder "/segment"]
|
||||
let given = DownloadTemplate "https://example.com/{version}/segment"
|
||||
actual = renderDownloadWithVersion given "1.2"
|
||||
expected = Just [uri|https://example.com/1.2/segment|]
|
||||
in actual `shouldBe` expected
|
||||
|
Reference in New Issue
Block a user