Skip to content

Commit def6615

Browse files
feat: allow exluding paths from tarball (#70)
1 parent aaa29b5 commit def6615

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,22 @@ You can replicate this in your own org, by following the examples here.
6767
6868
Version: %{build_version}
6969
```
70+
71+
5. Optionally, add a `.copr-ci` file to the root of your repo to exclude submodules or directories from the
72+
build. This is useful for reducing the size of the source tarball when large submodules are not needed for
73+
packaging. Each non-empty, non-comment line is treated as a path relative to the repo root to exclude.
74+
75+
```
76+
# .copr-ci - paths to exclude from the copr build tarball
77+
# Lines starting with '#' are comments and are ignored.
78+
79+
# exclude an entire submodule
80+
third-party/build-deps
81+
82+
# exclude a specific subdirectory inside a submodule
83+
third-party/build-deps/third-party/FFmpeg/AMF/Thirdparty
84+
```
85+
86+
Excluded paths are:
87+
- **Not initialized** as submodules (never cloned, saving time and bandwidth).
88+
- **Excluded** from the generated source tarball passed to rpmbuild.

copr-ci.sh

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,43 @@ else
3333
git checkout "$REVISION"
3434
fi
3535

36-
# initialize the submodules
37-
git submodule update --init --recursive
36+
# read optional exclusions from .copr-ci config file
37+
# each non-empty, non-comment line is treated as a submodule path or directory
38+
# to exclude (relative to the repo root, e.g. "third-party/build-deps")
39+
EXCLUDED_PATHS=()
40+
if [[ -f ".copr-ci" ]]; then
41+
echo "Found .copr-ci config file, reading exclusions..."
42+
while IFS= read -r line || [[ -n "$line" ]]; do
43+
# skip empty lines and comments
44+
[[ -z "$line" || "$line" =~ ^# ]] && continue
45+
EXCLUDED_PATHS+=("$line")
46+
echo " Excluding: $line"
47+
done < ".copr-ci"
48+
fi
49+
50+
# initialize the submodules, skipping any excluded paths
51+
if [[ ${#EXCLUDED_PATHS[@]} -gt 0 ]]; then
52+
# get all top-level submodule paths, then init only the ones not excluded
53+
mapfile -t TOP_SUBMODULES < <(git submodule status | awk '{print $2}')
54+
55+
for submodule in "${TOP_SUBMODULES[@]}"; do
56+
skip=false
57+
for excluded in "${EXCLUDED_PATHS[@]}"; do
58+
# match exact path or any path that starts with the excluded prefix
59+
if [[ "$submodule" == "$excluded" || "$submodule" == "$excluded/"* ]]; then
60+
skip=true
61+
break
62+
fi
63+
done
64+
if [[ "$skip" == false ]]; then
65+
git submodule update --init --recursive --depth 1 -- "$submodule"
66+
else
67+
echo "Skipping submodule: $submodule"
68+
fi
69+
done
70+
else
71+
git submodule update --init --recursive --depth 1
72+
fi
3873

3974
# get the tag of this commit IF it has one
4075
TAG=$(git tag --points-at HEAD | head -n1)
@@ -74,5 +109,9 @@ sed -i "s|%global build_version 0|%global build_version ${TAG}|" "${resultdir}"/
74109
sed -i "s|%global branch 0|%global branch ${BRANCH}|" "${resultdir}"/*.spec
75110
sed -i "s|%global commit 0|%global commit ${COMMIT}|" "${resultdir}"/*.spec
76111

77-
# create a tarball of the source code
78-
tar -czf "${resultdir}/tarball.tar.gz" .
112+
# create a tarball of the source code, excluding any configured paths
113+
TAR_EXCLUDE_ARGS=()
114+
for path in "${EXCLUDED_PATHS[@]}"; do
115+
TAR_EXCLUDE_ARGS+=("--exclude=./${path}")
116+
done
117+
tar -czf "${resultdir}/tarball.tar.gz" "${TAR_EXCLUDE_ARGS[@]}" .

0 commit comments

Comments
 (0)