cache-apt-pkgs-action/action.yml
awalsh128 1840a3c552 Non-working draft of v2
- Major refactor of project structure and workflows
- Replaced legacy scripts and commands with new Go implementation
- Updated and added CI/CD workflows
- Added new configuration and linting files
- Removed deprecated files and test logs
- Updated documentation and action metadata

This is an initial, non-working draft for v2.0. Further testing and fixes required.
2025-08-23 11:25:52 -07:00

133 lines
5 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"
steps:
- id: setup-binary
shell: bash
run: |
# Map runner architecture to binary name
case "${{ runner.arch }}" in
X64)
BINARY_NAME="cache-apt-pkgs-linux-amd64"
;;
ARM64)
BINARY_NAME="cache-apt-pkgs-linux-arm64"
;;
ARM)
BINARY_NAME="cache-apt-pkgs-linux-arm"
;;
*)
echo "Unsupported architecture: ${{ runner.arch }}"
exit 1
;;
esac
# Use bundled binary from action's dist directory
BINARY_PATH="${{ github.action_path }}/dist/$BINARY_NAME"
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
# Create symlink to standardize binary name for other steps
ln -sf "$BINARY_PATH" "${{ github.action_path }}/cache-apt-pkgs"
chmod +x "${{ github.action_path }}/cache-apt-pkgs"
- id: create-cache-key
shell: bash
run: |
${BINARY_PATH} createkey \
-cache-dir "$CACHE_DIR" \
-version "${{ inputs.version }}" \
-global-version "4" \
-exec-install-scripts ${{ inputs.execute_install_scripts }} \
${{ inputs.packages }}
echo "cache-key=$(cat $CACHE_DIR/cache_key.md5)" >> $GITHUB_OUTPUT
- id: load-cache
uses: actions/cache/restore@v4
with:
path: ~/cache-apt-pkgs
key: cache-apt-pkgs_${{ steps.create-cache-key.outputs.cache-key }}
- id: post-load-cache
run: |
if [ "$CACHE_HIT" == "true" ]; then
${BINARY_PATH} restore
-cache-dir "~/cache-apt-pkgs" \
-exec-install-scripts "$EXEC_INSTALL_SCRIPTS" \
-restore-root "/" \
"$PACKAGES"
else
${BINARY_PATH} install -cache-dir "~/cache-apt-pkgs"
fi
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
echo "all-package-version-list=$(create_list all)" >> $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