Skip to content

Commit

Permalink
Add zip compression method (fix #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnkr committed Oct 16, 2019
1 parent 74fd48a commit 13cdcc1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LABEL "com.github.actions.color"="black"
ENV GHR_FORK tcnksm/ghr
ENV GHR_VERSION 0.12.0

RUN apk add --no-cache bash curl xz
RUN apk add --no-cache bash curl xz zip

RUN sh -c "curl --silent -L https://github.com/${GHR_FORK}/releases/download/v${GHR_VERSION}/ghr_v${GHR_VERSION}_linux_amd64.tar.gz > ghr_v${GHR_VERSION}_linux_amd64.tar.gz" && \
sh -c "tar xvzf ghr_v${GHR_VERSION}_linux_amd64.tar.gz" && \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ The action will trigger on pushes to tags and exit neutrally otherwise.

- `GHR_COMPRESS`**Optional.**
Compress files before uploading them.
Can be either `gz`, `bz2` or `xz`.
The correct file extension will be appended (e.g. `.tar.gz`).
Can be either `gz`, `bz2`, `xz`, or `zip`.
The correct file extension will be appended (e.g. `.tar.gz`, or `.zip`).

## Usage example

Expand Down
41 changes: 29 additions & 12 deletions ghr-compress
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
#!/bin/bash
#!/usr/bin/env bash
set -e -u -o pipefail
shopt -s nullglob

extension="$GHR_COMPRESS"

if [ "$extension" = "gz" ]; then
option=z
elif [ "$extension" = "bz2" ]; then
option=j
elif [ "$extension" = "xz" ]; then
option=J
if [ "$GHR_COMPRESS" = "gz" ]; then
tar_option=z
extension=".tar.gz"
elif [ "$GHR_COMPRESS" = "bz2" ]; then
tar_option=j
extension=".tar.bz2"
elif [ "$GHR_COMPRESS" = "xz" ]; then
tar_option=J
extension=".tar.xz"
elif [ "$GHR_COMPRESS" = "zip" ]; then
extension=".zip"
else
echo "ghr-compress: error: unknown extension: ${extension}" >&2
exit 1
fi

ghr-compress-one-tar() {
local file="$1"
tar c "-${tar_option}" -f "${file}${extension}" "$file"
}

ghr-compress-one-zip() {
local file="$1"
zip -r "${file}${extension}" "$file"
}

ghr-compress-one() {
local file="$1"
/bin/tar c "-${option}" -f "${file}.tar.${extension}" "$file"
/bin/rm -r -- "$file"
if [ "$GHR_COMPRESS" = "zip" ]; then
ghr-compress-one-zip "$file" >&2
else
ghr-compress-one-tar "$file"
fi
rm -r -- "$file"
}

if [ "$GHR_PATH" = "." ]; then
Expand All @@ -27,5 +44,5 @@ if [ "$GHR_PATH" = "." ]; then
done
else
ghr-compress-one "$GHR_PATH"
echo "export GHR_PATH=$(printf '%q' "${GHR_PATH}.tar.${extension}")"
echo "export GHR_PATH=$(printf '%q' "${GHR_PATH}${extension}")"
fi

0 comments on commit 13cdcc1

Please # to comment.