Skip to content

Commit 9f817f3

Browse files
committed
2 parents c107d98 + b3b266d commit 9f817f3

10 files changed

Lines changed: 236 additions & 212 deletions

File tree

.github/workflows/build-distribute.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
branches:
77
- dev-v2
88
workflow_call:
9+
inputs:
10+
create_release:
11+
description: 'Create a GitHub release (disabled by default for dry-run/PR builds)'
12+
default: false
13+
type: boolean
914
permissions:
1015
contents: write
1116
id-token: write
@@ -73,7 +78,7 @@ jobs:
7378
create-release:
7479
needs: build-and-release
7580
runs-on: ubuntu-latest
76-
if: success()
81+
if: success() && (github.event_name != 'workflow_call' || inputs.create_release == true)
7782
steps:
7883
- name: Checkout
7984
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

.github/workflows/shellcheck.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.shellcheckrc

Lines changed: 0 additions & 31 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -155,84 +155,3 @@ For more context and information see [issue #57](https://github.com/awalsh128/ca
155155
### Cache Limits
156156

157157
A repository can have up to 5GB of caches. Once the 5GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted. To get more information on how to access and manage your actions's caches, see [GitHub Actions / Using workflows / Cache dependencies](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#viewing-cache-entries).
158-
159-
## Development
160-
161-
### Prerequisites
162-
163-
- **Go 1.20+** (for building the `apt_query` binary) - version specified in `go.mod`
164-
- Install from [golang.org](https://golang.org/dl/) or via package manager
165-
- Verify installation: `go version`
166-
- **ShellCheck** (for linting shell scripts) - install via:
167-
- macOS: `brew install shellcheck`
168-
- Linux: `sudo apt-get install shellcheck` or see [shellcheck installation guide](https://github.com/koalaman/shellcheck#installing)
169-
- Windows: Available via [scoop](https://scoop.sh/) or [chocolatey](https://chocolatey.org/)
170-
171-
### Building
172-
173-
The project includes Go binaries (`apt_query-arm64` and `apt_query-x86`) that are used by the shell scripts to query APT package information.
174-
175-
**Build all packages:**
176-
```bash
177-
go build -v ./...
178-
```
179-
180-
**Build for specific architecture:**
181-
```bash
182-
# For ARM64 (Apple Silicon, ARM servers)
183-
GOARCH=arm64 go build -o apt_query-arm64 ./src/cmd/apt_query
184-
185-
# For x86_64 (Intel/AMD)
186-
GOARCH=amd64 go build -o apt_query-x86 ./src/cmd/apt_query
187-
```
188-
189-
**Run tests:**
190-
```bash
191-
go test -v ./...
192-
```
193-
194-
### Linting
195-
196-
This project uses [ShellCheck](https://github.com/koalaman/shellcheck) to ensure shell script quality and catch common errors. The configuration is stored in `.shellcheckrc`.
197-
198-
**Run ShellCheck locally:**
199-
```bash
200-
shellcheck *.sh
201-
```
202-
203-
**IDE Integration:**
204-
205-
Many IDEs and editors can automatically run ShellCheck:
206-
207-
- **VS Code**: Install the [ShellCheck extension](https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck)
208-
- **Vim/Neovim**: Use [ALE](https://github.com/dense-analysis/ale) or [coc-shellcheck](https://github.com/josa42/coc-shellcheck)
209-
- **IntelliJ/CLion**: ShellCheck is integrated in recent versions
210-
- **Sublime Text**: Install [SublimeLinter-shellcheck](https://github.com/SublimeLinter/SublimeLinter-shellcheck)
211-
212-
**Go Linting:**
213-
214-
This project uses [golangci-lint](https://golangci-lint.run/) for Go code quality checks.
215-
216-
**Run golangci-lint locally:**
217-
```bash
218-
# Install golangci-lint (if not already installed)
219-
# macOS: brew install golangci-lint
220-
# Linux: See https://golangci-lint.run/usage/install/
221-
222-
golangci-lint run
223-
```
224-
225-
**IDE Integration:**
226-
227-
- **VS Code**: Install the [Go extension](https://marketplace.visualstudio.com/items?itemName=golang.go) for syntax highlighting, auto-completion, and built-in linting
228-
- **IntelliJ/GoLand**: Built-in Go support with linting and formatting
229-
- **Vim/Neovim**: Use [vim-go](https://github.com/fatih/vim-go) for Go development
230-
231-
### CI/CD
232-
233-
The GitHub Actions workflows will automatically:
234-
- **Build and test** Go code on pull requests
235-
- **Run ShellCheck** on shell scripts (blocks PRs on failures)
236-
- **Run golangci-lint** on Go code (blocks PRs on failures)
237-
238-
All checks run on pull requests and pushes to `master`, `dev`, and `staging` branches.

install_and_cache_pkgs.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cache_dir="${1}"
1919
add_repository="${3}"
2020

2121
# List of the packages to use.
22-
input_packages="${*:4}"
22+
input_packages="${@:4}"
2323

2424
if ! apt-fast --version > /dev/null 2>&1; then
2525
log "Installing apt-fast for optimized installs..."
@@ -31,7 +31,7 @@ if ! apt-fast --version > /dev/null 2>&1; then
3131
fi
3232

3333
# Add custom repositories if specified
34-
if [[ -n "${add_repository}" ]]; then
34+
if [ -n "${add_repository}" ]; then
3535
log "Adding custom repositories..."
3636
for repository in ${add_repository}; do
3737
log "- Adding repository: ${repository}"
@@ -71,10 +71,7 @@ install_log_filepath="${cache_dir}/install.log"
7171

7272
log "Clean installing ${package_count} packages..."
7373
# Zero interaction while installing or upgrading the system via apt.
74-
# Note: sudo doesn't affect redirects, but we want the output in the file anyway
75-
# shellcheck disable=SC2024
76-
# We intentionally redirect output here; the redirect happens as the current user which is fine
77-
sudo DEBIAN_FRONTEND=noninteractive apt-fast --yes install "${packages}" > "${install_log_filepath}"
74+
sudo DEBIAN_FRONTEND=noninteractive apt-fast --yes install ${packages} > "${install_log_filepath}"
7875
log "done"
7976
log "Installation log written to ${install_log_filepath}"
8077

@@ -84,7 +81,7 @@ installed_packages=$(get_installed_packages "${install_log_filepath}")
8481
log "Installed package list:"
8582
for installed_package in ${installed_packages}; do
8683
# Reformat for human friendly reading.
87-
log "- $(echo "${installed_package}" | awk -F= '{print $1" ("$2")"}')"
84+
log "- $(echo ${installed_package} | awk -F\= '{print $1" ("$2")"}')"
8885
done
8986

9087
log_empty_line
@@ -96,7 +93,7 @@ for installed_package in ${installed_packages}; do
9693

9794
# Sanity test in case APT enumerates duplicates.
9895
if test ! -f "${cache_filepath}"; then
99-
read -r package_name package_ver < <(get_package_name_ver "${installed_package}")
96+
read package_name package_ver < <(get_package_name_ver "${installed_package}")
10097
log " * Caching ${package_name} to ${cache_filepath}..."
10198

10299
# Pipe all package files (no folders), including symlinks, their targets, and installation control data to Tar.
@@ -107,9 +104,9 @@ for installed_package in ${installed_packages}; do
107104
while IFS= read -r f; do
108105
if test -f "${f}" -o -L "${f}"; then
109106
get_tar_relpath "${f}"
110-
if [[ -L "${f}" ]]; then
107+
if [ -L "${f}" ]; then
111108
target="$(readlink -f "${f}")"
112-
if [[ -f "${target}" ]]; then
109+
if [ -f "${target}" ]; then
113110
get_tar_relpath "${target}"
114111
fi
115112
fi
@@ -123,7 +120,7 @@ for installed_package in ${installed_packages}; do
123120
# Comma delimited name:ver pairs in the all packages manifest.
124121
manifest_all="${manifest_all}${package_name}=${package_ver},"
125122
done
126-
log "done (total cache size $(du -h "${cache_dir}" | tail -1 | awk '{print $1}'))"
123+
log "done (total cache size $(du -h ${cache_dir} | tail -1 | awk '{print $1}'))"
127124

128125
log_empty_line
129126

lib.sh

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ set +e
1717
# Filepath of the install script, otherwise an empty string.
1818
###############################################################################
1919
function execute_install_script {
20-
local package_name
21-
package_name=$(basename "${2}" | awk -F= '{print $1}')
22-
local install_script_filepath
23-
install_script_filepath=$(\
20+
local package_name=$(basename ${2} | awk -F\= '{print $1}')
21+
local install_script_filepath=$(\
2422
get_install_script_filepath "${1}" "${package_name}" "${3}")
2523
if test ! -z "${install_script_filepath}"; then
2624
log "- Executing ${install_script_filepath}..."
2725
# Don't abort on errors; dpkg-trigger will error normally since it is
2826
# outside its run environment.
29-
sudo sh -x "${install_script_filepath}" "${4}" || true
27+
sudo sh -x ${install_script_filepath} ${4} || true
3028
log " done"
3129
fi
3230
}
@@ -42,17 +40,9 @@ function execute_install_script {
4240
###############################################################################
4341
function get_install_script_filepath {
4442
# Filename includes arch (e.g. amd64).
45-
local filepath
46-
# Use glob expansion instead of ls|grep for better handling of non-alphanumeric filenames
47-
# Use nullglob to prevent literal match when no files found
48-
shopt -s nullglob
49-
for f in "${1}"var/lib/dpkg/info/"${2}"*."${3}"; do
50-
if [[ -f "${f}" ]] && [[ "${f}" =~ ${2}'(:.*)?.'"${3}" ]]; then
51-
filepath="${f}"
52-
break
53-
fi
54-
done
55-
shopt -u nullglob
43+
local filepath="$(\
44+
ls -1 ${1}var/lib/dpkg/info/${2}*.${3} 2> /dev/null \
45+
| grep -E ${2}'(:.*)?.'${3} | head -1 || true)"
5646
test "${filepath}" && echo "${filepath}"
5747
}
5848

@@ -76,7 +66,7 @@ function get_installed_packages {
7666
log_err "Unable to parse package name and version from \"${line}\""
7767
exit 2
7868
fi
79-
done < <(grep "^Unpacking " "${install_log_filepath}")
69+
done < <(grep "^Unpacking " ${install_log_filepath})
8070
if test -n "${dep_packages}"; then
8171
echo "${dep_packages:0:-1}" # Removing trailing space.
8272
else
@@ -93,13 +83,13 @@ function get_installed_packages {
9383
###############################################################################
9484
function get_package_name_ver {
9585
local ORIG_IFS="${IFS}"
96-
IFS='=' read -r name ver <<< "${1}"
86+
IFS=\= read name ver <<< "${1}"
9787
IFS="${ORIG_IFS}"
9888
# If version not found in the fully qualified package value.
9989
if test -z "${ver}"; then
10090
# This is a fallback and should not be used any more as its slow.
10191
log_err "Unexpected version resolution for package '${name}'"
102-
ver="$(apt-cache show "${name}" | grep '^Version:' | awk '{print $2}')"
92+
ver="$(apt-cache show ${name} | grep '^Version:' | awk '{print $2}')"
10393
fi
10494
echo "${name}" "${ver}"
10595
}
@@ -115,19 +105,16 @@ function get_normalized_package_list {
115105
# Remove commas, and block scalar folded backslashes,
116106
# extraneous spaces at the middle, beginning and end
117107
# then sort.
118-
local packages
119-
packages=$(echo "${1}" \
108+
local packages=$(echo "${1}" \
120109
| sed 's/[,\]/ /g; s/\s\+/ /g; s/^\s\+//g; s/\s\+$//g' \
121110
| sort -t' ')
122-
local script_dir
123-
script_dir="$(dirname -- "$(realpath -- "${0}")")"
111+
local script_dir="$(dirname -- "$(realpath -- "${0}")")"
124112

125-
local architecture
126-
architecture=$(dpkg --print-architecture)
127-
if [[ "${architecture}" == "arm64" ]]; then
128-
"${script_dir}"/apt_query-arm64 normalized-list "${packages}"
113+
local architecture=$(dpkg --print-architecture)
114+
if [ "${architecture}" == "arm64" ]; then
115+
${script_dir}/apt_query-arm64 normalized-list ${packages}
129116
else
130-
"${script_dir}"/apt_query-x86 normalized-list "${packages}"
117+
${script_dir}/apt_query-x86 normalized-list ${packages}
131118
fi
132119
}
133120

@@ -140,8 +127,8 @@ function get_normalized_package_list {
140127
# The relative filepath to archive.
141128
###############################################################################
142129
function get_tar_relpath {
143-
local filepath="${1}"
144-
if test "${filepath:0:1}" = "/"; then
130+
local filepath=${1}
131+
if test ${filepath:0:1} = "/"; then
145132
echo "${filepath:1}"
146133
else
147134
echo "${filepath}"
@@ -194,7 +181,7 @@ function validate_bool {
194181
if test "${1}" != "true" -a "${1}" != "false"; then
195182
log "aborted"
196183
log "${2} value '${1}' must be either true or false (case sensitive)."
197-
exit "${3}"
184+
exit ${3}
198185
fi
199186
}
200187

@@ -208,12 +195,12 @@ function validate_bool {
208195
# Log lines from write.
209196
###############################################################################
210197
function write_manifest {
211-
if [[ ${#2} -eq 0 ]]; then
198+
if [ ${#2} -eq 0 ]; then
212199
log "Skipped ${1} manifest write. No packages to install."
213200
else
214201
log "Writing ${1} packages manifest to ${3}..."
215202
# 0:-1 to remove trailing comma, delimit by newline and sort.
216-
echo "${2:0:-1}" | tr ',' '\n' | sort > "${3}"
203+
echo "${2:0:-1}" | tr ',' '\n' | sort > ${3}
217204
log "done"
218205
fi
219206
}

post_cache_action.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ test "${debug}" = "true" && set -x
2929
add_repository="${6}"
3030

3131
# List of the packages to use.
32-
packages="${*:7}"
32+
packages="${@:7}"
3333

3434
if test "${cache_hit}" = "true"; then
35-
"${script_dir}"/restore_pkgs.sh "${cache_dir}" "${cache_restore_root}" "${execute_install_scripts}" "${debug}"
35+
${script_dir}/restore_pkgs.sh "${cache_dir}" "${cache_restore_root}" "${execute_install_scripts}" "${debug}"
3636
else
37-
"${script_dir}"/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" "${add_repository}" "${packages}"
37+
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" "${add_repository}" ${packages}
3838
fi
3939

4040
log_empty_line

0 commit comments

Comments
 (0)