mirror of
https://github.com/srid/nixos-config.git
synced 2025-12-26 15:04:59 +08:00
Add hackage-publish
This commit is contained in:
parent
a668ce0035
commit
6d5046bb5c
2 changed files with 43 additions and 58 deletions
|
|
@ -48,6 +48,7 @@ in
|
|||
fuckport
|
||||
sshuttle-via
|
||||
entr
|
||||
hackage-publish
|
||||
|
||||
# Fonts
|
||||
cascadia-code
|
||||
|
|
|
|||
|
|
@ -1,58 +1,42 @@
|
|||
{ pkgs, ... }:
|
||||
pkgs.writeShellApplication {
|
||||
name = "hackage-publish";
|
||||
runtimeInputs = [ pkgs.cat-agenix-secret ];
|
||||
meta.description = "Publish Haskell library to Hackage with encrypted password";
|
||||
text = ''
|
||||
set -e
|
||||
|
||||
# Check if we're in a Haskell project
|
||||
if [ ! -f "*.cabal" ] && [ ! -f "cabal.project" ]; then
|
||||
echo "Error: Not in a Haskell project directory (no .cabal file found)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse command line arguments
|
||||
dry_run=false
|
||||
if [ "$#" -gt 0 ] && [ "$1" = "--dry-run" ]; then
|
||||
dry_run=true
|
||||
echo "Running in dry-run mode (will print commands instead of executing)"
|
||||
fi
|
||||
|
||||
# Set cabal command based on dry-run mode
|
||||
if [ "$dry_run" = true ]; then
|
||||
cabal_cmd="echo cabal"
|
||||
else
|
||||
cabal_cmd="cabal"
|
||||
fi
|
||||
|
||||
echo "Step 2: Generating distribution tarball..."
|
||||
$cabal_cmd sdist
|
||||
|
||||
echo "Step 3: Getting Hackage password..."
|
||||
if [ "$dry_run" = true ]; then
|
||||
password="<HACKAGE_PASSWORD>"
|
||||
else
|
||||
password=$(cat-agenix-secret hackage-password.age)
|
||||
if [ -z "$password" ]; then
|
||||
echo "Error: Failed to get Hackage password" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Step 4: Uploading to Hackage..."
|
||||
read -p "Upload package to Hackage? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
$cabal_cmd upload -u sridca -P "$password" --publish
|
||||
else
|
||||
echo "Upload cancelled"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Step 5: Uploading documentation..."
|
||||
$cabal_cmd upload -d -u sridca -P "$password" --publish
|
||||
|
||||
echo "Hackage publish completed successfully!"
|
||||
'';
|
||||
}
|
||||
# Publish current package to Hackage.
|
||||
{ writers, haskellPackages, coreutils, cabal-install, _1password-cli, ... }:
|
||||
|
||||
writers.writeHaskellBin "hackage-publish"
|
||||
{
|
||||
libraries = with haskellPackages; [
|
||||
shh
|
||||
temporary
|
||||
];
|
||||
} ''
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
import Shh
|
||||
import System.IO.Temp
|
||||
import System.FilePath
|
||||
import System.Directory
|
||||
import Control.Monad
|
||||
|
||||
loadFromBins ["${cabal-install}", "${coreutils}", "${_1password-cli}"]
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
withSystemTempDirectory "hackage-publish" $ \tmpDir -> do
|
||||
putStrLn $ "Using temporary directory: " <> tmpDir
|
||||
|
||||
-- Run cabal sdist
|
||||
putStrLn "Creating source distribution..."
|
||||
cabal "sdist" "-o" tmpDir
|
||||
|
||||
-- Get password from 1password
|
||||
putStrLn "Retrieving password from 1password..."
|
||||
password <- op "read" "op://Private/Hackage/password" |> captureTrim
|
||||
|
||||
-- Find the tarball file
|
||||
files <- listDirectory tmpDir
|
||||
let tarball = Prelude.head $ filter (\f -> takeExtension f == ".gz") files
|
||||
|
||||
-- Upload to hackage
|
||||
putStrLn "Publishing to Hackage..."
|
||||
cabal "upload" "--publish" "-u" "sridca" "-p" password (tmpDir </> tarball)
|
||||
|
||||
putStrLn "Successfully published to Hackage!"
|
||||
''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue