cache-apt-pkgs-action/action.yml

126 lines
4.8 KiB
YAML

name: "Cache APT Packages"
description: "Install APT based packages and cache them for future runs."
author: awalsh128
branding:
icon: "hard-drive"
color: "green"
inputs:
packages:
description: "Space delimited list of packages to install. Version can be specified optionally using APT command syntax of <name>=<version> (e.g. xdot=1.2-2)."
required: true
default: ""
version:
description: "Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed."
required: false
default: ""
execute_install_scripts:
description: "Execute Debian package pre and post install script upon restore. See README.md caveats for more information."
required: false
default: "false"
refresh:
description: "OBSOLETE: Refresh is not used by the action, use version instead."
deprecationMessage: "Refresh is not used by the action, use version instead."
debug:
description: "Enable debugging when there are issues with action. Minor performance penalty."
required: false
default: "false"
outputs:
cache-hit:
description: "A boolean value to indicate a cache was found for the packages requested."
# This compound expression is needed because lhs can be empty.
# Need to output true and false instead of true and nothing.
value: ${{ steps.load-cache.outputs.cache-hit || false }}
package-version-list:
description: "The main requested packages and versions that are installed. Represented as a comma delimited list with equals delimit on the package version (i.e. <package>:<version,<package>:<version>)."
value: ${{ steps.post-cache.outputs.package-version-list }}
all-package-version-list:
description: "All the pulled in packages and versions, including dependencies, that are installed. Represented as a comma delimited list with equals delimit on the package version (i.e. <package>:<version,<package>:<version>)."
value: ${{ steps.post-cache.outputs.all-package-version-list }}
runs:
using: "composite"
env:
CACHE_DIR: ~/cache-apt-pkgs
GLOBAL_VERSION: 20250824
steps:
- id: install-aptfast
shell: bash
run: |
if ! apt-fast --version > /dev/null 2>&1; then
"Installing apt-fast for optimized installs and updates"
/bin/bash -c "$(curl -sL https://raw.githubusercontent.com/ilikenwf/apt-fast/master/quick-install.sh)"
fi
- id: setup-binary
shell: bash
run: |
BINARY_PATH="${{ github.action_path }}/tools/distribute.sh getbinpath ${{ runner.arch }}"
if [ ! -f "$BINARY_PATH" ]; then
echo "Error: Binary not found at $BINARY_PATH"
echo "Please ensure the action has been properly built and binaries are included in the dist directory"
exit 1
fi
- id: create-cache-key
shell: bash
run: |
${BINARY_PATH} createkey \
-os-arch ${{ runner.arch }} \
-plaintext-path "${CACHE_DIR}/cache_key.txt" \
-ciphertext-path "${CACHE_DIR}/cache_key.md5" \
-version "${{ inputs.version }}" \
-global-version "${GLOBAL_VERSION}" \
${{ inputs.packages }}
echo "cache-key=$(cat $CACHE_DIR/cache_key.md5)" >> $GITHUB_OUTPUT
- id: load-cache
uses: actions/cache/restore@v4
with:
path: ${CACHE_DIR}
key: cache-apt-pkgs_${{ steps.create-cache-key.outputs.cache-key }}
- id: post-load-cache
# TODO get this implemented
# -exec-install-scripts ${{ inputs.execute_install_scripts }} \
run: |
if [ "$CACHE_HIT" == "true" ]; then
${BINARY_PATH} restore \
-cache-dir "${CACHE_DIR}" \
-restore-root "/" \
"$PACKAGES"
else
${BINARY_PATH} install \
-cache-dir "${CACHE_DIR}"
-version "${{ inputs.version }}" \
-global-version "${GLOBAL_VERSION}"
"$PACKAGES""
fi
echo "package-version-list=$(cat "${CACHE_DIR}/pkgs_args.txt")" >> $GITHUB_OUTPUT
echo "all-package-version-list=$(cat "${CACHE_DIR}/pkgs_installed.txt")" >> $GITHUB_OUTPUT
shell: bash
env:
CACHE_HIT: "${{ steps.load-cache.outputs.cache-hit }}"
EXEC_INSTALL_SCRIPTS: "${{ inputs.execute_install_scripts }}"
DEBUG: "${{ inputs.debug }}"
PACKAGES: "${{ inputs.packages }}"
- id: upload-logs
if: ${{ inputs.debug == 'true' }}
uses: actions/upload-artifact@v4
with:
name: cache-apt-pkgs-logs_${{ env.CACHE_KEY }}
path: ~/cache-apt-pkgs/*.log
- id: save-cache
if: ${{ ! steps.load-cache.outputs.cache-hit }}
uses: actions/cache/save@v4
with:
path: ~/cache-apt-pkgs
key: ${{ steps.load-cache.outputs.cache-primary-key }}
- id: clean-cache
run: |
rm -rf ~/cache-apt-pkgs
shell: bash