Skip to content

Commit

Permalink
Fix zip exclude matching
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jan 19, 2024
1 parent ba7d69b commit aa9d3b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ test.sh export-ignore
.github export-ignore
```

Use the `$GIT_ARCHIVE_OPTS` variable to pass options to the `git archive` command
or `$ZIP_OPTS` to pass options to the `zip` command.
Use the `$GIT_BUNDLE_OPTS` variable to pass options to the `git archive` command
or `$ZIP_BUNDLE_OPTS` to pass options to the `zip` command.

For example, if a Git repo contains no `META.json`, but generates it via a
`make` command, it will not be included in the zip archive, because `git
Expand All @@ -254,20 +254,23 @@ archive` to add it, like so:

```sh
make META.json
export GIT_ARCHIVE_OPTS="--add-file META.json"
export GIT_BUNDLE_OPTS="--add-file META.json"
pgxn-bundle
```

If, on the other hand, you're not using a Git repository, `pgxn-bundle` will
use the `zip` utility, instead. If there was a file to exclude from the
zip file, use the `$ZIP_OPTS` variable to pass the `--exclude` option to `zip`,
If, on the other hand, you're not using a Git repository, `pgxn-bundle` will use
the `zip` utility, instead. If there was a file to exclude from the zip file,
use the `$ZIP_BUNDLE_OPTS` variable to pass the `--exclude` option to `zip`,
something like:

``` sh
export ZIP_OPTS="--exclude .dev-only.txt"
export ZIP_BUNDLE_OPTS="--exclude */.dev-only.txt"
pgxn-bundle
```

Note the `*/` prefix, required to match a file name under the
`${PGXN_DIST_NAME}-${PGXN_DIST_VERSION}/` directory prefix.

### [`pgxn-release`]

``` sh
Expand Down
9 changes: 5 additions & 4 deletions bin/pgxn-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ VERSION=${PGXN_DIST_VERSION:-$(perl -MJSON=decode_json -E 'say decode_json(join
# Now bundle up the distribution for release.
release=${DISTNAME}-${VERSION}
if [ "true" == "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
echo "Bundling $release.zip from Git repository..."
git archive -v --format zip --prefix=${release}/ ${GIT_ARCHIVE_OPTS:-} --output ${release}.zip HEAD
echo "Bundling $release.zip with git archive..."
git archive -v --format zip --prefix=${release}/ ${GIT_BUNDLE_OPTS:-} --output ${release}.zip HEAD
else
echo "Bundling $release.zip with all files..."
echo "Bundling $release.zip with zip utility..."
mkdir /tmp/$release
cp -rf . /tmp/$release
(cd /tmp && zip -r $release.zip ${ZIP_OPTS:-} $release)
set -x
(cd /tmp && zip -r $release.zip $release ${ZIP_BUNDLE_OPTS:-})
mv /tmp/$release.zip .
fi
echo "bundle=$release.zip" >> $GITHUB_OUTPUT
22 changes: 11 additions & 11 deletions test/runtest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -eux
set -eu

pgversion=$1
expectutil=${2:-git}
Expand All @@ -13,17 +13,17 @@ extrafile=extra.txt
cd $(dirname "$0")

if [ -n "$testopts" ]; then
# Use GIT_ARCHIVE_OPTS to add an untracked file to the Git archive or
# ZIP_OPTS to exclude it.
# Use GIT_BUNDLE_OPTS to add an untracked file to the Git archive or
# ZIP_BUNDLE_OPTS to exclude it.
echo extra > "$extrafile"
export GIT_ARCHIVE_OPTS="--add-file $extrafile"
export ZIP_OPTS="--exclude $extrafile"
export GIT_BUNDLE_OPTS="--add-file $extrafile"
export ZIP_BUNDLE_OPTS="--exclude */$extrafile"
fi

pg-start $pgversion
pg-build-test
# pg-start $pgversion
# pg-build-test
pgxn-bundle
make clean
# make clean

# Make sure pgxn-bundle built the zip file.
if [ ! -f "$zipfile" ]; then
Expand All @@ -42,7 +42,7 @@ if [ "$expectutil" = "git" ]; then
echo ' Did pgxn-bundle use `zip` instead of `git archive`?'
exit 2
fi
# Make sure the untracked file was added via GIT_ARCHIVE_OPTS.
# Make sure the untracked file was added via GIT_BUNDLE_OPTS.
if [ -n "$testopts" ] && [ ! -f "$prefix/$extrafile" ]; then
echo "ERROR $prefix/$extrafile not included in archive"
exit 2
Expand All @@ -54,9 +54,9 @@ else
echo ' Did pgxn-bundle use `git archive` instead of `zip`?'
exit 2
fi
# Make sure the extra file was excluded via ZIP_OPTS.
# Make sure the extra file was excluded via ZIP_BUNDLE_OPTS.
if [ -n "$testopts" ] && [ -f "$prefix/$extrafile" ]; then
echo "ERROR $prefix/$extrafile not included in archive"
echo "ERROR $prefix/$extrafile included in archive but should not be"
exit 2
fi
fi
Expand Down

0 comments on commit aa9d3b9

Please sign in to comment.