Merge branch 'master' into copilot/fix-674930a1-c588-408c-9a64-b575dc5efb5c

This commit is contained in:
Andrew Walsh 2025-09-30 01:07:23 -07:00 committed by GitHub
commit 6be0984af2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 87 additions and 6 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
src/cmd/apt_query/apt_query*
apt_query*
apt_query*
*.log

View file

@ -36,6 +36,7 @@ There are three kinds of version labels you can use.
- `version` - Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed.
- `execute_install_scripts` - Execute Debian package pre and post install script upon restore. See [Caveats / Non-file Dependencies](#non-file-dependencies) for more information.
- `empty_packages_behavior` - Desired behavior when the given `packages` is empty. `'error'` (default), `'warn'` or `'ignore'`.
- `add-repository` - Space delimited list of repositories to add via `apt-add-repository` before installing packages. Supports PPA (e.g., `ppa:user/repo`) and other repository formats.
### Outputs
@ -90,6 +91,36 @@ install_doxygen_deps:
version: 1.0
```
### Using with Third-party PPAs
This example shows how to install packages from a third-party PPA:
```yaml
install_from_ppa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: chromium-browser
add-repository: ppa:canonical-chromium-builds/stage
version: 1.0
```
You can also add multiple repositories:
```yaml
install_from_multiple_repos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: package1 package2
add-repository: ppa:user/repo1 ppa:user/repo2
version: 1.0
```
## Caveats
### Non-file Dependencies

View file

@ -35,6 +35,10 @@ inputs:
description: 'Enable debugging when there are issues with action. Minor performance penalty.'
required: false
default: 'false'
add-repository:
description: 'Space delimited list of repositories to add via apt-add-repository before installing packages. Supports PPA (ppa:user/repo) and other repository formats.'
required: false
default: ''
outputs:
cache-hit:
@ -59,6 +63,7 @@ runs:
"$VERSION" \
"$EXEC_INSTALL_SCRIPTS" \
"$DEBUG" \
"$ADD_REPOSITORY" \
"$PACKAGES"
if [ -f ~/cache-apt-pkgs/cache_key.md5 ]; then
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
@ -71,6 +76,7 @@ runs:
EXEC_INSTALL_SCRIPTS: "${{ inputs.execute_install_scripts }}"
EMPTY_PACKAGES_BEHAVIOR: "${{ inputs.empty_packages_behavior }}"
DEBUG: "${{ inputs.debug }}"
ADD_REPOSITORY: "${{ inputs.add-repository }}"
PACKAGES: "${{ inputs.packages }}"
- id: load-cache
@ -89,6 +95,7 @@ runs:
"$CACHE_HIT" \
"$EXEC_INSTALL_SCRIPTS" \
"$DEBUG" \
"$ADD_REPOSITORY" \
"$PACKAGES"
function create_list { local list=$(cat ~/cache-apt-pkgs/manifest_${1}.log | tr '\n' ','); echo ${list:0:-1}; };
echo "package-version-list=$(create_list main)" >> $GITHUB_OUTPUT
@ -98,6 +105,7 @@ runs:
CACHE_HIT: "${{ steps.load-cache.outputs.cache-hit }}"
EXEC_INSTALL_SCRIPTS: "${{ inputs.execute_install_scripts }}"
DEBUG: "${{ inputs.debug }}"
ADD_REPOSITORY: "${{ inputs.add-repository }}"
PACKAGES: "${{ inputs.packages }}"
- id: upload-logs

View file

@ -15,8 +15,11 @@ source "${script_dir}/lib.sh"
# Directory that holds the cached packages.
cache_dir="${1}"
# Repositories to add before installing packages.
add_repository="${3}"
# List of the packages to use.
input_packages="${@:3}"
input_packages="${@:4}"
if ! apt-fast --version > /dev/null 2>&1; then
log "Installing apt-fast for optimized installs..."
@ -27,6 +30,17 @@ if ! apt-fast --version > /dev/null 2>&1; then
log_empty_line
fi
# Add custom repositories if specified
if [ -n "${add_repository}" ]; then
log "Adding custom repositories..."
for repository in ${add_repository}; do
log "- Adding repository: ${repository}"
sudo apt-add-repository -y "${repository}"
done
log "done"
log_empty_line
fi
log "Updating APT package list..."
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5)" ]]; then
sudo apt-fast update > /dev/null

View file

@ -25,13 +25,16 @@ execute_install_scripts="${4}"
debug="${5}"
test "${debug}" = "true" && set -x
# Repositories to add before installing packages.
add_repository="${6}"
# List of the packages to use.
packages="${@:6}"
packages="${@:7}"
if test "${cache_hit}" = "true"; then
${script_dir}/restore_pkgs.sh "${cache_dir}" "${cache_restore_root}" "${execute_install_scripts}" "${debug}"
else
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" ${packages}
${script_dir}/install_and_cache_pkgs.sh "${cache_dir}" "${debug}" "${add_repository}" ${packages}
fi
log_empty_line

View file

@ -24,8 +24,11 @@ execute_install_scripts="${3}"
# Debug mode for diagnosing issues.
debug="${4}"
# Repositories to add before installing packages.
add_repository="${5}"
# List of the packages to use.
input_packages="${@:5}"
input_packages="${@:6}"
# Trim commas, excess spaces, and sort.
log "Normalizing package list..."
@ -75,6 +78,21 @@ fi
validate_bool "${execute_install_scripts}" execute_install_scripts 4
# Basic validation for repository parameter
if [ -n "${add_repository}" ]; then
log "Validating repository parameter..."
for repository in ${add_repository}; do
# Check if repository format looks valid (basic check)
if [[ "${repository}" =~ [^a-zA-Z0-9:\/.-] ]]; then
log "aborted"
log "Repository '${repository}' contains invalid characters." >&2
log "Supported formats: 'ppa:user/repo', 'deb http://...', 'http://...', 'multiverse', etc." >&2
exit 6
fi
done
log "done"
fi
log "done"
log_empty_line
@ -94,6 +112,12 @@ log "- CPU architecture is '${cpu_arch}'."
value="${packages} @ ${version} ${force_update_inc}"
# Include repositories in cache key to ensure different repos get different caches
if [ -n "${add_repository}" ]; then
value="${value} ${add_repository}"
log "- Repositories '${add_repository}' added to value."
fi
# Don't invalidate existing caches for the standard Ubuntu runners
if [ "${cpu_arch}" != "x86_64" ]; then
value="${value} ${cpu_arch}"

View file

@ -40,7 +40,7 @@ log "done"
log_empty_line
# Only search for archived results. Manifest and cache key also live here.
cached_filepaths=$(ls -1 "${cache_dir}"/*.tar | sort)
cached_filepaths=$(ls -1 "${cache_dir}"/*.tar 2>/dev/null | sort)
cached_filecount=$(echo ${cached_filepaths} | wc -w)
log "Restoring ${cached_filecount} packages from cache..."