Validate version and break out cache key creation logic.
This commit is contained in:
parent
3dc9d0c3ae
commit
82c659a794
4 changed files with 39 additions and 7 deletions
|
@ -18,6 +18,7 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory
|
||||||
### Inputs
|
### Inputs
|
||||||
|
|
||||||
* `packages` - Space delimited list of packages to install.
|
* `packages` - Space delimited list of packages to install.
|
||||||
|
* `version` - Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed.
|
||||||
|
|
||||||
### Outputs
|
### Outputs
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ jobs:
|
||||||
- uses: awalsh128/cache-apt-pkgs-action@v1
|
- uses: awalsh128/cache-apt-pkgs-action@v1
|
||||||
with:
|
with:
|
||||||
packages: dia doxygen doxygen-doc doxygen-gui doxygen-latex graphviz mscgen
|
packages: dia doxygen doxygen-doc doxygen-gui doxygen-latex graphviz mscgen
|
||||||
|
version: 1.0
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -26,14 +26,12 @@ runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: Validate Packages
|
- name: Validate Packages
|
||||||
run: ${{ github.action_path }}/validate_pkgs.sh ${{ inputs.packages }}
|
run: ${{ github.action_path }}/validate_pkgs.sh "${{ inputs.version }}" ${{ inputs.packages }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Create Cache Key
|
- name: Create Cache Key
|
||||||
run: |
|
run: |
|
||||||
normalized_list=$(echo ${{ inputs.packages }} | sed 's/[\s,]+/ /g' | sort)
|
${{ github.action_path }}/create_cache_key.sh "${{ inputs.version }})"" ${{ inputs.packages }} >> $GITHUB_ENV
|
||||||
value=$(echo $normalized_list @ ${{ inputs.version }})
|
|
||||||
echo "CACHE_KEY=$(echo $value | md5sum | /bin/cut -f1 -d' ')" >> $GITHUB_ENV
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Load Package Cache
|
- name: Load Package Cache
|
||||||
|
|
21
create_cache_key.sh
Executable file
21
create_cache_key.sh
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Fail on any error.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
version=$1
|
||||||
|
packages=${@:2}
|
||||||
|
|
||||||
|
echo "* Creating cache key..."
|
||||||
|
|
||||||
|
# Remove package delimiters, sort (requires newline) and then convert back to inline list.
|
||||||
|
normalized_list=$(echo $packages | sed 's/[\s,]+/ /g' | tr ' ' '\n' | sort | tr '\n' ' ')
|
||||||
|
echo "* Normalized package list is '$normalized_list'."
|
||||||
|
|
||||||
|
value=$(echo $normalized_list @ $version)
|
||||||
|
echo "* Value to hash is '$value'."
|
||||||
|
|
||||||
|
key=$(echo $value | md5sum | /bin/cut -f1 -d' ')
|
||||||
|
echo "* Value hashed as '$key'."
|
||||||
|
|
||||||
|
echo "CACHE_KEY=$key"
|
|
@ -3,20 +3,31 @@
|
||||||
# Fail on any error.
|
# Fail on any error.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
packages=$1
|
version=$1
|
||||||
|
packages=${@:2}
|
||||||
|
|
||||||
echo -n "* Validating action arguments... ";
|
echo -n "* Validating action arguments... ";
|
||||||
|
|
||||||
|
echo $version | grep -o " " > /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "aborted."
|
||||||
|
echo "* Version value '$version' cannot contain spaces." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$packages" == "" ]; then
|
if [ "$packages" == "" ]; then
|
||||||
echo "aborted."
|
echo "aborted."
|
||||||
echo "* Packages argument cannot be empty." >&2
|
echo "* Packages argument cannot be empty." >&2
|
||||||
exit 1
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for package in $packages; do
|
for package in $packages; do
|
||||||
apt-cache search ^$package$ | grep $package > /dev/null
|
apt-cache search ^$package$ | grep $package > /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "aborted."
|
echo "aborted."
|
||||||
echo "* Package '$package' not found." >&2
|
echo "* Package '$package' not found." >&2
|
||||||
exit 2
|
exit 3
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "done."
|
echo "done."
|
||||||
|
|
Loading…
Reference in a new issue