Skip to content

Commit 4d3c9a2

Browse files
committed
Update build scripts and CI/CD workflows
* build: Improved build and publish process for multiple platforms * build: Added Dockerfile for containerized build environments
1 parent c8cc356 commit 4d3c9a2

File tree

18 files changed

+409
-83
lines changed

18 files changed

+409
-83
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ history.md
77
tests/.logs
88
tests/.tmp
99
.tmp
10-
dist
10+
dist
11+
.DS_Store

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"cSpell.words": [
33
"changesish",
44
"devstral",
5+
"dotenv",
56
"giv",
67
"ollama",
8+
"pypi",
79
"subcmd"
810
],
911
"[bats]": {

build/Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM ubuntu:24.04
2+
3+
# Install core utilities and dependencies
4+
RUN apt-get update && \
5+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
6+
build-essential \
7+
rpm \
8+
curl \
9+
wget \
10+
git \
11+
jq \
12+
npm \
13+
snapd \
14+
python3 \
15+
python3-pip \
16+
ruby \
17+
ruby-dev \
18+
flatpak-builder \
19+
lsb-release \
20+
ca-certificates \
21+
gnupg2 \
22+
xz-utils \
23+
sudo \
24+
locales \
25+
unzip
26+
27+
28+
# Set locale
29+
RUN locale-gen en_US.UTF-8
30+
ENV LANG=en_US.UTF-8
31+
ENV LANGUAGE=en_US:en
32+
ENV LC_ALL=en_US.UTF-8
33+
# Install snapd (for snap builds; install snaps at runtime)
34+
#RUN apt-get update && apt-get install -y --no-install-recommends snapd && rm -rf /var/lib/apt/lists/*
35+
# NOTE: To use snapcraft, start the container and run:
36+
# snap install core && snap install snapcraft --classic
37+
38+
# Install fpm (package builder for deb/rpm)
39+
RUN gem install --no-document fpm
40+
41+
# Install bats (for shell testing)
42+
RUN npm install -g bats
43+
44+
# Install Homebrew (for homebrew builds, on Linux)
45+
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || true
46+
ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH"
47+
RUN brew update || true
48+
49+
# Install GitHub CLI (gh)
50+
RUN type -p gh || (curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
51+
dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
52+
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
53+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | \
54+
tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
55+
apt-get update && apt-get install -y gh)
56+
57+
# Set workdir
58+
WORKDIR /workspace
59+
60+
# Default entrypoint and command
61+
ENTRYPOINT ["/bin/bash", "-c"]
62+
CMD ["if [ -f ./build/build.sh ]; then ./build/build.sh; else exec /bin/bash; fi"]

build/build.sh

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
#! /bin/bash
22

3+
34
mkdir -p .tmp
45
BUILD_TEMP=$(mktemp -d -p .tmp)
5-
VERSION=$(sed -n 's/^__VERSION="\([^"]*\)"/\1/p' ../giv/src/giv.sh)
6+
VERSION=$(sed -n 's/^__VERSION="\([^"]*\)"/\1/p' src/giv.sh)
67
DIST_DIR="./dist/${VERSION}"
78

89
printf "Building GIV CLI version %s...\n" "${VERSION}"
10+
rm -rf "${DIST_DIR}"
11+
mkdir -p "${DIST_DIR}"
12+
13+
FPM_INSTALLED="false"
14+
# Check for fpm, try to install if missing
15+
if ! command -v fpm >/dev/null 2>&1; then
16+
echo "Trying: gem install dotenv fpm"
17+
if gem install dotenv fpm; then
18+
echo "fpm installed via gem."
19+
fi
20+
fi
21+
22+
if ! command -v fpm >/dev/null 2>&1; then
23+
cat >&2 <<EOF
24+
Error: fpm is not installed and automatic installation failed.
25+
26+
Manual installation instructions:
27+
- See https://fpm.readthedocs.io/en/latest/installation.html
28+
- On macOS: gem install fpm
29+
- On Linux (Debian/Ubuntu): sudo apt-get install ruby ruby-dev build-essential && sudo gem install --no-document fpm
30+
- On Linux (Fedora): sudo dnf install ruby ruby-devel make gcc && sudo gem install --no-document fpm
31+
- Or see the docs for more options.
32+
EOF
33+
FPM_INSTALLED="false"
34+
else
35+
FPM_INSTALLED="true"
36+
fi
37+
938
mkdir -p "${BUILD_TEMP}/package"
1039
cp -r src templates docs "${BUILD_TEMP}/package/"
11-
cp README.md "${BUILD_TEMP}/package/"
40+
printf 'Copied src templates docs to %s\n' "${BUILD_TEMP}/package/"
41+
cp README.md "${BUILD_TEMP}/package/docs"
1242
mv "${BUILD_TEMP}/package/src/giv.sh" "${BUILD_TEMP}/package/src/giv"
1343
printf "Using build temp directory: %s\n" "${BUILD_TEMP}"
44+
45+
# Collect file lists for setup.py
46+
SH_FILES=$(find "${BUILD_TEMP}/package/src" -type f -name '*.sh' -print0 | xargs -0 -I{} bash -c 'printf "src/%s " "$(basename "{}")"')
47+
TEMPLATE_FILES=$(find "${BUILD_TEMP}/package/templates" -type f -print0 | xargs -0 -I{} bash -c 'printf "templates/%s " "$(basename "{}")"')
48+
DOCS_FILES=$(find "${BUILD_TEMP}/package/docs" -type f -print0 | xargs -0 -I{} bash -c 'printf "docs/%s " "$(basename "{}")"')
49+
50+
51+
export SH_FILES TEMPLATE_FILES DOCS_FILES
52+
1453
./build/npm/build.sh "${VERSION}" "${BUILD_TEMP}"
1554
./build/pypi/build.sh "${VERSION}" "${BUILD_TEMP}"
16-
# ./build/snap/build.sh "${VERSION}" "${BUILD_TEMP}"
17-
# ./build/linux/build.sh "${VERSION}" "${BUILD_TEMP}" "deb"
18-
# ./build/linux/build.sh "${VERSION}" "${BUILD_TEMP}" "rpm"
19-
# ./build/flatpak/build.sh "${VERSION}" "${BUILD_TEMP}"
20-
# ./build/homebrew/build.sh "${VERSION}" "${BUILD_TEMP}"
21-
#./build/scoop/build.sh "${VERSION}" "${BUILD_TEMP}"
55+
./build/homebrew/build.sh "${VERSION}" "${BUILD_TEMP}"
56+
./build/scoop/build.sh "${VERSION}" "${BUILD_TEMP}"
57+
if [ "${FPM_INSTALLED}" = "true" ]; then
58+
./build/linux/build.sh "${VERSION}" "${BUILD_TEMP}" "deb"
59+
./build/linux/build.sh "${VERSION}" "${BUILD_TEMP}" "rpm"
60+
fi
61+
./build/snap/build.sh "${VERSION}" "${BUILD_TEMP}"
62+
./build/flatpak/build.sh "${VERSION}" "${BUILD_TEMP}"
2263

2364
#rm -rf "${BUILD_TEMP}"
24-
printf "Build completed. Files are in %s\n" "${DIST_DIR}"
65+
printf "Build completed. Files are in %s\n" "${DIST_DIR}"

build/docker-build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
docker build -f build/Dockerfile -t giv:latest .
3+
docker run --rm -v "$(pwd)":/workspace giv:latest

build/flatpak/build.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
#!/usr/bin/env bash
2-
set -euo pipefail
2+
set -eu
33

44
VERSION="$1"
5-
FLATPAK_BUILD_TEMP="$2/flatpak"
5+
FLATPAK_BUILD_TEMP="$2"
66
FLATPAK_DIST_DIR="./dist/${VERSION}/flatpak"
77

8-
# Prepare staging dir
9-
rm -rf "$FLATPAK_BUILD_TEMP"
10-
mkdir -p "$FLATPAK_BUILD_TEMP/src" "$FLATPAK_BUILD_TEMP/templates"
8+
rm -rf "${FLATPAK_DIST_DIR}"
9+
mkdir -p "${FLATPAK_DIST_DIR}"
1110

12-
# Copy and rename main script
13-
cp src/giv.sh "$FLATPAK_BUILD_TEMP/src/giv"
14-
chmod +x "$FLATPAK_BUILD_TEMP/src/giv"
15-
# Copy libraries
16-
find src -type f -name '*.sh' ! -name 'giv.sh' -exec cp {} "$FLATPAK_BUILD_TEMP/src/" \;
17-
# Copy templates
18-
cp -r templates/* "$FLATPAK_BUILD_TEMP/templates/"
11+
# Ensure file lists are set
12+
SH_FILES="${SH_FILES:-}"
13+
TEMPLATE_FILES="${TEMPLATE_FILES:-}"
14+
DOCS_FILES="${DOCS_FILES:-}"
1915

20-
# Copy and substitute version in manifest
21-
sed "s/{{VERSION}}/${VERSION}/g" build/flatpak/flatpak.json > "$FLATPAK_BUILD_TEMP/flatpak.json"
16+
# Build sources array as valid JSON
17+
SOURCES_JSON="["
18+
for f in $SH_FILES $TEMPLATE_FILES $DOCS_FILES; do
19+
[ -n "$f" ] && SOURCES_JSON="$SOURCES_JSON{\"type\": \"file\", \"path\": \"$f\"},"
20+
done
21+
SOURCES_JSON="${SOURCES_JSON%,}]" # Remove trailing comma, close array
22+
23+
# Use jq to replace sources array in the template
24+
jq --argjson sources "$SOURCES_JSON" \
25+
--arg version "$VERSION" \
26+
'.sources = $sources | .version = $version' \
27+
build/flatpak/flatpak.json > "$FLATPAK_DIST_DIR/flatpak.json"
28+
29+
cp -r "${FLATPAK_BUILD_TEMP}/package/"* "${FLATPAK_DIST_DIR}/"
2230

23-
# Move to dist dir
24-
mkdir -p "${FLATPAK_DIST_DIR}"
25-
rm -rf "${FLATPAK_DIST_DIR:?}/"*
26-
mv "$FLATPAK_BUILD_TEMP"/* "${FLATPAK_DIST_DIR}/"
2731

2832
printf "Flatpak build completed. Files are in %s\n" "${FLATPAK_DIST_DIR}"
2933
printf "To build the flatpak, run:\n flatpak-builder build-dir flatpak.json --force-clean\n"

build/flatpak/flatpak.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@
1111
"build-commands": [
1212
"install -D src/giv /app/bin/giv",
1313
"install -Dm644 src/*.sh /app/lib/giv/",
14-
"install -Dm644 templates/* /app/share/giv/templates/"
14+
"install -Dm644 templates/* /app/share/giv/templates/",
15+
"install -Dm644 docs/* /app/share/giv/docs/"
1516
],
16-
"sources": [
17-
{ "type": "file", "path": "src/giv" },
18-
{ "type": "file", "path": "src/helpers.sh" },
19-
{ "type": "file", "path": "src/markdown.sh" },
20-
{ "type": "file", "path": "templates/changelog_prompt.md" },
21-
{ "type": "file", "path": "templates/message_prompt.md" },
22-
{ "type": "file", "path": "templates/post_example.md" },
23-
{ "type": "file", "path": "templates/post_prompt.md" },
24-
{ "type": "file", "path": "templates/release_notes_prompt.md" },
25-
{ "type": "file", "path": "templates/summary_prompt.md" },
26-
{ "type": "file", "path": "templates/announcement_prompt.md" }
17+
"sources": [
2718
]
2819
}
2920
]

build/flatpak/publish.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#!/bin/bash
2-
set -euo
2+
set -eu
33

44
VERSION="$1"
5-
_CWD="$(dirname "$(readlink -f "$0")")"
5+
6+
# Check if flatpak-builder is installed
7+
if ! command -v flatpak-builder &> /dev/null; then
8+
echo "flatpak-builder not found. Installing..."
9+
if command -v apt-get &> /dev/null; then
10+
sudo apt-get update
11+
sudo apt-get install -y flatpak-builder
12+
elif command -v dnf &> /dev/null; then
13+
sudo dnf install -y flatpak-builder
14+
elif command -v pacman &> /dev/null; then
15+
sudo pacman -Sy --noconfirm flatpak-builder
16+
else
17+
echo "Package manager not supported. Please install flatpak-builder manually."
18+
exit 1
19+
fi
20+
fi
21+
622
cd "./dist/${VERSION}/flatpak/"
7-
flatpak-builder build-dir flatpak.json --force-clean
8-
cd "${_CWD}"
23+
flatpak-builder build-dir flatpak.json --force-clean

build/homebrew/build.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#!/usr/bin/env bash
2-
set -euo pipefail
2+
set -eu
33

44
VERSION="$1"
5-
HOMEBREW_BUILD_TEMP="$2/homebrew"
5+
HOMEBREW_BUILD_TEMP="$2/package"
66
HOMEBREW_DIST_DIR="./dist/${VERSION}/homebrew"
77

8-
# Prepare temp
9-
rm -rf "$HOMEBREW_BUILD_TEMP"
10-
mkdir -p "$HOMEBREW_BUILD_TEMP/src" "$HOMEBREW_BUILD_TEMP/templates"
118

12-
# Copy files
13-
cp src/giv.sh "$HOMEBREW_BUILD_TEMP/src/giv"
14-
chmod +x "$HOMEBREW_BUILD_TEMP/src/giv"
15-
find src -type f -name '*.sh' ! -name 'giv.sh' -exec cp {} "$HOMEBREW_BUILD_TEMP/src/" \;
16-
cp -r templates/* "$HOMEBREW_BUILD_TEMP/templates/"
9+
# Ensure dist directory exists
10+
mkdir -p "$HOMEBREW_DIST_DIR"
11+
cp -rf "${HOMEBREW_BUILD_TEMP}" "${HOMEBREW_DIST_DIR}/"
1712

1813
# Tarball everything (relative to the root of temp)
1914
TARBALL_NAME="giv-${VERSION}.tar.gz"
@@ -24,9 +19,10 @@ SHA256=$(shasum -a 256 "$HOMEBREW_DIST_DIR/$TARBALL_NAME" | awk '{print $1}')
2419

2520
# Prepare Formula (template below)
2621
sed -e "s|{{VERSION}}|${VERSION}|g" \
27-
-e "s|{{TARBALL_URL}}|https://github.com/itlackey/giv/releases/download/v${VERSION}/$TARBALL_NAME|g" \
22+
-e "s|{{TARBALL_URL}}|https://github.com/giv-cli/giv/releases/download/v${VERSION}/$TARBALL_NAME|g" \
2823
-e "s|{{SHA256}}|$SHA256|g" \
2924
build/homebrew/giv.rb > "$HOMEBREW_DIST_DIR/giv.rb"
3025

26+
rm -rf "$HOMEBREW_DIST_DIR/package"
3127
printf "Homebrew build completed. Files are in %s\n" "${HOMEBREW_DIST_DIR}"
3228
printf "Upload %s to your releases, and update your tap with the new formula.\n" "$TARBALL_NAME"

build/homebrew/giv.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def install
99
bin.install "src/giv" => "giv"
1010
libexec.install Dir["src/*.sh"]
1111
(share/"giv/templates").install Dir["templates/*"]
12+
(share/"giv/docs").install Dir["docs/*"]
1213

1314
# Move all .sh libs to /usr/local/lib/giv for compatibility
1415
lib.mkpath

0 commit comments

Comments
 (0)