dedup and fix debug log and test in pr action

This commit is contained in:
Mahyar McDonald 2025-11-03 17:38:36 -08:00
parent 0957ded375
commit a96225340d
3 changed files with 151 additions and 3 deletions

View file

@ -19,7 +19,7 @@ jobs:
go-version-file: "go.mod"
- name: Build and test
run: |
run: | #shell
go build -v ./...
go test -v ./...
@ -27,3 +27,126 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
- name: Ensure apt_query binaries are executable
run: | #shell
chmod +x apt_query-x86 apt_query-arm64 || true
- name: Test action
id: test-action
uses: ./
with:
packages: curl wget
version: test-pr-${{ github.run_number }}
debug: 'true'
- name: Verify action outputs
run: | #shell
echo "Cache hit: ${{ steps.test-action.outputs.cache-hit }}"
echo "Package version list: ${{ steps.test-action.outputs.package-version-list }}"
echo "All package version list: ${{ steps.test-action.outputs.all-package-version-list }}"
# Verify outputs are set (even if cache-hit is false on first run)
if [ -z "${{ steps.test-action.outputs.package-version-list }}" ]; then
echo "❌ ERROR: package-version-list output is empty"
exit 1
fi
# Verify packages are in the output
if ! echo "${{ steps.test-action.outputs.package-version-list }}" | grep -q "curl"; then
echo "⚠️ WARNING: curl not found in package-version-list"
fi
if ! echo "${{ steps.test-action.outputs.package-version-list }}" | grep -q "wget"; then
echo "⚠️ WARNING: wget not found in package-version-list"
fi
echo "✅ Action outputs verified successfully"
- name: Create Aptfile for testing
run: |
cat > Aptfile << 'EOF'
# Test packages from Aptfile
git
ca-certificates
# Another package
gnupg
EOF
echo "Created Aptfile with contents:"
cat Aptfile
- name: Test action with Aptfile
id: test-action-aptfile
uses: ./
with:
use_aptfile: 'true'
version: test-pr-aptfile-${{ github.run_number }}
debug: 'true'
- name: Verify Aptfile functionality
run: | #shell
echo "Cache hit: ${{ steps.test-action-aptfile.outputs.cache-hit }}"
echo "Package version list: ${{ steps.test-action-aptfile.outputs.package-version-list }}"
echo "All package version list: ${{ steps.test-action-aptfile.outputs.all-package-version-list }}"
# Verify outputs are set
if [ -z "${{ steps.test-action-aptfile.outputs.package-version-list }}" ]; then
echo "❌ ERROR: package-version-list output is empty"
exit 1
fi
# Verify packages from Aptfile are in the output
if ! echo "${{ steps.test-action-aptfile.outputs.package-version-list }}" | grep -q "git"; then
echo "❌ ERROR: git not found in package-version-list (from Aptfile)"
exit 1
fi
if ! echo "${{ steps.test-action-aptfile.outputs.package-version-list }}" | grep -q "ca-certificates"; then
echo "❌ ERROR: ca-certificates not found in package-version-list (from Aptfile)"
exit 1
fi
if ! echo "${{ steps.test-action-aptfile.outputs.package-version-list }}" | grep -q "gnupg"; then
echo "❌ ERROR: gnupg not found in package-version-list (from Aptfile)"
exit 1
fi
echo "✅ Aptfile functionality verified successfully"
- name: Test action with Aptfile and packages input (merge)
id: test-action-merge
uses: ./
with:
packages: curl
use_aptfile: 'true'
version: test-pr-merge-${{ github.run_number }}
debug: 'true'
- name: Verify Aptfile and packages merge
run: | #shell
echo "Cache hit: ${{ steps.test-action-merge.outputs.cache-hit }}"
echo "Package version list: ${{ steps.test-action-merge.outputs.package-version-list }}"
# Verify outputs are set
if [ -z "${{ steps.test-action-merge.outputs.package-version-list }}" ]; then
echo "❌ ERROR: package-version-list output is empty"
exit 1
fi
# Verify packages from both sources are in the output
if ! echo "${{ steps.test-action-merge.outputs.package-version-list }}" | grep -q "curl"; then
echo "❌ ERROR: curl not found in package-version-list (from packages input)"
exit 1
fi
if ! echo "${{ steps.test-action-merge.outputs.package-version-list }}" | grep -q "git"; then
echo "❌ ERROR: git not found in package-version-list (from Aptfile)"
exit 1
fi
echo "✅ Aptfile and packages merge verified successfully"
- name: Cleanup Aptfile
if: always()
run: | #shell
rm -f Aptfile

23
lib.sh
View file

@ -124,8 +124,9 @@ function get_normalized_package_list {
# Remove "Reverse=Provides: " prefix from strings if present
local clean_result
clean_result=$(echo "${result}" | sed 's/Reverse=Provides: //g')
echo "cleaned result: ${clean_result}"
echo "result: ${result}"
# Debug logging to stderr (won't interfere with return value captured via command substitution)
echo "cleaned result: ${clean_result}" >&2
echo "result: ${result}" >&2
echo "${clean_result}"
}
@ -168,6 +169,24 @@ function validate_bool {
fi
}
###############################################################################
# Deduplicates a space-delimited list of packages.
# Arguments:
# Space delimited list of packages.
# Returns:
# Space delimited list of unique packages (sorted).
###############################################################################
function deduplicate_packages {
local packages="${1}"
if test -z "${packages}"; then
echo ""
return
fi
# Convert space-separated to newline-separated, sort unique, then convert back to space-separated
echo "${packages}" | tr ' ' '\n' | sort -u | tr '\n' ' ' | sed 's/[[:space:]]*$//'
}
###############################################################################
# Parses an Aptfile and extracts package names.
# Arguments:

View file

@ -69,6 +69,12 @@ else
combined_packages=""
fi
# Deduplicate packages after combining
if test -n "${combined_packages}"; then
combined_packages="$(deduplicate_packages "${combined_packages}")"
log "Deduplicated packages: '${combined_packages}'"
fi
# Create cache directory so artifacts can be saved.
mkdir -p "${cache_dir}"