Skip to content

Commit

Permalink
Merge pull request #6 from shoriminimoe/fix-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
shoriminimoe authored May 22, 2024
2 parents 5c39f3e + 8af3290 commit d3e9da9
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 55 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: CI

on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
Expand All @@ -26,7 +27,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: fish-actions/install-fish@v1
# FIXME: need dependencies installed here
- uses: melusina-org/setup-macports@v1
if: matrix.os == 'macos-latest'
- name: Install dependencies
run: bash tests/install-dependencies.sh
- uses: fish-shop/run-fishtape-tests@v1
with:
pattern: tests/**.fish
Expand Down
30 changes: 19 additions & 11 deletions functions/extract.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,50 @@ function extract -d "Extract archives"
return 1
end

if command -v gtar
# use GNU tar if available. This is what gnu-tar is installed as on
# macOS.
set tar gtar
else
set tar tar
end

set failed false

for file in $argv
switch $file
case '*.tar'
tar xvf "$file"
$tar xvf "$file"

case '*.tar.gz' '*.tgz'
tar xvzf "$file"
$tar xvzf "$file"

case '*.tar.bz2' '*.tar.bz' '*.tbz' '*.tbz2'
tar xvjf "$file"
$tar xvjf "$file"

case '*.tar.xz' '*.txz'
tar xvJf "$file"
$tar xvJf "$file"

case '*.tar.Z' '*.taz'
tar xvZf "$file"
$tar xvZf "$file"

case '*.tar.zst' '*.tzst'
tar --zstd -xvf "$file"
$tar --zstd -xvf "$file"

case '*.tar.lzma' '*.tar.zma' '*.tlz'
tar --lzma -xvf "$file"
$tar --lzma -xvf "$file"

case '*.tar.lrz'
lrzuntar "$file"

case '*.tar.lz'
tar --lzip -xvf "$file"
$tar --lzip -xvf "$file"

case '*.tar.lz4'
tar --use-compress-program=lz4 -xvf "$file"
$tar --use-compress-program=lz4 -xvf "$file"

case '*.tar.lzo'
tar --lzop -xvf "$file"
$tar --lzop -xvf "$file"

case '*.7z'
7zz x "$file"
Expand All @@ -71,7 +79,7 @@ function extract -d "Extract archives"
unzip "$file"

case '*.Z'
uncompress --keep "$file"
uncompress -k "$file"

case '*.zst'
unzstd --keep "$file"
Expand Down
86 changes: 43 additions & 43 deletions tests/file-types.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cp bwah.tar.zst bwah.tzst
tar --compress -cf bwah.tar.Z bwah
cp bwah.tar.Z bwah.taz
lz4 --quiet bwah.tar bwah.tar.lz4
lrzip --very-quiet bwah.tar
lrzip --quiet bwah.tar

# 7z
7zz a bwah.7z bwah >/dev/null
Expand All @@ -41,7 +41,7 @@ gzip --keep bwah
zip --quiet bwah.jar bwah

# lrzip
lrzip --very-quiet bwah
lrzip --quiet bwah

# lz4
lz4 --quiet bwah bwah.lz4
Expand All @@ -65,49 +65,49 @@ zstd --force bwah 2>/dev/null
pigz --zlib --keep bwah

set --local test_files \
bwah.7z \
bwah.Z \
bwah.bz \
bwah.bz2 \
bwah.gz \
bwah.jar \
bwah.lrz \
bwah.lz4 \
bwah.lzma \
bwah.tar \
bwah.tar.Z \
bwah.tar.bz \
bwah.tar.bz2 \
bwah.tar.gz \
bwah.tar.lrz \
bwah.tar.lz \
bwah.tar.lz4 \
bwah.tar.lzma \
bwah.tar.lzo \
bwah.tar.xz \
bwah.tar.zma \
bwah.tar.zst \
bwah.taz \
bwah.tbz \
bwah.tbz2 \
bwah.tgz \
bwah.tlz \
bwah.txz \
bwah.tzst \
bwah.xpi \
bwah.xz \
bwah.zip \
bwah.zz \
bwah.zst
bwah.7z \
bwah.Z \
bwah.bz \
bwah.bz2 \
bwah.gz \
bwah.jar \
bwah.lrz \
bwah.lz4 \
bwah.lzma \
bwah.tar \
bwah.tar.Z \
bwah.tar.bz \
bwah.tar.bz2 \
bwah.tar.gz \
bwah.tar.lrz \
bwah.tar.lz \
bwah.tar.lz4 \
bwah.tar.lzma \
bwah.tar.lzo \
bwah.tar.xz \
bwah.tar.zma \
bwah.tar.zst \
bwah.taz \
bwah.tbz \
bwah.tbz2 \
bwah.tgz \
bwah.tlz \
bwah.txz \
bwah.tzst \
bwah.xpi \
bwah.xz \
bwah.zip \
bwah.zz \
bwah.zst

for file in $test_files
rm -f bwah
@echo === extract $file ===
@test "archive exists" -f $file
@test "extract $file" (extract $file >/dev/null) $status -eq 0
@test "archive remains" -f $file
@test "bwah is present" -f bwah
rm -f $file
rm -f bwah
@echo === extract $file ===
@test "archive exists" -f $file
@test "extract $file" (extract $file >/dev/null) $status -eq 0
@test "archive remains" -f $file
@test "bwah is present" -f bwah
rm -f $file
end

rm -f bwah
55 changes: 55 additions & 0 deletions tests/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -euo pipefail

install_linux() {
sudo apt-get update
sudo apt-get install -y \
bzip2 \
gzip \
lrzip \
lz4 \
lzip \
lzma \
lzop \
ncompress \
pigz \
tar \
wget \
xz-utils \
zip \
zstd

tmpdir=$(mktemp -d)
wget -O "$tmpdir/7zip.tar.xz" https://www.7-zip.org/a/7z2405-linux-x64.tar.xz
tar xf "$tmpdir/7zip.tar.xz" -C "$tmpdir"
sudo mv -t /usr/local/bin/ "$tmpdir/7zz"
}

install_mac() {
brew update
brew install \
bzip2 \
gzip \
lrzip \
lz4 \
lzip \
lzop \
pigz \
gnu-tar \
xz \
zip \
sevenzip \
zstd
port install \
lzma \
ncompress
}

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
install_linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
install_mac
else
echo "Unsupported OS"
exit 1
fi

0 comments on commit d3e9da9

Please sign in to comment.