mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-07-06 09:04:38 +00:00
Draft of v2
This commit is contained in:
parent
a605dbde2a
commit
42b6b9694b
62
.github/actions/codehealth/action.yml
vendored
Normal file
62
.github/actions/codehealth/action.yml
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
name: "Verify code health and quality"
|
||||
description: "Runs build, linters, type, tests, and generates API docs to verify the code is in a good state"
|
||||
|
||||
inputs:
|
||||
run_tests:
|
||||
description: "Whether to run tests as part of verification (default: true)"
|
||||
required: false
|
||||
default: "true"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Lint
|
||||
shell: bash
|
||||
run: npm run lint
|
||||
|
||||
- name: Typecheck
|
||||
shell: bash
|
||||
run: npm run typecheck
|
||||
|
||||
- name: Type Coverage
|
||||
shell: bash
|
||||
run: npx type-coverage --at-least 95
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: 'github/codeql-action/init@1a818fd5f97ed0ee9a823421bd5b171add01227f' # v4.36.2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# Use 'security-extended' for more comprehensive security checks
|
||||
# and 'security-and-quality' to include code quality queries.
|
||||
queries: security-extended,security-and-quality
|
||||
|
||||
- name: Check Action Pinning
|
||||
shell: bash
|
||||
run: |
|
||||
# Install pinact (example via go or download binary)
|
||||
go install github.com/suzuki-shunsuke/pinact/cmd/pinact@latest
|
||||
|
||||
# Run check on the composite action file
|
||||
pinact run -check .github/actions/my-composite-action/action.yml
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: npm run build
|
||||
|
||||
- name: Unit tests
|
||||
if: ${{ inputs.run_tests == 'true' }}
|
||||
shell: bash
|
||||
run: npm run test:unit
|
||||
|
||||
- name: Integration tests
|
||||
if: ${{ inputs.run_tests == 'true' }}
|
||||
shell: bash
|
||||
run: npm run test:integration
|
||||
|
||||
- name: Generate API docs
|
||||
shell: bash
|
||||
run: npm run docs:api
|
||||
|
||||
- name: Verify API docs are up to date
|
||||
shell: bash
|
||||
run: git diff --exit-code -- docs/api
|
||||
15
.github/actions/setup-env/action.yml
vendored
Normal file
15
.github/actions/setup-env/action.yml
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
name: "Setup environment"
|
||||
description: "Checks out code, sets up Node.js, and installs dependencies"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Setup Node.js
|
||||
uses: "actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e" # v6.4.0
|
||||
with:
|
||||
node-version: 24
|
||||
cache: "npm"
|
||||
|
||||
- name: Install dependencies
|
||||
shell: bash
|
||||
run: npm ci
|
||||
997
.github/workflows/ci.yml
vendored
Normal file
997
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,997 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: "30 5 * * *"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
debug:
|
||||
description: "Run in debug mode."
|
||||
type: boolean
|
||||
required: false
|
||||
default: true
|
||||
|
||||
env:
|
||||
DEBUG: ${{ github.event.inputs.debug || false }}
|
||||
permissions:
|
||||
security-events: write
|
||||
|
||||
jobs:
|
||||
verification:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [24]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
|
||||
- name: Setup
|
||||
uses: ./.github/actions/setup-env
|
||||
|
||||
- name: Check code health
|
||||
uses: ./.github/actions/codehealth
|
||||
with:
|
||||
run_tests: "false" # Run full testing with coverage below
|
||||
|
||||
- name: Run tests with coverage
|
||||
shell: bash
|
||||
run: npm test
|
||||
|
||||
- name: Upload coverage info
|
||||
uses: "codecov/codecov-action@e53489f4d376d79066609109e7a95a29eb3740b1" # v7.0.0
|
||||
with:
|
||||
files: ./coverage/lcov.info
|
||||
fail_ci_if_error: true
|
||||
|
||||
- name: Annotate coverage on changed files
|
||||
uses: "jgillick/test-coverage-annotations@74fb1a9d4dbe8048001f4334c60095f65060c62a" # v1.0.3
|
||||
with:
|
||||
access-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
coverage: ./coverage/coverage-final.json
|
||||
only-changed-files: true
|
||||
|
||||
# All other jobs should depend on build_binaries (if run) or check_distribute (if not needed)
|
||||
list_all_versions:
|
||||
runs-on: ubuntu-latest
|
||||
name: List all package versions (including deps).
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot=1.3-1
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-list_all_versions
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: |
|
||||
steps.execute.outputs.cache-hit != 'false' ||
|
||||
steps.execute.outputs.all-package-version-list != 'fonts-liberation2=1:2.1.5-3,gir1.2-atk-1.0=2.52.0-1build1,gir1.2-freedesktop=1.80.1-1,gir1.2-gdkpixbuf-2.0=2.42.10+dfsg-3ubuntu3.2,gir1.2-gtk-3.0=3.24.41-4ubuntu1.3,gir1.2-harfbuzz-0.0=8.3.0-2build2,gir1.2-pango-1.0=1.52.1+ds-1build1,graphviz=2.42.2-9ubuntu0.1,libann0=1.1.2+doc-9build1,libblas3=3.12.0-3build1.1,libcdt5=2.42.2-9ubuntu0.1,libcgraph6=2.42.2-9ubuntu0.1,libgts-0.7-5t64=0.7.6+darcs121130-5.2build1,libgts-bin=0.7.6+darcs121130-5.2build1,libgvc6=2.42.2-9ubuntu0.1,libgvpr2=2.42.2-9ubuntu0.1,libharfbuzz-gobject0=8.3.0-2build2,liblab-gamut1=2.42.2-9ubuntu0.1,liblapack3=3.12.0-3build1.1,libpangoxft-1.0-0=1.52.1+ds-1build1,libpathplan4=2.42.2-9ubuntu0.1,python3-cairo=1.25.1-2build2,python3-gi-cairo=3.48.2-1,python3-numpy=1:1.26.4+ds-6ubuntu1,xdot=1.3-1'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
echo "package-version-list = ${{ steps.execute.outputs.package-version-list }}"
|
||||
echo "all-package-version-list = ${{ steps.execute.outputs.all-package-version-list }}"
|
||||
echo "diff all-package-version-list"
|
||||
diff <(echo "${{ steps.execute.outputs.all-package-version-list }}" ) <(echo "fonts-liberation2=1:2.1.5-3,gir1.2-atk-1.0=2.52.0-1build1,gir1.2-freedesktop=1.80.1-1,gir1.2-gdkpixbuf-2.0=2.42.10+dfsg-3ubuntu3.2,gir1.2-gtk-3.0=3.24.41-4ubuntu1.3,gir1.2-harfbuzz-0.0=8.3.0-2build2,gir1.2-pango-1.0=1.52.1+ds-1build1,graphviz=2.42.2-9ubuntu0.1,libann0=1.1.2+doc-9build1,libblas3=3.12.0-3build1.1,libcdt5=2.42.2-9ubuntu0.1,libcgraph6=2.42.2-9ubuntu0.1,libgts-0.7-5t64=0.7.6+darcs121130-5.2build1,libgts-bin=0.7.6+darcs121130-5.2build1,libgvc6=2.42.2-9ubuntu0.1,libgvpr2=2.42.2-9ubuntu0.1,libharfbuzz-gobject0=8.3.0-2build2,liblab-gamut1=2.42.2-9ubuntu0.1,liblapack3=3.12.0-3build1.1,libpangoxft-1.0-0=1.52.1+ds-1build1,libpathplan4=2.42.2-9ubuntu0.1,python3-cairo=1.25.1-2build2,python3-gi-cairo=3.48.2-1,python3-numpy=1:1.26.4+ds-6ubuntu1,xdot=1.3-1")
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
list_versions:
|
||||
runs-on: ubuntu-latest
|
||||
name: List package versions.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-list_versions
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if:
|
||||
steps.execute.outputs.cache-hit != 'false' || steps.execute.outputs.package-version-list
|
||||
!= 'rolldice=1.16-1build3,xdot=1.3-1'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
echo "package-version-list = ${{ steps.execute.outputs.package-version-list }}"
|
||||
echo "diff package-version-list"
|
||||
diff <(echo "${{ steps.execute.outputs.package-version-list }}" ) <(echo "rolldice=1.16-1build3,xdot=1.3-1")
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
standard_workflow_install:
|
||||
runs-on: ubuntu-latest
|
||||
name: Standard workflow install package and cache.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-standard_workflow
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'false'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
standard_workflow_install_with_new_version:
|
||||
needs: [standard_workflow_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: Standard workflow packages with new version.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt}}-standard_workflow_install_with_new_version
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'false'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
standard_workflow_restore:
|
||||
needs: [standard_workflow_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: Standard workflow restore cached packages.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-standard_workflow
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
standard_workflow_restore_with_packages_out_of_order:
|
||||
needs: [standard_workflow_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: Standard workflow restore with packages out of order.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: rolldice xdot
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-standard_workflow
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
standard_workflow_add_package:
|
||||
needs: [standard_workflow_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: Standard workflow add another package.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice distro-info-data
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-standard_workflow
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'false'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
standard_workflow_restore_add_package:
|
||||
needs: [standard_workflow_add_package]
|
||||
runs-on: ubuntu-latest
|
||||
name: Standard workflow restore added package.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice distro-info-data
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-standard_workflow
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
no_packages:
|
||||
runs-on: ubuntu-latest
|
||||
name: No packages passed.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: ""
|
||||
continue-on-error: true
|
||||
- name: Verify
|
||||
if: steps.execute.outcome == 'failure'
|
||||
run: exit 0
|
||||
shell: bash
|
||||
|
||||
package_not_found:
|
||||
runs-on: ubuntu-latest
|
||||
name: Package not found.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: package_that_doesnt_exist
|
||||
continue-on-error: true
|
||||
- name: Verify
|
||||
if: steps.execute.outcome == 'failure'
|
||||
run: exit 0
|
||||
shell: bash
|
||||
|
||||
version_contains_spaces:
|
||||
runs-on: ubuntu-latest
|
||||
name: Version contains spaces.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot
|
||||
version: 123 abc
|
||||
debug: ${{ env.DEBUG }}
|
||||
continue-on-error: true
|
||||
- name: Verify
|
||||
if: steps.execute.outcome == 'failure'
|
||||
run: exit 0
|
||||
shell: bash
|
||||
|
||||
regression_36:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Reinstall existing package (regression issue #36)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libgtk-3-dev
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_36
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_37:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Install with reported package dependencies not installed (regression issue #37)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libosmesa6-dev libgl1-mesa-dev python3-tk pandoc git-restore-mtime
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_37
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
debug_disabled:
|
||||
runs-on: ubuntu-latest
|
||||
name: Debug disabled.
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: xdot
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-list-all-package-versions
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_72_1:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Cache Java CA certs package v1 (regression issue #72)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: openjdk-11-jre
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_72
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_72_2:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Cache Java CA certs package v2 (regression issue #72)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: default-jre
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_72
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_76:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Cache empty archive (regression issue #76)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- run: |
|
||||
sudo wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null;
|
||||
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list;
|
||||
sudo apt-get -qq update;
|
||||
sudo apt-get install -y intel-oneapi-runtime-libs intel-oneapi-runtime-opencl;
|
||||
sudo apt-get install -y opencl-headers ocl-icd-opencl-dev;
|
||||
sudo apt-get install -y libsundials-dev;
|
||||
- uses: ./
|
||||
with:
|
||||
packages: intel-oneapi-runtime-libs
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_76
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_79:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Tar error with libboost-dev (regression issue #79)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libboost-dev
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_79
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_81:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Tar error with alsa-ucm-conf (regression issue #81)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages:
|
||||
libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcups2 libdrm2 libgbm1
|
||||
libnspr4 libnss3 libxcomposite1 libxdamage1 libxfixes3 libxkbcommon0 libxrandr2
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_81
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_84_literal_block_install:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Install multiline package listing using literal block style (regression issue #84)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: >
|
||||
xdot rolldice distro-info-data
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_84_literal_block
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_84_literal_block_restore:
|
||||
needs: [regression_84_literal_block_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: "Restore multiline package listing using literal block style (regression issue #84)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice distro-info-data
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_84_literal_block
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
regression_84_folded_block_install:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Install multiline package listing using literal block style (regression issue #84)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: |
|
||||
xdot \
|
||||
rolldice distro-info-data
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_84_folded_block
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_84_folded_block_restore:
|
||||
needs: [regression_84_folded_block_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: "Restore multiline package listing using literal block style (regression issue #84)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- name: Execute
|
||||
id: execute
|
||||
uses: ./
|
||||
with:
|
||||
packages: xdot rolldice distro-info-data
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_84_folded_block
|
||||
debug: ${{ env.DEBUG }}
|
||||
- name: Verify
|
||||
if: steps.execute.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
echo "cache-hit = ${{ steps.execute.outputs.cache-hit }}"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
regression_89:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Upload logs artifact name (regression issue #89)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libgtk-3-dev:amd64
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_89
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_98:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Install error due to SHELLOPTS override (regression issue #98)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: git-restore-mtime libgl1-mesa-dev libosmesa6-dev pandoc
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_98
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_106_install:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Stale apt repo not finding package on restore, install phase (regression issue #106)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libtk8.6
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_106
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
regression_106_restore:
|
||||
needs: [regression_106_install]
|
||||
runs-on: ubuntu-latest
|
||||
name: "Stale apt repo not finding package on restore, restore phase (regression issue #106)."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libtk8.6
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-regression_106
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
multi_arch_cache_key:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Cache packages with multi-arch cache key."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libfuse2
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-multi_arch_cache_key
|
||||
debug: ${{ env.DEBUG }}
|
||||
|
||||
virtual_package:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Cache virtual package."
|
||||
steps:
|
||||
- uses: "actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0" # v7.0.0
|
||||
- name: Download build artifacts
|
||||
uses: "actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" # v8.0.1
|
||||
with:
|
||||
pattern: cache-apt-pkgs-*
|
||||
path: distribute-artifacts
|
||||
- name: Setup distribute directory
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p distribute/X64 distribute/X86 distribute/ARM64 distribute/ARM
|
||||
for artifact_dir in distribute-artifacts/cache-apt-pkgs-*; do
|
||||
if [ -d "$artifact_dir" ]; then
|
||||
arch=$(basename "$artifact_dir" | sed 's/cache-apt-pkgs-\([^-]*\)-.*/\1/')
|
||||
echo "Copying artifacts for architecture: $arch"
|
||||
cp -r "$artifact_dir"/* "distribute/$arch/" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
ls -la distribute/*/ || true
|
||||
- uses: ./
|
||||
with:
|
||||
packages: libvips
|
||||
version: ${{ github.run_id }}-${{ github.run_attempt }}-virtual_package
|
||||
debug: ${{ env.DEBUG }}
|
||||
19
.github/workflows/pub_dev_push_event.yml
vendored
19
.github/workflows/pub_dev_push_event.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
name: Publish Dev Push Event
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
publish_event:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish dev push
|
||||
steps:
|
||||
- run: |
|
||||
curl -i \
|
||||
-X POST \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token ${{ secrets.PUBLISH_PUSH_TOKEN }}" \
|
||||
https://api.github.com/repos/awalsh128/cache-apt-pkgs-action-ci/dispatches \
|
||||
-d '{"event_type":"dev_push"}'
|
||||
19
.github/workflows/pub_master_push_event.yml
vendored
19
.github/workflows/pub_master_push_event.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
name: Publish Master Push Event
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
publish_event:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish master push
|
||||
steps:
|
||||
- run: |
|
||||
curl -i \
|
||||
-X POST \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token ${{ secrets.PUBLISH_PUSH_TOKEN }}" \
|
||||
https://api.github.com/repos/awalsh128/cache-apt-pkgs-action-ci/dispatches \
|
||||
-d '{"event_type":"master_push"}'
|
||||
19
.github/workflows/pub_staging_push_event.yml
vendored
19
.github/workflows/pub_staging_push_event.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
name: Publish Staging Push Event
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- staging
|
||||
|
||||
jobs:
|
||||
publish_event:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish staging push
|
||||
steps:
|
||||
- run: |
|
||||
curl -i \
|
||||
-X POST \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-H "Authorization: token ${{ secrets.PUBLISH_PUSH_TOKEN }}" \
|
||||
https://api.github.com/repos/awalsh128/cache-apt-pkgs-action-ci/dispatches \
|
||||
-d '{"event_type":"staging_push"}'
|
||||
29
.github/workflows/pull_request.yml
vendored
29
.github/workflows/pull_request.yml
vendored
|
|
@ -1,29 +0,0 @@
|
|||
name: Pull Request
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
integrate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version-file: "go.mod"
|
||||
|
||||
- name: Build and test
|
||||
run: |
|
||||
go build -v ./...
|
||||
go test -v ./...
|
||||
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.52.2
|
||||
86
.github/workflows/release.yml
vendored
Normal file
86
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "Release tag (for example v0.2.0)"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [24]
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || inputs.tag }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: 'actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0' # v7.0.0
|
||||
|
||||
- name: Setup environment
|
||||
uses: ./.github/actions/setup-env
|
||||
|
||||
# Preflight checks (validate tag format, version consistency, etc.)
|
||||
- name: Release preflight (tag/version)
|
||||
run: npm run release:preflight
|
||||
|
||||
- name: Check code health
|
||||
uses: ./.github/actions/codehealth
|
||||
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
needs: validate
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: 'actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0' # v7.0.0
|
||||
|
||||
- name: Setup environment
|
||||
uses: ./.github/actions/setup-env
|
||||
|
||||
- name: Build package
|
||||
run: npm run build
|
||||
|
||||
- name: Resolve npm dist-tag
|
||||
run: |
|
||||
TAG="${{ github.ref_type == 'tag' && github.ref_name || inputs.tag }}"
|
||||
if [[ "$TAG" == *-* ]]; then
|
||||
echo "NPM_DIST_TAG=next" >> "$GITHUB_ENV"
|
||||
else
|
||||
echo "NPM_DIST_TAG=latest" >> "$GITHUB_ENV"
|
||||
fi
|
||||
|
||||
- name: Generate API docs
|
||||
run: npm run docs:api
|
||||
|
||||
- name: Publish to npm
|
||||
run: npm publish --access public --provenance --tag "$NPM_DIST_TAG"
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create GitHub release
|
||||
uses: 'softprops/action-gh-release@2bb465e97f322d3cb2a965294d483e0d26a67aa9' # v3.0.1
|
||||
with:
|
||||
generate_release_notes: true
|
||||
tag_name: ${{ github.ref_type == 'tag' && github.ref_name || inputs.tag }}
|
||||
|
||||
- name: Setup Pages
|
||||
uses: 'actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d' # v6.0.0
|
||||
|
||||
- name: Upload Pages artifact
|
||||
uses: 'actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9' # v5.0.0
|
||||
with:
|
||||
path: docs/api
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: 'actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128' # v5.0.0
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
|||
src/cmd/apt_query/apt_query*
|
||||
node_modules/
|
||||
coverage/
|
||||
target/
|
||||
59
README.md
59
README.md
|
|
@ -6,6 +6,12 @@
|
|||
|
||||
This action allows caching of Advanced Package Tool (APT) package dependencies to improve workflow execution time instead of installing the packages on every run.
|
||||
|
||||
> [!NOTE]
|
||||
> The open source projects that I maintain are a labor of love. If you find this useful and want to support open source, **please consider donating and [Buy Me a Coffe](http://buymeacoffee.com/awalsh128)**.
|
||||
|
||||
> [!NOTE]
|
||||
> Version 2 of the action is now available! See [Version 2 FAQ](V2_FAQ.MD) for more information.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Looking for co-maintainers to help review changes, and investigate issues. I haven't had as much time to stay on top of this action as I would like to and want to make sure it is still responsive and reliable for the community. If you are interested, please reach out.
|
||||
|
||||
|
|
@ -43,6 +49,58 @@ There are three kinds of version labels you can use.
|
|||
- `package-version-list` - The main requested packages and versions that are installed. Represented as a comma delimited list with equals delimit on the package version (i.e. \<package1>=<version1\>,\<package2>=\<version2>,...).
|
||||
- `all-package-version-list` - 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. \<package1>=<version1\>,\<package2>=\<version2>,...).
|
||||
|
||||
### Security Compliance
|
||||
|
||||
This action runs as a JavaScript GitHub Action on the `node20` runtime and does not require consumers to run `npm install` in their workflow in order to use it. The implementation dependency surface is limited to the action runtime packages declared in `package.json`: `@actions/cache`, `@actions/core`, `tar`, `winston`, and `ts-apt`.
|
||||
|
||||
For workflows with stricter compliance requirements, the main security characteristics are:
|
||||
|
||||
- `packages` should be treated as an allowlisted input in your workflow. Prefer explicit package names and versions where reproducibility matters.
|
||||
- `version` can be used as a cache namespace so you can intentionally rotate caches when package policy or runner baselines change.
|
||||
- `empty_packages_behavior` can be left at the default `error` to fail closed when an expected package list is missing.
|
||||
- `execute_install_scripts` is disabled by default. Enable it only when required, because Debian maintainer scripts execute arbitrary package-provided shell logic during restore.
|
||||
- `debug` is disabled by default. Enable it only for investigation and review logs before sharing them outside your organization.
|
||||
|
||||
#### Features
|
||||
|
||||
Security-relevant action features:
|
||||
|
||||
- Package inputs are normalized before cache lookup, which reduces accidental cache divergence from ordering, commas, backslashes, or duplicate whitespace in the package list.
|
||||
- Unpinned package names are resolved to concrete package versions before the cache key is generated, which improves traceability of what was actually cached for a run.
|
||||
- Cache keys are derived from the normalized package set, the user-provided `version`, and the runner architecture, which helps isolate caches across package changes and incompatible platforms.
|
||||
- The action rejects invalid boolean inputs and rejects `version` values containing spaces, reducing ambiguous workflow configuration.
|
||||
- When creating archives, the action records installed package manifests and only archives existing files and symlinks from installed packages, plus maintainer scripts when present.
|
||||
- The `package-version-list` and `all-package-version-list` outputs can be captured by downstream workflow steps for audit logs, attestation inputs, or compliance reporting.
|
||||
|
||||
#### Usage Recommendations
|
||||
|
||||
For GitHub Actions workflow hardening, prefer the following controls around this action:
|
||||
|
||||
- Pin this action to a major version you trust, or to a full commit SHA for stricter supply chain control.
|
||||
- Use the minimum required workflow `permissions` instead of broad defaults.
|
||||
- Run on GitHub-hosted or otherwise trusted runners with controlled APT sources.
|
||||
- Limit who can modify workflow files and package lists through branch protection and pull request review.
|
||||
- Review whether cached APT contents are acceptable for your repository's cache retention policy and data handling requirements.
|
||||
|
||||
Example hardened usage:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: awalsh128/cache-apt-pkgs-action@v2
|
||||
with:
|
||||
packages: curl=8.5.0-2ubuntu10.6 jq=1.7.1-3build1
|
||||
version: ubuntu-24.04-v1
|
||||
empty_packages_behavior: error
|
||||
execute_install_scripts: false
|
||||
```
|
||||
|
||||
### Cache scopes
|
||||
|
||||
The cache is scoped to the packages given and the branch. The default branch cache is available to other branches.
|
||||
|
|
@ -78,7 +136,6 @@ jobs:
|
|||
```
|
||||
|
||||
```yaml
|
||||
|
||||
---
|
||||
install_doxygen_deps:
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
|||
27
V2_FAQ.MD
Normal file
27
V2_FAQ.MD
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# cache-apt-pkgs-action - Version 2 FAQ
|
||||
|
||||
## Why did you create a new version
|
||||
|
||||
### Bash Scripts
|
||||
|
||||
Bash shell scripting grew in complexity and became very unreadable. The action needed higher level language idioms like array and map handling, complex pattern matching, and complex text processing.
|
||||
|
||||
### Language Choice
|
||||
|
||||
Languages like Python, Go, Rust, etc. have performance and writeability trade offs that would greatly improve this action, but ultimately Typescript was chosen because:
|
||||
|
||||
- it is the most performant and well supported for GitHub actions;
|
||||
- native strongly types libraries for action args and actions like caching;
|
||||
- provides a balance of code comprehension for contributors and performance; and
|
||||
- allows for better integration, CI, regression testing, and release workflows.
|
||||
|
||||
## Where did all the APT functionality go?
|
||||
|
||||
Since this has been a complex part of the codebase, I decided to separate the concern as its own library. This can now be found in [npm/ts-apt](https://www.npmjs.com/package/ts-apt). For ease of use there is an option to bring in the workspace for inline source so it can be debugged and then committed to the [ts-apt](http://github.com/awalsh128/ts-apt) repository.
|
||||
|
||||
## How do I start using this?
|
||||
|
||||
> [!IMPORTANT]
|
||||
> This is still in beta so use at your own risk!
|
||||
|
||||
For now you can use the `v2.*` release tags (pinning also supported). Once this version has had time to soak it will be released as the latest. `v1.*` will still get updates but in maintenance mode.
|
||||
110
action.yml
110
action.yml
|
|
@ -1,23 +1,23 @@
|
|||
name: 'Cache APT Packages'
|
||||
description: 'Install APT based packages and cache them for future runs.'
|
||||
name: "Cache APT Packages"
|
||||
description: "Install APT based packages and cache them for future runs."
|
||||
author: awalsh128
|
||||
branding:
|
||||
icon: 'hard-drive'
|
||||
color: 'green'
|
||||
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).'
|
||||
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: ''
|
||||
default: ""
|
||||
version:
|
||||
description: 'Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed.'
|
||||
description: "Version of cache to load. Each version will have its own cache. Note, all characters except spaces are allowed."
|
||||
required: false
|
||||
default: ''
|
||||
default: ""
|
||||
execute_install_scripts:
|
||||
description: 'Execute Debian package pre and post install script upon restore. See README.md caveats for more information.'
|
||||
description: "Execute Debian package pre and post install script upon restore. See README.md caveats for more information."
|
||||
required: false
|
||||
default: 'false'
|
||||
default: "false"
|
||||
empty_packages_behavior:
|
||||
description: >
|
||||
Desired behavior when the provided package list is empty.
|
||||
|
|
@ -27,94 +27,20 @@ inputs:
|
|||
warn: Output a warning without failing the action
|
||||
ignore: Proceed silently without warnings or errors
|
||||
required: false
|
||||
default: 'error'
|
||||
refresh:
|
||||
description: 'OBSOLETE: Refresh is not used by the action, use version instead.'
|
||||
deprecationMessage: 'Refresh is not used by the action, use version instead.'
|
||||
default: "error"
|
||||
debug:
|
||||
description: 'Enable debugging when there are issues with action. Minor performance penalty.'
|
||||
description: "Enable debugging when there are issues with action. Minor performance penalty."
|
||||
required: false
|
||||
default: '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 }}
|
||||
description: "A boolean value to indicate a cache was found for the packages requested."
|
||||
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 }}
|
||||
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>)."
|
||||
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 }}
|
||||
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>)."
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- id: pre-cache
|
||||
run: |
|
||||
${GITHUB_ACTION_PATH}/pre_cache_action.sh \
|
||||
~/cache-apt-pkgs \
|
||||
"$VERSION" \
|
||||
"$EXEC_INSTALL_SCRIPTS" \
|
||||
"$DEBUG" \
|
||||
"$PACKAGES"
|
||||
if [ -f ~/cache-apt-pkgs/cache_key.md5 ]; then
|
||||
echo "CACHE_KEY=$(cat ~/cache-apt-pkgs/cache_key.md5)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "CACHE_KEY=" >> $GITHUB_ENV
|
||||
fi
|
||||
shell: bash
|
||||
env:
|
||||
VERSION: "${{ inputs.version }}"
|
||||
EXEC_INSTALL_SCRIPTS: "${{ inputs.execute_install_scripts }}"
|
||||
EMPTY_PACKAGES_BEHAVIOR: "${{ inputs.empty_packages_behavior }}"
|
||||
DEBUG: "${{ inputs.debug }}"
|
||||
PACKAGES: "${{ inputs.packages }}"
|
||||
|
||||
- id: load-cache
|
||||
if: ${{ env.CACHE_KEY }}
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: ~/cache-apt-pkgs
|
||||
key: cache-apt-pkgs_${{ env.CACHE_KEY }}
|
||||
|
||||
- id: post-cache
|
||||
if: ${{ env.CACHE_KEY }}
|
||||
run: |
|
||||
${GITHUB_ACTION_PATH}/post_cache_action.sh \
|
||||
~/cache-apt-pkgs \
|
||||
/ \
|
||||
"$CACHE_HIT" \
|
||||
"$EXEC_INSTALL_SCRIPTS" \
|
||||
"$DEBUG" \
|
||||
"$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
|
||||
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: ${{ env.CACHE_KEY && 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: ${{ env.CACHE_KEY && ! 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
|
||||
using: "node20"
|
||||
main: "dist/index.js"
|
||||
|
|
|
|||
BIN
apt_query-arm64
BIN
apt_query-arm64
Binary file not shown.
BIN
apt_query-x86
BIN
apt_query-x86
Binary file not shown.
87
dev_scripts/lib.sh
Executable file
87
dev_scripts/lib.sh
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
#!/bin/bash
|
||||
|
||||
LIB_EXIT_CODE=99
|
||||
|
||||
#######################################
|
||||
# Clone a repository and change directory to it.
|
||||
# Arguments:
|
||||
# The repository name.
|
||||
# The directory containing repository to rebase.
|
||||
# The tag to clone from, otherwise use HEAD.
|
||||
# Returns:
|
||||
# 0 if directory was changed, non-zero on error.
|
||||
#######################################
|
||||
function clone_repo {
|
||||
repo_name="${1}"
|
||||
repo_url="https://github.com/awalsh128/${repo_name}"
|
||||
repo_dir="${2}"
|
||||
repo_dir_parent=$(realpath "$(dirname "${repo_dir}")")
|
||||
wd=$(pwd)
|
||||
[[ -d ${repo_dir} ]] && rm -fr "${repo_dir}"
|
||||
cd "${repo_dir_parent}" || exit "${LIB_EXIT_CODE}"
|
||||
if [[ -n "${3}" ]]; then
|
||||
git clone -b "${3}" "${repo_url}"
|
||||
else
|
||||
git clone "${repo_url}"
|
||||
fi
|
||||
cd "${wd}" || exit "${LIB_EXIT_CODE}"
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Clone a repository and change directory to it.
|
||||
# Arguments:
|
||||
# The repository name.
|
||||
# The tag to clone from, otherwise use HEAD.
|
||||
# Returns:
|
||||
# 0 if directory was changed, non-zero on error.
|
||||
#######################################
|
||||
function clone_repo_and_cd {
|
||||
clone_repo "${1}" "/tmp/${1}" "${2}"
|
||||
cd "/tmp/${1}" || exit "${LIB_EXIT_CODE}"
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Yes or no prompt.
|
||||
# Arguments:
|
||||
# Message to display at prompt.
|
||||
# Returns:
|
||||
# None
|
||||
#######################################
|
||||
function confirm_prompt {
|
||||
while true; do
|
||||
read -rp "${1} [Y|n] " response
|
||||
case ${response} in
|
||||
[Yy]*) break;;
|
||||
[Nn]*) exit;;
|
||||
*) echo "Invalid option selected.";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Validate argument and exit if invalid.
|
||||
# Arguments:
|
||||
# Argument to validate.
|
||||
# Message to display on error.
|
||||
# Help message.
|
||||
# Returns:
|
||||
# None
|
||||
#######################################
|
||||
function validate_arg {
|
||||
if [[ -n "${1}" ]] || [[ -z "${1}" ]]; then
|
||||
printf "error: %s\n%s\n" "${2}" "${3}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#######################################
|
||||
# Print out command usage.
|
||||
# Arguments:
|
||||
# Name of command.
|
||||
# Parameters
|
||||
# Returns:
|
||||
# Usage message.
|
||||
#######################################
|
||||
function usage {
|
||||
echo "usage: $(basename "${1}") ${2}"
|
||||
}
|
||||
21
dev_scripts/switch_tsapt_local.sh
Normal file
21
dev_scripts/switch_tsapt_local.sh
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck disable=SC1090
|
||||
source "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
PACKAGE_PATH="${SCRIPT_DIR}/../package.json"
|
||||
LOCAL_VAL="../../ts-apt"
|
||||
NPM_VAL="^ts-apt/$(npm view ts-apt version 2> /dev/null | tr -d '\n')"
|
||||
|
||||
if ! grep -q "\"ts-apt\": \"${LOCAL_VAL}\"," "${PACKAGE_PATH}"; then
|
||||
echo "Switching ts-apt dependency to local path '${LOCAL_VAL}'..."
|
||||
if [[ ! -d "${SCRIPT_DIR}/../ts-apt" ]]; then
|
||||
echo "Local ts-apt path '${LOCAL_VAL}' does not exist. Checking out..."
|
||||
clone_repo "ts-apt" "${SCRIPT_DIR}/../ts-apt"
|
||||
fi
|
||||
sed -i "s#\"ts-apt\": \".*\",#\"ts-apt\": \"${LOCAL_VAL}\",#" "${PACKAGE_PATH}"
|
||||
else
|
||||
echo "Switching ts-apt dependency to NPM version '${NPM_VAL}'..."
|
||||
sed -i "s#\"ts-apt\": \".*\",#\"ts-apt\": \"${NPM_VAL}\",#" "${PACKAGE_PATH}"
|
||||
fi
|
||||
53
dist/action.d.ts
vendored
Normal file
53
dist/action.d.ts
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { type PackageManager, type CommandRunner } from "../../ts-apt/dist/index.js";
|
||||
import winston from "winston";
|
||||
type TarModule = typeof import("tar");
|
||||
type EmptyPackageBehavior = "error" | "warn" | "ignore";
|
||||
interface PackageName {
|
||||
readonly name: string;
|
||||
readonly version?: string;
|
||||
readonly distro?: string;
|
||||
serialize(): string;
|
||||
}
|
||||
export interface ActionInputs {
|
||||
readonly packages: string;
|
||||
readonly version: string;
|
||||
readonly executeInstallScripts: boolean;
|
||||
readonly emptyPackagesBehavior: EmptyPackageBehavior;
|
||||
readonly debug: boolean;
|
||||
}
|
||||
export interface ActionOutputs {
|
||||
readonly cacheHit: boolean;
|
||||
readonly packageVersionList: string;
|
||||
readonly allPackageVersionList: string;
|
||||
}
|
||||
export declare class ActionPackageName implements PackageName {
|
||||
readonly name: string;
|
||||
readonly version?: string | undefined;
|
||||
constructor(name: string, version?: string | undefined);
|
||||
serialize(): string;
|
||||
}
|
||||
export declare function parseBoolean(value: string, fieldName: string): boolean;
|
||||
export declare function normalizeInputPackages(inputPackages: string): string[];
|
||||
export declare class ActionRunner {
|
||||
private readonly commandRunner;
|
||||
private readonly tar;
|
||||
private readonly logger;
|
||||
constructor(commandRunner: CommandRunner, tarModule: TarModule, logger: winston.Logger);
|
||||
parseBoolean(value: string, fieldName: string): boolean;
|
||||
normalizeInputPackages(inputPackages: string): string[];
|
||||
resolvePackageVersion(packageManager: PackageManager, packageName: string): Promise<string>;
|
||||
normalizePackagesWithVersions(packageManager: PackageManager, inputPackages: string): Promise<string[]>;
|
||||
validateEmptyPackages(behavior: EmptyPackageBehavior, packages: string[]): void;
|
||||
getCacheRoot(): string;
|
||||
getCacheKey(normalizedPackages: string[], version: string): Promise<string>;
|
||||
findInstallScript(packageName: string, extension: "preinst" | "postinst", root: string): string | undefined;
|
||||
tarRelativePath(filePath: string): string;
|
||||
buildFileListForPackage(packageManager: PackageManager, packageName: string): Promise<string[]>;
|
||||
updateAptLists(packageManager: PackageManager): Promise<void>;
|
||||
packageSpecifierToName(packageSpecifier: string): string;
|
||||
installAndCachePackages(cacheDir: string, packages: string[], packageManager: PackageManager): Promise<void>;
|
||||
restorePackages(cacheDir: string, executeInstallScripts: boolean): Promise<void>;
|
||||
runAction(inputs: ActionInputs): Promise<ActionOutputs>;
|
||||
}
|
||||
export declare function runAction(inputs: ActionInputs, logger: winston.Logger): Promise<ActionOutputs>;
|
||||
export {};
|
||||
265
dist/action.js
vendored
Normal file
265
dist/action.js
vendored
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { createPackageManager, DefaultCommandRunner, } from "../../ts-apt/dist/index.js";
|
||||
import { isAptListsFresh } from "./io.js";
|
||||
import { readManifestAsCsv, writeManifest } from "./manifest.js";
|
||||
import * as tar from "tar";
|
||||
const FORCE_UPDATE_INCREMENT = "3";
|
||||
const CACHE_DIRNAME = "cache-apt-pkgs";
|
||||
const CACHE_PREFIX = "cache-apt-pkgs_";
|
||||
export class ActionPackageName {
|
||||
name;
|
||||
version;
|
||||
constructor(name, version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
serialize() {
|
||||
return this.version ? `${this.name}=${this.version}` : this.name;
|
||||
}
|
||||
}
|
||||
function toPackageName(packageSpecifier) {
|
||||
const [name, version] = packageSpecifier.split("=");
|
||||
if (!name) {
|
||||
throw new Error("Package name cannot be empty.");
|
||||
}
|
||||
return new ActionPackageName(name, version);
|
||||
}
|
||||
export function parseBoolean(value, fieldName) {
|
||||
if (value === "true") {
|
||||
return true;
|
||||
}
|
||||
if (value === "false") {
|
||||
return false;
|
||||
}
|
||||
throw new Error(`${fieldName} value '${value}' must be either true or false.`);
|
||||
}
|
||||
export function normalizeInputPackages(inputPackages) {
|
||||
return inputPackages
|
||||
.replace(/[,\\]/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.split(" ")
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
export class ActionRunner {
|
||||
commandRunner;
|
||||
tar;
|
||||
logger;
|
||||
constructor(commandRunner, tarModule, logger) {
|
||||
this.commandRunner = commandRunner;
|
||||
this.tar = tarModule;
|
||||
this.logger = logger;
|
||||
}
|
||||
parseBoolean(value, fieldName) {
|
||||
return parseBoolean(value, fieldName);
|
||||
}
|
||||
normalizeInputPackages(inputPackages) {
|
||||
return normalizeInputPackages(inputPackages);
|
||||
}
|
||||
async resolvePackageVersion(packageManager, packageName) {
|
||||
const packageInfo = await packageManager.getPackageInfo([
|
||||
toPackageName(packageName),
|
||||
]);
|
||||
const version = packageInfo[0]?.version;
|
||||
if (!version) {
|
||||
throw new Error(`Unable to resolve package version for '${packageName}'.`);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
async normalizePackagesWithVersions(packageManager, inputPackages) {
|
||||
const raw = this.normalizeInputPackages(inputPackages);
|
||||
const packages = await Promise.all(raw.map(async (pkg) => {
|
||||
if (pkg.includes("=")) {
|
||||
return pkg;
|
||||
}
|
||||
return `${pkg}=${await this.resolvePackageVersion(packageManager, pkg)}`;
|
||||
}));
|
||||
return packages.sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
validateEmptyPackages(behavior, packages) {
|
||||
if (packages.length > 0) {
|
||||
return;
|
||||
}
|
||||
if (behavior === "ignore") {
|
||||
return;
|
||||
}
|
||||
if (behavior === "warn") {
|
||||
process.stdout.write("::warning::Packages argument is empty.\n");
|
||||
return;
|
||||
}
|
||||
throw new Error("Packages argument is empty.");
|
||||
}
|
||||
getCacheRoot() {
|
||||
return path.join(os.homedir(), CACHE_DIRNAME);
|
||||
}
|
||||
async getCacheKey(normalizedPackages, version) {
|
||||
const architecture = (await this.commandRunner.run("arch")).stdout.trim();
|
||||
let value = `${normalizedPackages.join(" ")} @ ${version} ${FORCE_UPDATE_INCREMENT}`;
|
||||
if (architecture !== "x86_64") {
|
||||
value = `${value} ${architecture}`;
|
||||
}
|
||||
const hash = crypto.createHash("md5").update(value).digest("hex");
|
||||
return `${CACHE_PREFIX}${hash}`;
|
||||
}
|
||||
findInstallScript(packageName, extension, root) {
|
||||
const scriptsDir = path.join(root, "var", "lib", "dpkg", "info");
|
||||
if (!fs.existsSync(scriptsDir)) {
|
||||
return undefined;
|
||||
}
|
||||
const pattern = new RegExp(`^${packageName}(:.*)?\\.${extension}$`);
|
||||
const matches = fs
|
||||
.readdirSync(scriptsDir)
|
||||
.filter((entry) => pattern.test(entry))
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
const candidate = matches[0];
|
||||
if (!candidate) {
|
||||
return undefined;
|
||||
}
|
||||
return path.join(scriptsDir, candidate);
|
||||
}
|
||||
tarRelativePath(filePath) {
|
||||
return filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
||||
}
|
||||
async buildFileListForPackage(packageManager, packageName) {
|
||||
const files = (await packageManager.listInstalledFiles(toPackageName(packageName)))
|
||||
.filter((filePath) => {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return false;
|
||||
}
|
||||
const stat = fs.lstatSync(filePath);
|
||||
return stat.isFile() || stat.isSymbolicLink();
|
||||
})
|
||||
.map(this.tarRelativePath);
|
||||
const preinst = this.findInstallScript(packageName, "preinst", "/");
|
||||
const postinst = this.findInstallScript(packageName, "postinst", "/");
|
||||
if (preinst) {
|
||||
files.push(this.tarRelativePath(preinst));
|
||||
}
|
||||
if (postinst) {
|
||||
files.push(this.tarRelativePath(postinst));
|
||||
}
|
||||
return Array.from(new Set(files)).sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
async updateAptLists(packageManager) {
|
||||
if (isAptListsFresh()) {
|
||||
return;
|
||||
}
|
||||
await packageManager.update();
|
||||
}
|
||||
packageSpecifierToName(packageSpecifier) {
|
||||
return packageSpecifier.split("=")[0] ?? packageSpecifier;
|
||||
}
|
||||
async installAndCachePackages(cacheDir, packages, packageManager) {
|
||||
await this.updateAptLists(packageManager);
|
||||
writeManifest(path.join(cacheDir, "manifest_main.log"), packages);
|
||||
const installedPackages = await packageManager.install(packages.map(toPackageName));
|
||||
const manifestAll = [];
|
||||
for (const pkg of installedPackages) {
|
||||
const packageName = pkg.name;
|
||||
const packageVersion = pkg.version;
|
||||
if (!packageName || !packageVersion) {
|
||||
continue;
|
||||
}
|
||||
const archivePath = path.join(cacheDir, `${packageName}=${packageVersion}.tar`);
|
||||
if (!fs.existsSync(archivePath)) {
|
||||
const filesToArchive = await this.buildFileListForPackage(packageManager, packageName);
|
||||
await this.tar.create({
|
||||
cwd: "/",
|
||||
file: archivePath,
|
||||
portable: false,
|
||||
preservePaths: false,
|
||||
follow: false,
|
||||
noDirRecurse: false,
|
||||
}, filesToArchive);
|
||||
}
|
||||
manifestAll.push(`${packageName}=${packageVersion}`);
|
||||
}
|
||||
writeManifest(path.join(cacheDir, "manifest_all.log"), manifestAll);
|
||||
}
|
||||
async restorePackages(cacheDir, executeInstallScripts) {
|
||||
const archives = fs
|
||||
.readdirSync(cacheDir)
|
||||
.filter((entry) => entry.endsWith(".tar"))
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
for (const archive of archives) {
|
||||
const archivePath = path.join(cacheDir, archive);
|
||||
await this.tar.extract({
|
||||
cwd: "/",
|
||||
file: archivePath,
|
||||
preservePaths: true,
|
||||
});
|
||||
if (!executeInstallScripts) {
|
||||
continue;
|
||||
}
|
||||
const packageName = archive.split("=")[0] ?? "";
|
||||
if (!packageName) {
|
||||
continue;
|
||||
}
|
||||
const preinst = this.findInstallScript(packageName, "preinst", "/");
|
||||
if (preinst) {
|
||||
this.logger.info(`Running pre-install script for ${packageName}`);
|
||||
await this.commandRunner.run("sudo", ["sh", "-x", preinst, "install"]);
|
||||
}
|
||||
const postinst = this.findInstallScript(packageName, "postinst", "/");
|
||||
if (postinst) {
|
||||
this.logger.info(`Running post-install script for ${packageName}`);
|
||||
await this.commandRunner.run("sudo", [
|
||||
"sh",
|
||||
"-x",
|
||||
postinst,
|
||||
"configure",
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
async runAction(inputs) {
|
||||
if (/\s/.test(inputs.version)) {
|
||||
throw new Error(`Version value '${inputs.version}' cannot contain spaces.`);
|
||||
}
|
||||
const packageInfoManager = await createPackageManager(false);
|
||||
const normalizedPackages = await this.normalizePackagesWithVersions(packageInfoManager, inputs.packages);
|
||||
this.validateEmptyPackages(inputs.emptyPackagesBehavior, normalizedPackages);
|
||||
const cacheDir = this.getCacheRoot();
|
||||
fs.mkdirSync(cacheDir, { recursive: true });
|
||||
if (normalizedPackages.length === 0) {
|
||||
writeManifest(path.join(cacheDir, "manifest_main.log"), []);
|
||||
writeManifest(path.join(cacheDir, "manifest_all.log"), []);
|
||||
return {
|
||||
cacheHit: false,
|
||||
packageVersionList: "",
|
||||
allPackageVersionList: "",
|
||||
};
|
||||
}
|
||||
const key = await this.getCacheKey(normalizedPackages, inputs.version);
|
||||
fs.writeFileSync(path.join(cacheDir, "cache_key.md5"), key.replace(CACHE_PREFIX, ""), "utf8");
|
||||
const restoredKey = await cache.restoreCache([cacheDir], key);
|
||||
const cacheHit = restoredKey === key;
|
||||
if (cacheHit) {
|
||||
await this.restorePackages(cacheDir, inputs.executeInstallScripts);
|
||||
}
|
||||
else {
|
||||
const installManager = await createPackageManager(true);
|
||||
const installTargets = normalizedPackages.map((packageSpecifier) => this.packageSpecifierToName(packageSpecifier));
|
||||
await this.installAndCachePackages(cacheDir, installTargets, installManager);
|
||||
await cache.saveCache([cacheDir], key);
|
||||
}
|
||||
return {
|
||||
cacheHit,
|
||||
packageVersionList: readManifestAsCsv(path.join(cacheDir, "manifest_main.log")),
|
||||
allPackageVersionList: readManifestAsCsv(path.join(cacheDir, "manifest_all.log")),
|
||||
};
|
||||
}
|
||||
}
|
||||
export async function runAction(inputs, logger) {
|
||||
const packageManager = (await createPackageManager(true, logger, logger));
|
||||
const commandRunner = new DefaultCommandRunner(logger, logger);
|
||||
const actionRunner = new ActionRunner(commandRunner, tar, logger);
|
||||
return await actionRunner.runAction(inputs);
|
||||
}
|
||||
//# sourceMappingURL=action.js.map
|
||||
1
dist/action.js.map
vendored
Normal file
1
dist/action.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/index.d.ts
vendored
Normal file
1
dist/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {};
|
||||
41
dist/index.js
vendored
Normal file
41
dist/index.js
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import * as core from "@actions/core";
|
||||
import { parseBoolean, runAction } from "./action.js";
|
||||
import winston from "winston";
|
||||
function parseEmptyPackagesBehavior(value) {
|
||||
if (value === "error" || value === "warn" || value === "ignore") {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`empty_packages_behavior value '${value}' must be one of: error, warn, ignore.`);
|
||||
}
|
||||
function getInputs() {
|
||||
const executeInstallScriptsRaw = core.getInput("execute_install_scripts");
|
||||
const debugRaw = core.getInput("debug");
|
||||
const emptyPackagesBehaviorRaw = core.getInput("empty_packages_behavior") || "error";
|
||||
return {
|
||||
packages: core.getInput("packages", { required: true }),
|
||||
version: core.getInput("version"),
|
||||
executeInstallScripts: parseBoolean(executeInstallScriptsRaw, "execute_install_scripts"),
|
||||
emptyPackagesBehavior: parseEmptyPackagesBehavior(emptyPackagesBehaviorRaw),
|
||||
debug: parseBoolean(debugRaw, "debug"),
|
||||
};
|
||||
}
|
||||
async function main() {
|
||||
try {
|
||||
const inputs = getInputs();
|
||||
const logger = winston.createLogger({
|
||||
level: inputs.debug ? "debug" : "info",
|
||||
format: winston.format.combine(winston.format.colorize(), winston.format.printf(({ level, message }) => `${level}: ${message}`)),
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
const outputs = await runAction(inputs, logger);
|
||||
core.setOutput("cache-hit", String(outputs.cacheHit));
|
||||
core.setOutput("package-version-list", outputs.packageVersionList);
|
||||
core.setOutput("all-package-version-list", outputs.allPackageVersionList);
|
||||
}
|
||||
catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
core.setFailed(message);
|
||||
}
|
||||
}
|
||||
void main();
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
dist/index.js.map
vendored
Normal file
1
dist/index.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAqB,MAAM,aAAa,CAAC;AACzE,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,SAAS,0BAA0B,CACjC,KAAa;IAEb,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,KAAK,CACb,kCAAkC,KAAK,wCAAwC,CAChF,CAAC;AACJ,CAAC;AAED,SAAS,SAAS;IAChB,MAAM,wBAAwB,GAAG,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC;IAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,wBAAwB,GAC5B,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,IAAI,OAAO,CAAC;IAEtD,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QACvD,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACjC,qBAAqB,EAAE,YAAY,CACjC,wBAAwB,EACxB,yBAAyB,CAC1B;QACD,qBAAqB,EAAE,0BAA0B,CAAC,wBAAwB,CAAC;QAC3E,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC;KACvC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;YAClC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;YACtC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EACzB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,OAAO,EAAE,CAAC,CACtE;YACD,UAAU,EAAE,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC/C,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEhD,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,SAAS,CAAC,sBAAsB,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS,CAAC,0BAA0B,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC5E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,KAAK,IAAI,EAAE,CAAC"}
|
||||
23
dist/io.d.ts
vendored
Normal file
23
dist/io.d.ts
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { type CommandRunner } from "../../ts-apt/dist/index.js";
|
||||
export declare function isAptListsFresh(): boolean;
|
||||
export declare class Package {
|
||||
readonly name: string;
|
||||
readonly version: string;
|
||||
constructor(name: string, version: string);
|
||||
serialize(): string;
|
||||
}
|
||||
export declare class CacheKey {
|
||||
readonly version: string;
|
||||
readonly forceUpdateIncrement: string;
|
||||
readonly arch: string;
|
||||
readonly normalizedPackages: string[];
|
||||
constructor(version: string, forceUpdateIncrement: string, arch: string, normalizedPackages: string[]);
|
||||
serialize(): string;
|
||||
}
|
||||
export declare function deserializeCacheKey(serialized: string): CacheKey;
|
||||
export declare class Cache {
|
||||
private readonly cachePath;
|
||||
private readonly commandRunner;
|
||||
constructor(cacheDir: string | undefined, commandRunner: CommandRunner);
|
||||
getKey(normalizedPackages: string[], version: string): Promise<string>;
|
||||
}
|
||||
88
dist/io.js
vendored
Normal file
88
dist/io.js
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as crypto from "crypto";
|
||||
import * as os from "os";
|
||||
export function isAptListsFresh() {
|
||||
const aptListsPath = "/var/lib/apt/lists";
|
||||
const maxDepth = 5;
|
||||
function search(currentPath, currentDepth) {
|
||||
if (currentDepth > maxDepth)
|
||||
return false;
|
||||
try {
|
||||
const stats = fs.statSync(currentPath);
|
||||
if (stats.isDirectory()) {
|
||||
const entries = fs.readdirSync(currentPath);
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(currentPath, entry);
|
||||
if (search(fullPath, currentDepth + 1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Ignore permission errors or inaccessible paths
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return search(aptListsPath, 0);
|
||||
}
|
||||
export class Package {
|
||||
name;
|
||||
version;
|
||||
constructor(name, version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
serialize() {
|
||||
return `${this.name}@${this.version}`;
|
||||
}
|
||||
}
|
||||
const FORCE_UPDATE_INCREMENT = "4";
|
||||
const CACHE_DIRNAME = "cache-apt-pkgs";
|
||||
const CACHE_PREFIX = "cache-apt-pkgs_";
|
||||
export class CacheKey {
|
||||
version;
|
||||
forceUpdateIncrement;
|
||||
arch;
|
||||
normalizedPackages;
|
||||
constructor(version, forceUpdateIncrement, arch, normalizedPackages) {
|
||||
this.version = version;
|
||||
this.forceUpdateIncrement = forceUpdateIncrement;
|
||||
this.arch = arch;
|
||||
this.normalizedPackages = normalizedPackages;
|
||||
}
|
||||
serialize() {
|
||||
return `${this.version}|${this.forceUpdateIncrement}|${this.arch}|${this.normalizedPackages.join(",")}`;
|
||||
}
|
||||
}
|
||||
export function deserializeCacheKey(serialized) {
|
||||
const parts = serialized.split("|");
|
||||
if (parts.length !== 4) {
|
||||
throw new Error(`Invalid serialized cache key: ${serialized}`);
|
||||
}
|
||||
const [version, forceUpdateIncrement, arch, normalizedPackagesStr] = parts;
|
||||
const normalizedPackages = normalizedPackagesStr.split(",");
|
||||
return new CacheKey(version, forceUpdateIncrement, arch, normalizedPackages);
|
||||
}
|
||||
export class Cache {
|
||||
cachePath;
|
||||
commandRunner;
|
||||
constructor(cacheDir = CACHE_DIRNAME, commandRunner) {
|
||||
this.cachePath = path.join(os.homedir(), cacheDir);
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
async getKey(normalizedPackages, version) {
|
||||
const architecture = await (await this.commandRunner.run("arch")).stdout.trim();
|
||||
let value = `${normalizedPackages.join(" ")} @ ${version} ${FORCE_UPDATE_INCREMENT}`;
|
||||
if (architecture !== "x86_64") {
|
||||
value = `${value} ${architecture}`;
|
||||
}
|
||||
const hash = crypto.createHash("md5").update(value).digest("hex");
|
||||
return `${CACHE_PREFIX}${hash}`;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=io.js.map
|
||||
1
dist/io.js.map
vendored
Normal file
1
dist/io.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"io.js","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,MAAM,UAAU,eAAe;IAC7B,MAAM,YAAY,GAAG,oBAAoB,CAAC;IAC1C,MAAM,QAAQ,GAAG,CAAC,CAAC;IAEnB,SAAS,MAAM,CAAC,WAAmB,EAAE,YAAoB;QACvD,IAAI,YAAY,GAAG,QAAQ;YAAE,OAAO,KAAK,CAAC;QAE1C,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YACvC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;gBAC5C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;oBAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;oBAC/C,IAAI,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;wBACvC,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,iDAAiD;QACnD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,OAAO,OAAO;IAEP;IACA;IAFX,YACW,IAAY,EACZ,OAAe;QADf,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;IACvB,CAAC;IAEJ,SAAS;QACP,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;IACxC,CAAC;CACF;AAED,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,aAAa,GAAG,gBAAgB,CAAC;AACvC,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC,MAAM,OAAO,QAAQ;IAER;IACA;IACA;IACA;IAJX,YACW,OAAe,EACf,oBAA4B,EAC5B,IAAY,EACZ,kBAA4B;QAH5B,YAAO,GAAP,OAAO,CAAQ;QACf,yBAAoB,GAApB,oBAAoB,CAAQ;QAC5B,SAAI,GAAJ,IAAI,CAAQ;QACZ,uBAAkB,GAAlB,kBAAkB,CAAU;IACpC,CAAC;IAEJ,SAAS;QACP,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC1G,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CAAC,UAAkB;IACpD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,iCAAiC,UAAU,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,CAAC,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,qBAAqB,CAAC,GAAG,KAAK,CAAC;IAC3E,MAAM,kBAAkB,GAAG,qBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7D,OAAO,IAAI,QAAQ,CACjB,OAAQ,EACR,oBAAqB,EACrB,IAAK,EACL,kBAAkB,CACnB,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,KAAK;IACC,SAAS,CAAS;IAClB,aAAa,CAAgB;IAE9C,YAAY,WAAmB,aAAa,EAAE,aAA4B;QACxE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,kBAA4B,EAAE,OAAe;QACxD,MAAM,YAAY,GAAG,MAAM,CACzB,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CACrC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,IAAI,KAAK,GAAG,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,IAAI,sBAAsB,EAAE,CAAC;QAErF,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;YAC9B,KAAK,GAAG,GAAG,KAAK,IAAI,YAAY,EAAE,CAAC;QACrC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,OAAO,GAAG,YAAY,GAAG,IAAI,EAAE,CAAC;IAClC,CAAC;CACF"}
|
||||
2
dist/manifest.d.ts
vendored
Normal file
2
dist/manifest.d.ts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export declare function writeManifest(filePath: string, entries: string[]): void;
|
||||
export declare function readManifestAsCsv(filePath: string): string;
|
||||
17
dist/manifest.js
vendored
Normal file
17
dist/manifest.js
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import fs from "node:fs";
|
||||
export function writeManifest(filePath, entries) {
|
||||
const normalized = [...entries].filter(Boolean).sort((a, b) => a.localeCompare(b));
|
||||
fs.writeFileSync(filePath, normalized.join("\n"), "utf8");
|
||||
}
|
||||
export function readManifestAsCsv(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return "";
|
||||
}
|
||||
return fs
|
||||
.readFileSync(filePath, "utf8")
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean)
|
||||
.join(",");
|
||||
}
|
||||
//# sourceMappingURL=manifest.js.map
|
||||
1
dist/manifest.js.map
vendored
Normal file
1
dist/manifest.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,OAAiB;IAC/D,MAAM,UAAU,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,EAAE;SACN,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC;SAC9B,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
||||
9
dist/shell.d.ts
vendored
Normal file
9
dist/shell.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { type SpawnSyncOptions } from "node:child_process";
|
||||
export interface CommandResult {
|
||||
readonly status: number;
|
||||
readonly stdout: string;
|
||||
readonly stderr: string;
|
||||
}
|
||||
export declare function runCommand(command: string, args?: string[], options?: SpawnSyncOptions): CommandResult;
|
||||
export declare function runCommandOrThrow(command: string, args?: string[], options?: SpawnSyncOptions): CommandResult;
|
||||
export declare function fileIsFresh(path: string, withinMinutes: number): boolean;
|
||||
46
dist/shell.js
vendored
Normal file
46
dist/shell.js
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
export function runCommand(command, args = [], options = {}) {
|
||||
const result = spawnSync(command, args, {
|
||||
encoding: "utf8",
|
||||
...options,
|
||||
});
|
||||
const stdout = typeof result.stdout === "string"
|
||||
? result.stdout
|
||||
: result.stdout
|
||||
? result.stdout.toString("utf8")
|
||||
: "";
|
||||
const stderr = typeof result.stderr === "string"
|
||||
? result.stderr
|
||||
: result.stderr
|
||||
? result.stderr.toString("utf8")
|
||||
: "";
|
||||
return {
|
||||
status: result.status ?? 1,
|
||||
stdout,
|
||||
stderr,
|
||||
};
|
||||
}
|
||||
export function runCommandOrThrow(command, args = [], options = {}) {
|
||||
const result = runCommand(command, args, options);
|
||||
if (result.status !== 0) {
|
||||
throw new Error([
|
||||
`Command failed: ${command} ${args.join(" ")}`,
|
||||
`exit: ${result.status}`,
|
||||
result.stdout ? `stdout:\n${result.stdout.trim()}` : "",
|
||||
result.stderr ? `stderr:\n${result.stderr.trim()}` : "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function fileIsFresh(path, withinMinutes) {
|
||||
if (!fs.existsSync(path)) {
|
||||
return false;
|
||||
}
|
||||
const stat = fs.statSync(path);
|
||||
const maxAgeMs = withinMinutes * 60 * 1000;
|
||||
return Date.now() - stat.mtimeMs <= maxAgeMs;
|
||||
}
|
||||
//# sourceMappingURL=shell.js.map
|
||||
1
dist/shell.js.map
vendored
Normal file
1
dist/shell.js.map
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,MAAM,SAAS,CAAC;AAQzB,MAAM,UAAU,UAAU,CACxB,OAAe,EACf,OAAiB,EAAE,EACnB,UAA4B,EAAE;IAE9B,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE;QACtC,QAAQ,EAAE,MAAM;QAChB,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,MAAM,MAAM,GACV,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QAC/B,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YAChC,CAAC,CAAC,EAAE,CAAC;IACX,MAAM,MAAM,GACV,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QAC/B,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YAChC,CAAC,CAAC,EAAE,CAAC;IAEX,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC;QAC1B,MAAM;QACN,MAAM;KACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,OAAe,EACf,OAAiB,EAAE,EACnB,UAA4B,EAAE;IAE9B,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb;YACE,mBAAmB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC9C,SAAS,MAAM,CAAC,MAAM,EAAE;YACxB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;YACvD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;SACxD;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,aAAqB;IAC7D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,aAAa,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC;AAC/C,CAAC"}
|
||||
16
eslint.config.js
Normal file
16
eslint.config.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import tsParser from "@typescript-eslint/parser";
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: ["dist/**", "node_modules/**", "target/**"],
|
||||
},
|
||||
{
|
||||
files: ["src/**/*.ts", "test/**/*.ts"],
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
},
|
||||
rules: {},
|
||||
},
|
||||
];
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Fail on any error.
|
||||
set -e
|
||||
|
||||
# Debug mode for diagnosing issues.
|
||||
# Setup first before other operations.
|
||||
debug="${2}"
|
||||
test "${debug}" = "true" && set -x
|
||||
|
||||
# Include library.
|
||||
script_dir="$(dirname -- "$(realpath -- "${0}")")"
|
||||
source "${script_dir}/lib.sh"
|
||||
|
||||
# Directory that holds the cached packages.
|
||||
cache_dir="${1}"
|
||||
|
||||
# List of the packages to use.
|
||||
input_packages="${@:3}"
|
||||
|
||||
if ! apt-fast --version > /dev/null 2>&1; then
|
||||
log "Installing apt-fast for optimized installs..."
|
||||
# Install apt-fast for optimized installs.
|
||||
/bin/bash -c "$(curl -sL https://raw.githubusercontent.com/ilikenwf/apt-fast/master/quick-install.sh)"
|
||||
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
|
||||
log "done"
|
||||
else
|
||||
log "skipped (fresh within at least 5 minutes)"
|
||||
fi
|
||||
|
||||
log_empty_line
|
||||
|
||||
packages="$(get_normalized_package_list "${input_packages}")"
|
||||
package_count=$(wc -w <<< "${packages}")
|
||||
log "Clean installing and caching ${package_count} package(s)."
|
||||
|
||||
log_empty_line
|
||||
|
||||
manifest_main=""
|
||||
log "Package list:"
|
||||
for package in ${packages}; do
|
||||
manifest_main="${manifest_main}${package},"
|
||||
log "- ${package}"
|
||||
done
|
||||
write_manifest "main" "${manifest_main}" "${cache_dir}/manifest_main.log"
|
||||
|
||||
log_empty_line
|
||||
|
||||
# Strictly contains the requested packages.
|
||||
manifest_main=""
|
||||
# Contains all packages including dependencies.
|
||||
manifest_all=""
|
||||
|
||||
install_log_filepath="${cache_dir}/install.log"
|
||||
|
||||
log "Clean installing ${package_count} packages..."
|
||||
# Zero interaction while installing or upgrading the system via apt.
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-fast --yes install ${packages} > "${install_log_filepath}"
|
||||
log "done"
|
||||
log "Installation log written to ${install_log_filepath}"
|
||||
|
||||
log_empty_line
|
||||
|
||||
installed_packages=$(get_installed_packages "${install_log_filepath}")
|
||||
log "Installed package list:"
|
||||
for installed_package in ${installed_packages}; do
|
||||
# Reformat for human friendly reading.
|
||||
log "- $(echo ${installed_package} | awk -F\= '{print $1" ("$2")"}')"
|
||||
done
|
||||
|
||||
log_empty_line
|
||||
|
||||
installed_packages_count=$(wc -w <<< "${installed_packages}")
|
||||
log "Caching ${installed_packages_count} installed packages..."
|
||||
for installed_package in ${installed_packages}; do
|
||||
cache_filepath="${cache_dir}/${installed_package}.tar"
|
||||
|
||||
# Sanity test in case APT enumerates duplicates.
|
||||
if test ! -f "${cache_filepath}"; then
|
||||
read package_name package_ver < <(get_package_name_ver "${installed_package}")
|
||||
log " * Caching ${package_name} to ${cache_filepath}..."
|
||||
|
||||
# Pipe all package files (no folders) and installation control data to Tar.
|
||||
tar -cf "${cache_filepath}" -C / --verbatim-files-from --files-from <( { dpkg -L "${package_name}" &&
|
||||
get_install_script_filepath "" "${package_name}" "preinst" &&
|
||||
get_install_script_filepath "" "${package_name}" "postinst" ;} |
|
||||
while IFS= read -r f; do test -f "${f}" -o -L "${f}" && get_tar_relpath "${f}"; done )
|
||||
|
||||
log " done (compressed size $(du -h "${cache_filepath}" | cut -f1))."
|
||||
fi
|
||||
|
||||
# Comma delimited name:ver pairs in the all packages manifest.
|
||||
manifest_all="${manifest_all}${package_name}=${package_ver},"
|
||||
done
|
||||
log "done (total cache size $(du -h ${cache_dir} | tail -1 | awk '{print $1}'))"
|
||||
|
||||
log_empty_line
|
||||
|
||||
write_manifest "all" "${manifest_all}" "${cache_dir}/manifest_all.log"
|
||||
178
lib.sh
178
lib.sh
|
|
@ -1,178 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Don't fail on error. We use the exit status as a conditional.
|
||||
#
|
||||
# This is the default behavior but can be overridden by the caller in the
|
||||
# SHELLOPTS env var.
|
||||
set +e
|
||||
|
||||
###############################################################################
|
||||
# Execute the Debian install script.
|
||||
# Arguments:
|
||||
# Root directory to search from.
|
||||
# File path to cached package archive.
|
||||
# Installation script extension (preinst, postinst).
|
||||
# Parameter to pass to the installation script.
|
||||
# Returns:
|
||||
# Filepath of the install script, otherwise an empty string.
|
||||
###############################################################################
|
||||
function execute_install_script {
|
||||
local package_name=$(basename ${2} | awk -F\= '{print $1}')
|
||||
local install_script_filepath=$(\
|
||||
get_install_script_filepath "${1}" "${package_name}" "${3}")
|
||||
if test ! -z "${install_script_filepath}"; then
|
||||
log "- Executing ${install_script_filepath}..."
|
||||
# Don't abort on errors; dpkg-trigger will error normally since it is
|
||||
# outside its run environment.
|
||||
sudo sh -x ${install_script_filepath} ${4} || true
|
||||
log " done"
|
||||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Gets the Debian install script filepath.
|
||||
# Arguments:
|
||||
# Root directory to search from.
|
||||
# Name of the unqualified package to search for.
|
||||
# Extension of the installation script (preinst, postinst)
|
||||
# Returns:
|
||||
# Filepath of the script file, otherwise an empty string.
|
||||
###############################################################################
|
||||
function get_install_script_filepath {
|
||||
# Filename includes arch (e.g. amd64).
|
||||
local filepath="$(\
|
||||
ls -1 ${1}var/lib/dpkg/info/${2}*.${3} 2> /dev/null \
|
||||
| grep -E ${2}'(:.*)?.'${3} | head -1 || true)"
|
||||
test "${filepath}" && echo "${filepath}"
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Gets a list of installed packages from a Debian package installation log.
|
||||
# Arguments:
|
||||
# The filepath of the Debian install log.
|
||||
# Returns:
|
||||
# The list of colon delimited action syntax pairs with each pair equals
|
||||
# delimited. <name>:<version> <name>:<version>...
|
||||
###############################################################################
|
||||
function get_installed_packages {
|
||||
local install_log_filepath="${1}"
|
||||
local regex="^Unpacking ([^ :]+)([^ ]+)? (\[[^ ]+\]\s)?\(([^ )]+)"
|
||||
local dep_packages=""
|
||||
while read -r line; do
|
||||
# ${regex} should be unquoted since it isn't a literal.
|
||||
if [[ "${line}" =~ ${regex} ]]; then
|
||||
dep_packages="${dep_packages}${BASH_REMATCH[1]}=${BASH_REMATCH[4]} "
|
||||
else
|
||||
log_err "Unable to parse package name and version from \"${line}\""
|
||||
exit 2
|
||||
fi
|
||||
done < <(grep "^Unpacking " ${install_log_filepath})
|
||||
if test -n "${dep_packages}"; then
|
||||
echo "${dep_packages:0:-1}" # Removing trailing space.
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Splits a fully action syntax APT package into the name and version.
|
||||
# Arguments:
|
||||
# The action syntax equals delimited package pair or just the package name.
|
||||
# Returns:
|
||||
# The package name and version pair.
|
||||
###############################################################################
|
||||
function get_package_name_ver {
|
||||
local ORIG_IFS="${IFS}"
|
||||
IFS=\= read name ver <<< "${1}"
|
||||
IFS="${ORIG_IFS}"
|
||||
# If version not found in the fully qualified package value.
|
||||
if test -z "${ver}"; then
|
||||
# This is a fallback and should not be used any more as its slow.
|
||||
log_err "Unexpected version resolution for package '${name}'"
|
||||
ver="$(apt-cache show ${name} | grep '^Version:' | awk '{print $2}')"
|
||||
fi
|
||||
echo "${name}" "${ver}"
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Sorts given packages by name and split on commas and/or spaces.
|
||||
# Arguments:
|
||||
# The comma and/or space delimited list of packages.
|
||||
# Returns:
|
||||
# Sorted list of space delimited package name=version pairs.
|
||||
###############################################################################
|
||||
function get_normalized_package_list {
|
||||
# Remove commas, and block scalar folded backslashes,
|
||||
# extraneous spaces at the middle, beginning and end
|
||||
# then sort.
|
||||
local packages=$(echo "${1}" \
|
||||
| sed 's/[,\]/ /g; s/\s\+/ /g; s/^\s\+//g; s/\s\+$//g' \
|
||||
| sort -t' ')
|
||||
local script_dir="$(dirname -- "$(realpath -- "${0}")")"
|
||||
|
||||
local architecture=$(dpkg --print-architecture)
|
||||
if [ "${architecture}" == "arm64" ]; then
|
||||
${script_dir}/apt_query-arm64 normalized-list ${packages}
|
||||
else
|
||||
${script_dir}/apt_query-x86 normalized-list ${packages}
|
||||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Gets the relative filepath acceptable by Tar. Just removes the leading slash
|
||||
# that Tar disallows.
|
||||
# Arguments:
|
||||
# Absolute filepath to archive.
|
||||
# Returns:
|
||||
# The relative filepath to archive.
|
||||
###############################################################################
|
||||
function get_tar_relpath {
|
||||
local filepath=${1}
|
||||
if test ${filepath:0:1} = "/"; then
|
||||
echo "${filepath:1}"
|
||||
else
|
||||
echo "${filepath}"
|
||||
fi
|
||||
}
|
||||
|
||||
function log { echo "${@}"; }
|
||||
function log_err { >&2 echo "${@}"; }
|
||||
|
||||
function log_empty_line { echo ""; }
|
||||
|
||||
###############################################################################
|
||||
# Validates an argument to be of a boolean value.
|
||||
# Arguments:
|
||||
# Argument to validate.
|
||||
# Variable name of the argument.
|
||||
# Exit code if validation fails.
|
||||
# Returns:
|
||||
# Sorted list of space delimited packages.
|
||||
###############################################################################
|
||||
function validate_bool {
|
||||
if test "${1}" != "true" -a "${1}" != "false"; then
|
||||
log "aborted"
|
||||
log "${2} value '${1}' must be either true or false (case sensitive)."
|
||||
exit ${3}
|
||||
fi
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Writes the manifest to a specified file.
|
||||
# Arguments:
|
||||
# Type of manifest being written.
|
||||
# List of packages being written to the file.
|
||||
# File path of the manifest being written.
|
||||
# Returns:
|
||||
# Log lines from write.
|
||||
###############################################################################
|
||||
function write_manifest {
|
||||
if [ ${#2} -eq 0 ]; then
|
||||
log "Skipped ${1} manifest write. No packages to install."
|
||||
else
|
||||
log "Writing ${1} packages manifest to ${3}..."
|
||||
# 0:-1 to remove trailing comma, delimit by newline and sort.
|
||||
echo "${2:0:-1}" | tr ',' '\n' | sort > ${3}
|
||||
log "done"
|
||||
fi
|
||||
}
|
||||
3950
package-lock.json
generated
Normal file
3950
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
39
package.json
Normal file
39
package.json
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "cache-apt-pkgs-action",
|
||||
"version": "2.0.0",
|
||||
"private": true,
|
||||
"description": "GitHub Action to install and cache APT packages",
|
||||
"author": "Andrew Walsh",
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare:ts-apt": "cd ../ts-apt && npx tsc -p tsconfig.build.json",
|
||||
"postinstall": "npm run prepare:ts-apt",
|
||||
"prelint": "npm run prepare:ts-apt",
|
||||
"pretypecheck": "npm run prepare:ts-apt",
|
||||
"pretest": "npm run prepare:ts-apt",
|
||||
"prebuild": "npm run prepare:ts-apt",
|
||||
"build": "tsc -p tsconfig.build.json",
|
||||
"clean": "rm -rf dist coverage",
|
||||
"lint": "eslint src test --ext .ts",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/cache": "^6.1.0",
|
||||
"@actions/core": "^1.11.1",
|
||||
"tar": "^7.4.3",
|
||||
"ts-apt": "file:../ts-apt",
|
||||
"winston": "^3.19.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.15.30",
|
||||
"@typescript-eslint/parser": "^8.46.3",
|
||||
"eslint": "^9.31.0",
|
||||
"typescript": "^5.8.3",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Fail on any error.
|
||||
set -e
|
||||
|
||||
# Include library.
|
||||
script_dir="$(dirname -- "$(realpath -- "${0}")")"
|
||||
source "${script_dir}/lib.sh"
|
||||
|
||||
# Directory that holds the cached packages.
|
||||
cache_dir="${1}"
|
||||
|
||||
# Root directory to untar the cached packages to.
|
||||
# Typically filesystem root '/' but can be changed for testing.
|
||||
# WARNING: If non-root, this can cause errors during install script execution.
|
||||
cache_restore_root="${2}"
|
||||
|
||||
# Indicates that the cache was found.
|
||||
cache_hit="${3}"
|
||||
|
||||
# Cache and execute post install scripts on restore.
|
||||
execute_install_scripts="${4}"
|
||||
|
||||
# Debug mode for diagnosing issues.
|
||||
debug="${5}"
|
||||
test "${debug}" = "true" && set -x
|
||||
|
||||
# List of the packages to use.
|
||||
packages="${@:6}"
|
||||
|
||||
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}
|
||||
fi
|
||||
|
||||
log_empty_line
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Include library.
|
||||
script_dir="$(dirname -- "$(realpath -- "${0}")")"
|
||||
source "${script_dir}/lib.sh"
|
||||
|
||||
# Debug mode for diagnosing issues.
|
||||
# Setup first before other operations.
|
||||
debug="${4}"
|
||||
validate_bool "${debug}" debug 1
|
||||
test ${debug} == "true" && set -x
|
||||
|
||||
# Directory that holds the cached packages.
|
||||
cache_dir="${1}"
|
||||
|
||||
# Version of the cache to create or load.
|
||||
version="${2}"
|
||||
|
||||
# Execute post-installation script.
|
||||
execute_install_scripts="${3}"
|
||||
|
||||
# Debug mode for diagnosing issues.
|
||||
debug="${4}"
|
||||
|
||||
# List of the packages to use.
|
||||
input_packages="${@:5}"
|
||||
|
||||
# Trim commas, excess spaces, and sort.
|
||||
log "Normalizing package list..."
|
||||
packages="$(get_normalized_package_list "${input_packages}")"
|
||||
log "done"
|
||||
|
||||
# Create cache directory so artifacts can be saved.
|
||||
mkdir -p ${cache_dir}
|
||||
|
||||
log "Validating action arguments (version='${version}', packages='${packages}')...";
|
||||
if grep -q " " <<< "${version}"; then
|
||||
log "aborted"
|
||||
log "Version value '${version}' cannot contain spaces." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Is length of string zero?
|
||||
if test -z "${packages}"; then
|
||||
case "$EMPTY_PACKAGES_BEHAVIOR" in
|
||||
ignore)
|
||||
exit 0
|
||||
;;
|
||||
warn)
|
||||
echo "::warning::Packages argument is empty."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log "aborted"
|
||||
log "Packages argument is empty." >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
validate_bool "${execute_install_scripts}" execute_install_scripts 4
|
||||
|
||||
log "done"
|
||||
|
||||
log_empty_line
|
||||
|
||||
# Abort on any failure at this point.
|
||||
set -e
|
||||
|
||||
log "Creating cache key..."
|
||||
|
||||
# Forces an update in cases where an accidental breaking change was introduced
|
||||
# and a global cache reset is required, or change in cache action requiring reload.
|
||||
force_update_inc="3"
|
||||
|
||||
# Force a different cache key for different architectures (currently x86_64 and aarch64 are available on GitHub)
|
||||
cpu_arch="$(arch)"
|
||||
log "- CPU architecture is '${cpu_arch}'."
|
||||
|
||||
value="${packages} @ ${version} ${force_update_inc}"
|
||||
|
||||
# Don't invalidate existing caches for the standard Ubuntu runners
|
||||
if [ "${cpu_arch}" != "x86_64" ]; then
|
||||
value="${value} ${cpu_arch}"
|
||||
log "- Architecture '${cpu_arch}' added to value."
|
||||
fi
|
||||
|
||||
log "- Value to hash is '${value}'."
|
||||
|
||||
key="$(echo "${value}" | md5sum | cut -f1 -d' ')"
|
||||
log "- Value hashed as '${key}'."
|
||||
|
||||
log "done"
|
||||
|
||||
key_filepath="${cache_dir}/cache_key.md5"
|
||||
echo ${key} > ${key_filepath}
|
||||
log "Hash value written to ${key_filepath}"
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Fail on any error.
|
||||
set -e
|
||||
|
||||
# Debug mode for diagnosing issues.
|
||||
# Setup first before other operations.
|
||||
debug="${4}"
|
||||
test ${debug} == "true" && set -x
|
||||
|
||||
# Include library.
|
||||
script_dir="$(dirname -- "$(realpath -- "${0}")")"
|
||||
source "${script_dir}/lib.sh"
|
||||
|
||||
# Directory that holds the cached packages.
|
||||
cache_dir="${1}"
|
||||
|
||||
# Root directory to untar the cached packages to.
|
||||
# Typically filesystem root '/' but can be changed for testing.
|
||||
cache_restore_root="${2}"
|
||||
test -d ${cache_restore_root} || mkdir ${cache_restore_root}
|
||||
|
||||
# Cache and execute post install scripts on restore.
|
||||
execute_install_scripts="${3}"
|
||||
|
||||
cache_filepaths="$(ls -1 "${cache_dir}" | sort)"
|
||||
log "Found $(echo ${cache_filepaths} | wc -w) files in the cache."
|
||||
for cache_filepath in ${cache_filepaths}; do
|
||||
log "- "$(basename ${cache_filepath})""
|
||||
done
|
||||
|
||||
log_empty_line
|
||||
|
||||
log "Reading from main requested packages manifest..."
|
||||
for logline in $(cat "${cache_dir}/manifest_main.log" | tr ',' '\n' ); do
|
||||
log "- $(echo "${logline}" | tr ':' ' ')"
|
||||
done
|
||||
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_filecount=$(echo ${cached_filepaths} | wc -w)
|
||||
|
||||
log "Restoring ${cached_filecount} packages from cache..."
|
||||
for cached_filepath in ${cached_filepaths}; do
|
||||
|
||||
log "- $(basename "${cached_filepath}") restoring..."
|
||||
sudo tar -xf "${cached_filepath}" -C "${cache_restore_root}" > /dev/null
|
||||
log " done"
|
||||
|
||||
# Execute install scripts if available.
|
||||
if test ${execute_install_scripts} == "true"; then
|
||||
# May have to add more handling for extracting pre-install script before extracting all files.
|
||||
# Keeping it simple for now.
|
||||
execute_install_script "${cache_restore_root}" "${cached_filepath}" preinst install
|
||||
execute_install_script "${cache_restore_root}" "${cached_filepath}" postinst configure
|
||||
fi
|
||||
done
|
||||
log "done"
|
||||
420
src/action.ts
Normal file
420
src/action.ts
Normal file
|
|
@ -0,0 +1,420 @@
|
|||
import cache from "@actions/cache";
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import {
|
||||
createPackageManager,
|
||||
type AptPackageManager,
|
||||
type PackageManager,
|
||||
type CommandRunner,
|
||||
DefaultCommandRunner,
|
||||
} from "../../ts-apt/dist/index.js";
|
||||
import { isAptListsFresh } from "./io.js";
|
||||
import { readManifest, writeManifest } from "./manifest.js";
|
||||
import * as tar from "tar";
|
||||
import winston from "winston";
|
||||
|
||||
type TarModule = typeof import("tar");
|
||||
|
||||
type EmptyPackageBehavior = "error" | "warn" | "ignore";
|
||||
|
||||
export interface ActionInputs {
|
||||
readonly packages: string;
|
||||
readonly version: string;
|
||||
readonly executeInstallScripts: boolean;
|
||||
readonly emptyPackagesBehavior: EmptyPackageBehavior;
|
||||
readonly debug: boolean;
|
||||
}
|
||||
|
||||
export interface ActionOutputs {
|
||||
readonly cacheHit: boolean;
|
||||
readonly packageVersionList: string;
|
||||
readonly allPackageVersionList: string;
|
||||
}
|
||||
|
||||
export class ActionPackageName implements Comparable<ActionPackageName> {
|
||||
constructor(
|
||||
readonly name: string,
|
||||
readonly version?: string,
|
||||
) {}
|
||||
|
||||
serialize() {
|
||||
if (this.version) {
|
||||
return this.name + "=" + this.version;
|
||||
}
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
export function deserializePackageName(text: string): ActionPackageName | null {
|
||||
const [name, version] = text.split("=");
|
||||
if (!name) {
|
||||
return null;
|
||||
}
|
||||
return new ActionPackageName(name, version);
|
||||
}
|
||||
|
||||
export function parseBoolean(value: string, fieldName: string): boolean {
|
||||
if (value === "true") {
|
||||
return true;
|
||||
}
|
||||
if (value === "false") {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`${fieldName} value '${value}' must be either true or false.`,
|
||||
);
|
||||
}
|
||||
|
||||
export function normalizeInputPackages(
|
||||
inputPackages: string,
|
||||
): ActionPackageName[] {
|
||||
return inputPackages
|
||||
.replace(/[,\\]/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.split(" ")
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((part) => deserializePackageName(part))
|
||||
.filter((pkg): pkg is ActionPackageName => pkg !== null);
|
||||
}
|
||||
|
||||
export class ActionRunner {
|
||||
private readonly commandRunner: CommandRunner;
|
||||
private readonly tar: TarModule;
|
||||
private readonly logger: winston.Logger;
|
||||
|
||||
constructor(
|
||||
commandRunner: CommandRunner,
|
||||
tarModule: TarModule,
|
||||
logger: winston.Logger,
|
||||
) {
|
||||
this.commandRunner = commandRunner;
|
||||
this.tar = tarModule;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
parseBoolean(value: string, fieldName: string): boolean {
|
||||
return parseBoolean(value, fieldName);
|
||||
}
|
||||
|
||||
normalizeInputPackages(inputPackages: string): ActionPackageName[] {
|
||||
return normalizeInputPackages(inputPackages);
|
||||
}
|
||||
|
||||
async resolvePackageVersion(
|
||||
packageManager: PackageManager,
|
||||
packageName: string,
|
||||
): Promise<string> {
|
||||
const packageInfo = await packageManager.getPackageInfo([packageName]);
|
||||
const version = packageInfo[0]?.version;
|
||||
if (!version) {
|
||||
throw new Error(
|
||||
`Unable to resolve package version for '${packageName}'.`,
|
||||
);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
async normalizePackagesWithVersions(
|
||||
packageManager: PackageManager,
|
||||
inputPackages: string,
|
||||
): Promise<ActionPackageName[]> {
|
||||
const raw = this.normalizeInputPackages(inputPackages);
|
||||
const packages = await Promise.all(
|
||||
raw.map(async (pkg) => {
|
||||
if (pkg.version) {
|
||||
return pkg.serialize();
|
||||
}
|
||||
return `${pkg.name}=${await this.resolvePackageVersion(packageManager, pkg.name)}`;
|
||||
}),
|
||||
);
|
||||
|
||||
return packages.sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
validateEmptyPackages(
|
||||
behavior: EmptyPackageBehavior,
|
||||
packages: string[],
|
||||
): void {
|
||||
if (packages.length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (behavior === "ignore") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (behavior === "warn") {
|
||||
process.stdout.write("::warning::Packages argument is empty.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error("Packages argument is empty.");
|
||||
}
|
||||
|
||||
getCacheRoot(): string {
|
||||
return path.join(os.homedir(), CACHE_DIRNAME);
|
||||
}
|
||||
|
||||
async getCacheKey(
|
||||
normalizedPackages: string[],
|
||||
version: string,
|
||||
): Promise<string> {
|
||||
const architecture = await (
|
||||
await this.commandRunner.run("arch")
|
||||
).stdout.trim();
|
||||
let value = `${normalizedPackages.join(" ")} @ ${version} ${FORCE_UPDATE_INCREMENT}`;
|
||||
|
||||
if (architecture !== "x86_64") {
|
||||
value = `${value} ${architecture}`;
|
||||
}
|
||||
|
||||
const hash = crypto.createHash("md5").update(value).digest("hex");
|
||||
return `${CACHE_PREFIX}${hash}`;
|
||||
}
|
||||
|
||||
findInstallScript(
|
||||
packageName: string,
|
||||
extension: "preinst" | "postinst",
|
||||
root: string,
|
||||
): string | undefined {
|
||||
const scriptsDir = path.join(root, "var", "lib", "dpkg", "info");
|
||||
if (!fs.existsSync(scriptsDir)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const pattern = new RegExp(`^${packageName}(:.*)?\\.${extension}$`);
|
||||
const matches = fs
|
||||
.readdirSync(scriptsDir)
|
||||
.filter((entry) => pattern.test(entry))
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
const candidate = matches[0];
|
||||
if (!candidate) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return path.join(scriptsDir, candidate);
|
||||
}
|
||||
|
||||
tarRelativePath(filePath: string): string {
|
||||
return filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
||||
}
|
||||
|
||||
async buildFileListForPackage(
|
||||
packageManager: PackageManager,
|
||||
packageName: string,
|
||||
): Promise<string[]> {
|
||||
const files = (await packageManager.listInstalledFiles(packageName))
|
||||
.filter((filePath) => {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const stat = fs.lstatSync(filePath);
|
||||
return stat.isFile() || stat.isSymbolicLink();
|
||||
})
|
||||
.map(this.tarRelativePath);
|
||||
|
||||
const preinst = this.findInstallScript(packageName, "preinst", "/");
|
||||
const postinst = this.findInstallScript(packageName, "postinst", "/");
|
||||
|
||||
if (preinst) {
|
||||
files.push(this.tarRelativePath(preinst));
|
||||
}
|
||||
if (postinst) {
|
||||
files.push(this.tarRelativePath(postinst));
|
||||
}
|
||||
|
||||
return Array.from(new Set(files)).sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
async updateAptLists(packageManager: PackageManager): Promise<void> {
|
||||
if (isAptListsFresh()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await packageManager.update();
|
||||
}
|
||||
|
||||
packageSpecifierToName(packageSpecifier: string): string {
|
||||
return packageSpecifier.split("=")[0] ?? packageSpecifier;
|
||||
}
|
||||
|
||||
async installAndCachePackages(
|
||||
cacheDir: string,
|
||||
packages: string[],
|
||||
packageManager: PackageManager,
|
||||
): Promise<void> {
|
||||
await this.updateAptLists(packageManager);
|
||||
|
||||
writeManifest(path.join(cacheDir, "manifest_main.log"), packages);
|
||||
|
||||
const installedPackages = await packageManager.install(packages);
|
||||
|
||||
const manifestAll: string[] = [];
|
||||
for (const pkg of installedPackages) {
|
||||
const packageName = pkg.name;
|
||||
const packageVersion = pkg.version;
|
||||
if (!packageName || !packageVersion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const archivePath = path.join(
|
||||
cacheDir,
|
||||
`${packageName}=${packageVersion}.tar`,
|
||||
);
|
||||
if (!fs.existsSync(archivePath)) {
|
||||
const filesToArchive = await this.buildFileListForPackage(
|
||||
packageManager,
|
||||
packageName,
|
||||
);
|
||||
await this.tar.create(
|
||||
{
|
||||
cwd: "/",
|
||||
file: archivePath,
|
||||
portable: false,
|
||||
preservePaths: false,
|
||||
follow: false,
|
||||
noDirRecurse: false,
|
||||
},
|
||||
filesToArchive,
|
||||
);
|
||||
}
|
||||
|
||||
manifestAll.push(`${packageName}=${packageVersion}`);
|
||||
}
|
||||
|
||||
writeManifest(path.join(cacheDir, "manifest_all.log"), manifestAll);
|
||||
}
|
||||
|
||||
async restorePackages(
|
||||
cacheDir: string,
|
||||
executeInstallScripts: boolean,
|
||||
): Promise<void> {
|
||||
const archives = fs
|
||||
.readdirSync(cacheDir)
|
||||
.filter((entry) => entry.endsWith(".tar"))
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
for (const archive of archives) {
|
||||
const archivePath = path.join(cacheDir, archive);
|
||||
await this.tar.extract({
|
||||
cwd: "/",
|
||||
file: archivePath,
|
||||
preservePaths: true,
|
||||
});
|
||||
|
||||
if (!executeInstallScripts) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const packageName = archive.split("=")[0] ?? "";
|
||||
if (!packageName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const preinst = this.findInstallScript(packageName, "preinst", "/");
|
||||
if (preinst) {
|
||||
this.logger.info(`Running pre-install script for ${packageName}`);
|
||||
await this.commandRunner.run("sudo", ["sh", "-x", preinst, "install"]);
|
||||
}
|
||||
|
||||
const postinst = this.findInstallScript(packageName, "postinst", "/");
|
||||
if (postinst) {
|
||||
this.logger.info(`Running post-install script for ${packageName}`);
|
||||
await this.commandRunner.run("sudo", [
|
||||
"sh",
|
||||
"-x",
|
||||
postinst,
|
||||
"configure",
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async runAction(inputs: ActionInputs): Promise<ActionOutputs> {
|
||||
if (/\s/.test(inputs.version)) {
|
||||
throw new Error(
|
||||
`Version value '${inputs.version}' cannot contain spaces.`,
|
||||
);
|
||||
}
|
||||
|
||||
const packageInfoManager = await createPackageManager(false);
|
||||
const normalizedPackages = await this.normalizePackagesWithVersions(
|
||||
packageInfoManager,
|
||||
inputs.packages,
|
||||
);
|
||||
this.validateEmptyPackages(
|
||||
inputs.emptyPackagesBehavior,
|
||||
normalizedPackages,
|
||||
);
|
||||
|
||||
const cacheDir = this.getCacheRoot();
|
||||
fs.mkdirSync(cacheDir, { recursive: true });
|
||||
|
||||
if (normalizedPackages.length === 0) {
|
||||
writeManifest(path.join(cacheDir, "manifest_main.log"), []);
|
||||
writeManifest(path.join(cacheDir, "manifest_all.log"), []);
|
||||
return {
|
||||
cacheHit: false,
|
||||
packageVersionList: "",
|
||||
allPackageVersionList: "",
|
||||
};
|
||||
}
|
||||
|
||||
const key = await this.getCacheKey(normalizedPackages, inputs.version);
|
||||
fs.writeFileSync(
|
||||
path.join(cacheDir, "cache_key.md5"),
|
||||
key.replace(CACHE_PREFIX, ""),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const restoredKey = await cache.restoreCache([cacheDir], key);
|
||||
const cacheHit = restoredKey === key;
|
||||
|
||||
if (cacheHit) {
|
||||
await this.restorePackages(cacheDir, inputs.executeInstallScripts);
|
||||
} else {
|
||||
const installManager = await createPackageManager(true);
|
||||
const installTargets = normalizedPackages.map((packageSpecifier) =>
|
||||
this.packageSpecifierToName(packageSpecifier),
|
||||
);
|
||||
await this.installAndCachePackages(
|
||||
cacheDir,
|
||||
installTargets,
|
||||
installManager,
|
||||
);
|
||||
await cache.saveCache([cacheDir], key);
|
||||
}
|
||||
|
||||
return {
|
||||
cacheHit,
|
||||
packageVersionList: readManifest(
|
||||
path.join(cacheDir, "manifest_main.log"),
|
||||
),
|
||||
allPackageVersionList: readManifest(
|
||||
path.join(cacheDir, "manifest_all.log"),
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function runAction(
|
||||
inputs: ActionInputs,
|
||||
logger: winston.Logger,
|
||||
): Promise<ActionOutputs> {
|
||||
const packageManager = (await createPackageManager(
|
||||
true,
|
||||
logger,
|
||||
logger,
|
||||
)) as AptPackageManager;
|
||||
const commandRunner = new DefaultCommandRunner(logger, logger);
|
||||
const actionRunner = new ActionRunner(commandRunner, tar, logger);
|
||||
|
||||
return await actionRunner.runAction(inputs);
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/common"
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/exec"
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/logging"
|
||||
)
|
||||
|
||||
func getExecutor(replayFilename string) exec.Executor {
|
||||
if len(replayFilename) == 0 {
|
||||
return &exec.BinExecutor{}
|
||||
}
|
||||
return exec.NewReplayExecutor(replayFilename)
|
||||
}
|
||||
|
||||
func main() {
|
||||
debug := flag.Bool("debug", false, "Log diagnostic information to a file alongside the binary.")
|
||||
|
||||
replayFilename := flag.String("replayfile", "",
|
||||
"Replay command output from a specified file rather than executing a binary."+
|
||||
"The file should be in the same format as the log generated by the debug flag.")
|
||||
|
||||
flag.Parse()
|
||||
unparsedFlags := flag.Args()
|
||||
|
||||
logging.Init(os.Args[0]+".log", *debug)
|
||||
|
||||
executor := getExecutor(*replayFilename)
|
||||
|
||||
if len(unparsedFlags) < 2 {
|
||||
logging.Fatalf("Expected at least 2 non-flag arguments but found %d.", len(unparsedFlags))
|
||||
return
|
||||
}
|
||||
command := unparsedFlags[0]
|
||||
pkgNames := unparsedFlags[1:]
|
||||
|
||||
switch command {
|
||||
|
||||
case "normalized-list":
|
||||
pkgs, err := common.GetAptPackages(executor, pkgNames)
|
||||
if err != nil {
|
||||
logging.Fatalf("Encountered error resolving some or all package names, see combined std[out,err] below.\n%s", err.Error())
|
||||
}
|
||||
fmt.Println(pkgs.Serialize())
|
||||
|
||||
default:
|
||||
logging.Fatalf("Command '%s' not recognized.", command)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"testing"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/cmdtesting"
|
||||
)
|
||||
|
||||
var createReplayLogs bool = false
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&createReplayLogs, "createreplaylogs", false, "Execute the test commands, save the command output for future replay and skip the tests themselves.")
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
cmdtesting.TestMain(m)
|
||||
}
|
||||
|
||||
func TestNormalizedList_MultiplePackagesExists_StdoutsAlphaSortedPackageNameVersionPairs(t *testing.T) {
|
||||
result := cmdtesting.New(t, createReplayLogs).Run("normalized-list", "xdot", "rolldice")
|
||||
result.ExpectSuccessfulOut("rolldice=1.16-1build1 xdot=1.1-2")
|
||||
}
|
||||
|
||||
func TestNormalizedList_SamePackagesDifferentOrder_StdoutsMatch(t *testing.T) {
|
||||
expected := "rolldice=1.16-1build1 xdot=1.1-2"
|
||||
|
||||
ct := cmdtesting.New(t, createReplayLogs)
|
||||
|
||||
result := ct.Run("normalized-list", "rolldice", "xdot")
|
||||
result.ExpectSuccessfulOut(expected)
|
||||
|
||||
result = ct.Run("normalized-list", "xdot", "rolldice")
|
||||
result.ExpectSuccessfulOut(expected)
|
||||
}
|
||||
|
||||
func TestNormalizedList_MultiVersionWarning_StdoutSingleVersion(t *testing.T) {
|
||||
var result = cmdtesting.New(t, createReplayLogs).Run("normalized-list", "libosmesa6-dev", "libgl1-mesa-dev")
|
||||
result.ExpectSuccessfulOut("libgl1-mesa-dev=21.2.6-0ubuntu0.1~20.04.2 libosmesa6-dev=21.2.6-0ubuntu0.1~20.04.2")
|
||||
}
|
||||
|
||||
func TestNormalizedList_SinglePackageExists_StdoutsSinglePackageNameVersionPair(t *testing.T) {
|
||||
var result = cmdtesting.New(t, createReplayLogs).Run("normalized-list", "xdot")
|
||||
result.ExpectSuccessfulOut("xdot=1.1-2")
|
||||
}
|
||||
|
||||
func TestNormalizedList_VersionContainsColon_StdoutsEntireVersion(t *testing.T) {
|
||||
var result = cmdtesting.New(t, createReplayLogs).Run("normalized-list", "default-jre")
|
||||
result.ExpectSuccessfulOut("default-jre=2:1.11-72")
|
||||
}
|
||||
|
||||
func TestNormalizedList_NonExistentPackageName_StderrsAptCacheErrors(t *testing.T) {
|
||||
var result = cmdtesting.New(t, createReplayLogs).Run("normalized-list", "nonexistentpackagename")
|
||||
result.ExpectError(
|
||||
`Error encountered running apt-cache --quiet=0 --no-all-versions show nonexistentpackagename
|
||||
Exited with status code 100; see combined std[out,err] below:
|
||||
N: Unable to locate package nonexistentpackagename
|
||||
N: Unable to locate package nonexistentpackagename
|
||||
E: No packages found`)
|
||||
}
|
||||
|
||||
func TestNormalizedList_NoPackagesGiven_StderrsArgMismatch(t *testing.T) {
|
||||
var result = cmdtesting.New(t, createReplayLogs).Run("normalized-list")
|
||||
result.ExpectError("Expected at least 2 non-flag arguments but found 1.")
|
||||
}
|
||||
|
||||
func TestNormalizedList_VirtualPackagesExists_StdoutsConcretePackage(t *testing.T) {
|
||||
result := cmdtesting.New(t, createReplayLogs).Run("normalized-list", "libvips")
|
||||
result.ExpectSuccessfulOut("libvips42=8.9.1-2")
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
2025/03/15 22:29:08 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:09 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show xdot rolldice",
|
||||
"Stdout": "Package: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\nPackage: rolldice\nArchitecture: amd64\nVersion: 1.16-1build1\nPriority: optional\nSection: universe/games\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Thomas Ross \u003cthomasross@thomasross.io\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 31\nDepends: libc6 (\u003e= 2.7), libreadline8 (\u003e= 6.0)\nFilename: pool/universe/r/rolldice/rolldice_1.16-1build1_amd64.deb\nSize: 9628\nMD5sum: af6390bf2d5d5b4710d308ac06d4913a\nSHA1: 1d87ccac5b20f4e2a217a0e058408f46cfe5caff\nSHA256: 2e076006200057da0be52060e3cc2f4fc7c51212867173e727590bd7603a0337\nHomepage: https://github.com/sstrickl/rolldice\nDescription-en: virtual dice roller\n rolldice is a virtual dice roller that takes a string on the command\n line in the format of some fantasy role playing games like Advanced\n Dungeons \u0026 Dragons [1] and returns the result of the dice rolls.\n .\n [1] Advanced Dungeons \u0026 Dragons is a registered trademark of TSR, Inc.\nDescription-md5: fc24e9e12c794a8f92ab0ca6e1058501\n\n",
|
||||
"Stderr": "",
|
||||
"CombinedOut": "Package: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\nPackage: rolldice\nArchitecture: amd64\nVersion: 1.16-1build1\nPriority: optional\nSection: universe/games\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Thomas Ross \u003cthomasross@thomasross.io\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 31\nDepends: libc6 (\u003e= 2.7), libreadline8 (\u003e= 6.0)\nFilename: pool/universe/r/rolldice/rolldice_1.16-1build1_amd64.deb\nSize: 9628\nMD5sum: af6390bf2d5d5b4710d308ac06d4913a\nSHA1: 1d87ccac5b20f4e2a217a0e058408f46cfe5caff\nSHA256: 2e076006200057da0be52060e3cc2f4fc7c51212867173e727590bd7603a0337\nHomepage: https://github.com/sstrickl/rolldice\nDescription-en: virtual dice roller\n rolldice is a virtual dice roller that takes a string on the command\n line in the format of some fantasy role playing games like Advanced\n Dungeons \u0026 Dragons [1] and returns the result of the dice rolls.\n .\n [1] Advanced Dungeons \u0026 Dragons is a registered trademark of TSR, Inc.\nDescription-md5: fc24e9e12c794a8f92ab0ca6e1058501\n\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
2025/03/15 22:29:10 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:12 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show libosmesa6-dev libgl1-mesa-dev",
|
||||
"Stdout": "Package: libosmesa6-dev\nArchitecture: amd64\nVersion: 21.2.6-0ubuntu0.1~20.04.2\nMulti-Arch: same\nPriority: extra\nSection: devel\nSource: mesa\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Debian X Strike Force \u003cdebian-x@lists.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 88\nProvides: libosmesa-dev\nDepends: libosmesa6 (= 21.2.6-0ubuntu0.1~20.04.2), mesa-common-dev (= 21.2.6-0ubuntu0.1~20.04.2) | libgl-dev\nConflicts: libosmesa-dev\nReplaces: libosmesa-dev\nFilename: pool/main/m/mesa/libosmesa6-dev_21.2.6-0ubuntu0.1~20.04.2_amd64.deb\nSize: 8844\nMD5sum: b6c380d1b916bc6955aaf108a3be468e\nSHA1: 4b772c8127e60a342dabec4ff0939969d99038b4\nSHA256: bf003b66573d611877664e01659046d281b26698f3665345cb784ddded662c6a\nSHA512: 761557925874473e4408504772a0af4d29f6dc1dcbd53e772315dffb6da87d47960edca4de39deda7cae33a8730d87a19b40a7d29739ba7cff5b60ee4900a13a\nHomepage: https://mesa3d.org/\nDescription-en: Mesa Off-screen rendering extension -- development files\n This package provides the required environment for developing programs\n that use the off-screen rendering extension of Mesa.\n .\n For more information on OSmesa see the libosmesa6 package.\nDescription-md5: 9b1d7a0b3e6a2ea021f4443f42dcff4f\n\nPackage: libgl1-mesa-dev\nArchitecture: amd64\nVersion: 21.2.6-0ubuntu0.1~20.04.2\nMulti-Arch: same\nPriority: extra\nSection: libdevel\nSource: mesa\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Debian X Strike Force \u003cdebian-x@lists.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 70\nDepends: libgl-dev, libglvnd-dev\nFilename: pool/main/m/mesa/libgl1-mesa-dev_21.2.6-0ubuntu0.1~20.04.2_amd64.deb\nSize: 6420\nMD5sum: 759a811dcb12adfcebfc1a6aa52e85b9\nSHA1: 3b9de17b1c67ee40603e1eebaefa978810a2f2d2\nSHA256: 76846d96ae0706a7edcd514d452a1393bb8b8a8ac06518253dd5869441807052\nSHA512: 581e4b3752b4c98399f3519fce2c5ab033cea3cac66bde3c204af769ff0377400087f9c4c6aaebe06c19d05f8715b3346d249a86c3ae80a098ca476e76af01c3\nHomepage: https://mesa3d.org/\nDescription-en: transitional dummy package\n This is a transitional dummy package, it can be safely removed.\nDescription-md5: 635a93bcd1440d16621693fe064c2aa9\n\n",
|
||||
"Stderr": "N: There are 2 additional records. Please use the '-a' switch to see them.\n",
|
||||
"CombinedOut": "Package: libosmesa6-dev\nArchitecture: amd64\nVersion: 21.2.6-0ubuntu0.1~20.04.2\nMulti-Arch: same\nPriority: extra\nSection: devel\nSource: mesa\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Debian X Strike Force \u003cdebian-x@lists.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 88\nProvides: libosmesa-dev\nDepends: libosmesa6 (= 21.2.6-0ubuntu0.1~20.04.2), mesa-common-dev (= 21.2.6-0ubuntu0.1~20.04.2) | libgl-dev\nConflicts: libosmesa-dev\nReplaces: libosmesa-dev\nFilename: pool/main/m/mesa/libosmesa6-dev_21.2.6-0ubuntu0.1~20.04.2_amd64.deb\nSize: 8844\nMD5sum: b6c380d1b916bc6955aaf108a3be468e\nSHA1: 4b772c8127e60a342dabec4ff0939969d99038b4\nSHA256: bf003b66573d611877664e01659046d281b26698f3665345cb784ddded662c6a\nSHA512: 761557925874473e4408504772a0af4d29f6dc1dcbd53e772315dffb6da87d47960edca4de39deda7cae33a8730d87a19b40a7d29739ba7cff5b60ee4900a13a\nHomepage: https://mesa3d.org/\nDescription-en: Mesa Off-screen rendering extension -- development files\n This package provides the required environment for developing programs\n that use the off-screen rendering extension of Mesa.\n .\n For more information on OSmesa see the libosmesa6 package.\nDescription-md5: 9b1d7a0b3e6a2ea021f4443f42dcff4f\n\nPackage: libgl1-mesa-dev\nArchitecture: amd64\nVersion: 21.2.6-0ubuntu0.1~20.04.2\nMulti-Arch: same\nPriority: extra\nSection: libdevel\nSource: mesa\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Debian X Strike Force \u003cdebian-x@lists.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 70\nDepends: libgl-dev, libglvnd-dev\nFilename: pool/main/m/mesa/libgl1-mesa-dev_21.2.6-0ubuntu0.1~20.04.2_amd64.deb\nSize: 6420\nMD5sum: 759a811dcb12adfcebfc1a6aa52e85b9\nSHA1: 3b9de17b1c67ee40603e1eebaefa978810a2f2d2\nSHA256: 76846d96ae0706a7edcd514d452a1393bb8b8a8ac06518253dd5869441807052\nSHA512: 581e4b3752b4c98399f3519fce2c5ab033cea3cac66bde3c204af769ff0377400087f9c4c6aaebe06c19d05f8715b3346d249a86c3ae80a098ca476e76af01c3\nHomepage: https://mesa3d.org/\nDescription-en: transitional dummy package\n This is a transitional dummy package, it can be safely removed.\nDescription-md5: 635a93bcd1440d16621693fe064c2aa9\n\nN: There are 2 additional records. Please use the '-a' switch to see them.\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
2025/03/15 22:29:13 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:14 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show nonexistentpackagename",
|
||||
"Stdout": "",
|
||||
"Stderr": "N: Unable to locate package nonexistentpackagename\nN: Unable to locate package nonexistentpackagename\nE: No packages found\n",
|
||||
"CombinedOut": "N: Unable to locate package nonexistentpackagename\nN: Unable to locate package nonexistentpackagename\nE: No packages found\n",
|
||||
"ExitCode": 100
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
2025/03/15 22:29:14 Error encountered running apt-cache --quiet=0 --no-all-versions show nonexistentpackagename
|
||||
Exited with status code 100; see combined std[out,err] below:
|
||||
N: Unable to locate package nonexistentpackagename
|
||||
N: Unable to locate package nonexistentpackagename
|
||||
E: No packages found
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
2025/03/15 22:29:14 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:14 Expected at least 2 non-flag arguments but found 1.
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
2025/03/15 22:29:09 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:10 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show rolldice xdot",
|
||||
"Stdout": "Package: rolldice\nArchitecture: amd64\nVersion: 1.16-1build1\nPriority: optional\nSection: universe/games\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Thomas Ross \u003cthomasross@thomasross.io\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 31\nDepends: libc6 (\u003e= 2.7), libreadline8 (\u003e= 6.0)\nFilename: pool/universe/r/rolldice/rolldice_1.16-1build1_amd64.deb\nSize: 9628\nMD5sum: af6390bf2d5d5b4710d308ac06d4913a\nSHA1: 1d87ccac5b20f4e2a217a0e058408f46cfe5caff\nSHA256: 2e076006200057da0be52060e3cc2f4fc7c51212867173e727590bd7603a0337\nHomepage: https://github.com/sstrickl/rolldice\nDescription-en: virtual dice roller\n rolldice is a virtual dice roller that takes a string on the command\n line in the format of some fantasy role playing games like Advanced\n Dungeons \u0026 Dragons [1] and returns the result of the dice rolls.\n .\n [1] Advanced Dungeons \u0026 Dragons is a registered trademark of TSR, Inc.\nDescription-md5: fc24e9e12c794a8f92ab0ca6e1058501\n\nPackage: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\n",
|
||||
"Stderr": "",
|
||||
"CombinedOut": "Package: rolldice\nArchitecture: amd64\nVersion: 1.16-1build1\nPriority: optional\nSection: universe/games\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Thomas Ross \u003cthomasross@thomasross.io\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 31\nDepends: libc6 (\u003e= 2.7), libreadline8 (\u003e= 6.0)\nFilename: pool/universe/r/rolldice/rolldice_1.16-1build1_amd64.deb\nSize: 9628\nMD5sum: af6390bf2d5d5b4710d308ac06d4913a\nSHA1: 1d87ccac5b20f4e2a217a0e058408f46cfe5caff\nSHA256: 2e076006200057da0be52060e3cc2f4fc7c51212867173e727590bd7603a0337\nHomepage: https://github.com/sstrickl/rolldice\nDescription-en: virtual dice roller\n rolldice is a virtual dice roller that takes a string on the command\n line in the format of some fantasy role playing games like Advanced\n Dungeons \u0026 Dragons [1] and returns the result of the dice rolls.\n .\n [1] Advanced Dungeons \u0026 Dragons is a registered trademark of TSR, Inc.\nDescription-md5: fc24e9e12c794a8f92ab0ca6e1058501\n\nPackage: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
2025/03/15 22:29:10 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:10 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show xdot rolldice",
|
||||
"Stdout": "Package: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\nPackage: rolldice\nArchitecture: amd64\nVersion: 1.16-1build1\nPriority: optional\nSection: universe/games\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Thomas Ross \u003cthomasross@thomasross.io\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 31\nDepends: libc6 (\u003e= 2.7), libreadline8 (\u003e= 6.0)\nFilename: pool/universe/r/rolldice/rolldice_1.16-1build1_amd64.deb\nSize: 9628\nMD5sum: af6390bf2d5d5b4710d308ac06d4913a\nSHA1: 1d87ccac5b20f4e2a217a0e058408f46cfe5caff\nSHA256: 2e076006200057da0be52060e3cc2f4fc7c51212867173e727590bd7603a0337\nHomepage: https://github.com/sstrickl/rolldice\nDescription-en: virtual dice roller\n rolldice is a virtual dice roller that takes a string on the command\n line in the format of some fantasy role playing games like Advanced\n Dungeons \u0026 Dragons [1] and returns the result of the dice rolls.\n .\n [1] Advanced Dungeons \u0026 Dragons is a registered trademark of TSR, Inc.\nDescription-md5: fc24e9e12c794a8f92ab0ca6e1058501\n\n",
|
||||
"Stderr": "",
|
||||
"CombinedOut": "Package: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\nPackage: rolldice\nArchitecture: amd64\nVersion: 1.16-1build1\nPriority: optional\nSection: universe/games\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Thomas Ross \u003cthomasross@thomasross.io\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 31\nDepends: libc6 (\u003e= 2.7), libreadline8 (\u003e= 6.0)\nFilename: pool/universe/r/rolldice/rolldice_1.16-1build1_amd64.deb\nSize: 9628\nMD5sum: af6390bf2d5d5b4710d308ac06d4913a\nSHA1: 1d87ccac5b20f4e2a217a0e058408f46cfe5caff\nSHA256: 2e076006200057da0be52060e3cc2f4fc7c51212867173e727590bd7603a0337\nHomepage: https://github.com/sstrickl/rolldice\nDescription-en: virtual dice roller\n rolldice is a virtual dice roller that takes a string on the command\n line in the format of some fantasy role playing games like Advanced\n Dungeons \u0026 Dragons [1] and returns the result of the dice rolls.\n .\n [1] Advanced Dungeons \u0026 Dragons is a registered trademark of TSR, Inc.\nDescription-md5: fc24e9e12c794a8f92ab0ca6e1058501\n\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
2025/03/15 22:29:12 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:12 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show xdot",
|
||||
"Stdout": "Package: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\n",
|
||||
"Stderr": "",
|
||||
"CombinedOut": "Package: xdot\nArchitecture: all\nVersion: 1.1-2\nPriority: optional\nSection: universe/python\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Python Applications Packaging Team \u003cpython-apps-team@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 153\nDepends: gir1.2-gtk-3.0, graphviz, python3-gi, python3-gi-cairo, python3:any\nFilename: pool/universe/x/xdot/xdot_1.1-2_all.deb\nSize: 26708\nMD5sum: aab630b6e1f73a0e3ae85b208b8b6d00\nSHA1: 202155c123c7bd7628023b848e997f342d14359d\nSHA256: 4b7ecb2c4dc948a850024a9b7378d58195230659307bbde4018a1be17645e690\nHomepage: https://github.com/jrfonseca/xdot.py\nDescription-en: interactive viewer for Graphviz dot files\n xdot is an interactive viewer for graphs written in Graphviz's dot language.\n It uses internally the graphviz's xdot output format as an intermediate\n format, and PyGTK and Cairo for rendering. xdot can be used either as a\n standalone application from command line, or as a library embedded in your\n Python 3 application.\n .\n Features:\n * Since it doesn't use bitmaps it is fast and has a small memory footprint.\n * Arbitrary zoom.\n * Keyboard/mouse navigation.\n * Supports events on the nodes with URLs.\n * Animated jumping between nodes.\n * Highlights node/edge under mouse.\nDescription-md5: eb58f25a628b48a744f1b904af3b9282\n\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
2025/03/15 22:29:12 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:13 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show default-jre",
|
||||
"Stdout": "Package: default-jre\nArchitecture: amd64\nVersion: 2:1.11-72\nPriority: optional\nSection: interpreters\nSource: java-common (0.72)\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Debian Java Maintainers \u003cpkg-java-maintainers@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 6\nProvides: java-runtime, java10-runtime, java11-runtime, java2-runtime, java5-runtime, java6-runtime, java7-runtime, java8-runtime, java9-runtime\nDepends: default-jre-headless (= 2:1.11-72), openjdk-11-jre\nFilename: pool/main/j/java-common/default-jre_1.11-72_amd64.deb\nSize: 1084\nMD5sum: 4f441bb884801f3a07806934e4519652\nSHA1: 9922edaa7bd91921a2beee6c60343ebf551957a9\nSHA256: 063bb2ca3b51309f6625033c336beffb0eb8286aaabcf3bf917eef498de29ea5\nHomepage: https://wiki.debian.org/Java/\nDescription-en: Standard Java or Java compatible Runtime\n This dependency package points to the Java runtime, or Java compatible\n runtime recommended for this architecture, which is\n openjdk-11-jre for amd64.\nDescription-md5: 071b7a2f9baf048d89c849c14bcafb9e\nCnf-Extra-Commands: java,jexec\n\n",
|
||||
"Stderr": "",
|
||||
"CombinedOut": "Package: default-jre\nArchitecture: amd64\nVersion: 2:1.11-72\nPriority: optional\nSection: interpreters\nSource: java-common (0.72)\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nOriginal-Maintainer: Debian Java Maintainers \u003cpkg-java-maintainers@lists.alioth.debian.org\u003e\nBugs: https://bugs.launchpad.net/ubuntu/+filebug\nInstalled-Size: 6\nProvides: java-runtime, java10-runtime, java11-runtime, java2-runtime, java5-runtime, java6-runtime, java7-runtime, java8-runtime, java9-runtime\nDepends: default-jre-headless (= 2:1.11-72), openjdk-11-jre\nFilename: pool/main/j/java-common/default-jre_1.11-72_amd64.deb\nSize: 1084\nMD5sum: 4f441bb884801f3a07806934e4519652\nSHA1: 9922edaa7bd91921a2beee6c60343ebf551957a9\nSHA256: 063bb2ca3b51309f6625033c336beffb0eb8286aaabcf3bf917eef498de29ea5\nHomepage: https://wiki.debian.org/Java/\nDescription-en: Standard Java or Java compatible Runtime\n This dependency package points to the Java runtime, or Java compatible\n runtime recommended for this architecture, which is\n openjdk-11-jre for amd64.\nDescription-md5: 071b7a2f9baf048d89c849c14bcafb9e\nCnf-Extra-Commands: java,jexec\n\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
2025/03/15 22:29:14 Debug log created at /home/awalsh128/cache-apt-pkgs-action/src/cmd/apt_query/apt_query.log
|
||||
2025/03/15 22:29:14 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "apt-cache --quiet=0 --no-all-versions show libvips",
|
||||
"Stdout": "",
|
||||
"Stderr": "N: Can't select candidate version from package libvips as it has no candidate\nN: Can't select versions from package 'libvips' as it is purely virtual\nN: No packages found\n",
|
||||
"CombinedOut": "N: Can't select candidate version from package libvips as it has no candidate\nN: Can't select versions from package 'libvips' as it is purely virtual\nN: No packages found\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
2025/03/15 22:29:14 EXECUTION-OBJ-START
|
||||
{
|
||||
"Cmd": "bash -c apt-cache showpkg libvips | grep -A 1 \"Reverse Provides\" | tail -1",
|
||||
"Stdout": "libvips42 8.9.1-2 (= )\n",
|
||||
"Stderr": "",
|
||||
"CombinedOut": "libvips42 8.9.1-2 (= )\n",
|
||||
"ExitCode": 0
|
||||
}
|
||||
EXECUTION-OBJ-END
|
||||
57
src/index.ts
Normal file
57
src/index.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import * as core from "@actions/core";
|
||||
import { parseBoolean, runAction, type ActionInputs } from "./action.js";
|
||||
import winston from "winston";
|
||||
|
||||
function parseEmptyPackagesBehavior(
|
||||
value: string,
|
||||
): "error" | "warn" | "ignore" {
|
||||
if (value === "error" || value === "warn" || value === "ignore") {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`empty_packages_behavior value '${value}' must be one of: error, warn, ignore.`,
|
||||
);
|
||||
}
|
||||
|
||||
function getInputs(): ActionInputs {
|
||||
const executeInstallScriptsRaw = core.getInput("execute_install_scripts");
|
||||
const debugRaw = core.getInput("debug");
|
||||
const emptyPackagesBehaviorRaw =
|
||||
core.getInput("empty_packages_behavior") || "error";
|
||||
|
||||
return {
|
||||
packages: core.getInput("packages", { required: true }),
|
||||
version: core.getInput("version"),
|
||||
executeInstallScripts: parseBoolean(
|
||||
executeInstallScriptsRaw,
|
||||
"execute_install_scripts",
|
||||
),
|
||||
emptyPackagesBehavior: parseEmptyPackagesBehavior(emptyPackagesBehaviorRaw),
|
||||
debug: parseBoolean(debugRaw, "debug"),
|
||||
};
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
try {
|
||||
const inputs = getInputs();
|
||||
const logger = winston.createLogger({
|
||||
level: inputs.debug ? "debug" : "info",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.printf(({ level, message }) => `${level}: ${message}`),
|
||||
),
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
const outputs = await runAction(inputs, logger);
|
||||
|
||||
core.setOutput("cache-hit", String(outputs.cacheHit));
|
||||
core.setOutput("package-version-list", outputs.packageVersionList);
|
||||
core.setOutput("all-package-version-list", outputs.allPackageVersionList);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
core.setFailed(message);
|
||||
}
|
||||
}
|
||||
|
||||
void main();
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
package cmdtesting
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/common"
|
||||
)
|
||||
|
||||
const binaryName = "apt_query"
|
||||
|
||||
type CmdTesting struct {
|
||||
*testing.T
|
||||
createReplayLogs bool
|
||||
replayFilename string
|
||||
}
|
||||
|
||||
func New(t *testing.T, createReplayLogs bool) *CmdTesting {
|
||||
replayFilename := "testlogs/" + strings.ToLower(t.Name()) + ".log"
|
||||
if createReplayLogs {
|
||||
os.Remove(replayFilename)
|
||||
os.Remove(binaryName + ".log")
|
||||
}
|
||||
return &CmdTesting{t, createReplayLogs, replayFilename}
|
||||
}
|
||||
|
||||
type RunResult struct {
|
||||
Testing *CmdTesting
|
||||
CombinedOut string
|
||||
Err error
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
cmd := exec.Command("go", "build")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
panic(string(out))
|
||||
}
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func (t *CmdTesting) Run(command string, pkgNames ...string) RunResult {
|
||||
replayfile := "testlogs/" + strings.ToLower(t.Name()) + ".log"
|
||||
|
||||
flags := []string{"-debug=true"}
|
||||
if !t.createReplayLogs {
|
||||
flags = append(flags, "-replayfile="+replayfile)
|
||||
}
|
||||
|
||||
cmd := exec.Command("./"+binaryName, append(append(flags, command), pkgNames...)...)
|
||||
combinedOut, err := cmd.CombinedOutput()
|
||||
|
||||
if t.createReplayLogs {
|
||||
err := common.AppendFile(binaryName+".log", t.replayFilename)
|
||||
if err != nil {
|
||||
t.T.Fatalf("Error encountered appending log file.\n%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return RunResult{Testing: t, CombinedOut: string(combinedOut), Err: err}
|
||||
}
|
||||
|
||||
func (r *RunResult) ExpectSuccessfulOut(expected string) {
|
||||
if r.Testing.createReplayLogs {
|
||||
r.Testing.Log("Skipping test while creating replay logs.")
|
||||
return
|
||||
}
|
||||
|
||||
if r.Err != nil {
|
||||
r.Testing.Errorf("Error running command: %v\n%s", r.Err, r.CombinedOut)
|
||||
return
|
||||
}
|
||||
fullExpected := expected + "\n" // Output will always have a end of output newline.
|
||||
if r.CombinedOut != fullExpected {
|
||||
r.Testing.Errorf("Unexpected combined std[err,out] found.\nExpected:\n'%s'\nActual:\n'%s'", fullExpected, r.CombinedOut)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RunResult) ExpectError(expectedCombinedOut string) {
|
||||
if r.Testing.createReplayLogs {
|
||||
r.Testing.Log("Skipping test while creating replay logs.")
|
||||
return
|
||||
}
|
||||
|
||||
fullExpectedCombinedOut := expectedCombinedOut + "\n" // Output will always have a end of output newline.
|
||||
if r.CombinedOut != fullExpectedCombinedOut {
|
||||
r.Testing.Errorf("Unexpected combined std[err,out] found.\nExpected:\n'%s'\nActual:\n'%s'", fullExpectedCombinedOut, r.CombinedOut)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/exec"
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/logging"
|
||||
)
|
||||
|
||||
// An APT package name and version representation.
|
||||
type AptPackage struct {
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
type AptPackages []AptPackage
|
||||
|
||||
// Serialize the APT packages into lines of <name>=<version>.
|
||||
func (ps AptPackages) Serialize() string {
|
||||
tokens := []string{}
|
||||
for _, p := range ps {
|
||||
tokens = append(tokens, p.Name+"="+p.Version)
|
||||
}
|
||||
return strings.Join(tokens, " ")
|
||||
}
|
||||
|
||||
func isErrLine(line string) bool {
|
||||
return strings.HasPrefix(line, "E: ") || strings.HasPrefix(line, "N: ")
|
||||
}
|
||||
|
||||
// Resolves virtual packages names to their concrete one.
|
||||
func getNonVirtualPackage(executor exec.Executor, name string) (pkg *AptPackage, err error) {
|
||||
execution := executor.Exec("bash", "-c", fmt.Sprintf("apt-cache showpkg %s | grep -A 1 \"Reverse Provides\" | tail -1", name))
|
||||
err = execution.Error()
|
||||
if err != nil {
|
||||
logging.Fatal(err)
|
||||
return pkg, err
|
||||
}
|
||||
if isErrLine(execution.CombinedOut) {
|
||||
return pkg, execution.Error()
|
||||
}
|
||||
splitLine := GetSplitLine(execution.CombinedOut, " ", 3)
|
||||
if len(splitLine.Words) < 2 {
|
||||
return pkg, fmt.Errorf("unable to parse space delimited line's package name and version from apt-cache showpkg output below:\n%s", execution.CombinedOut)
|
||||
}
|
||||
return &AptPackage{Name: splitLine.Words[0], Version: splitLine.Words[1]}, nil
|
||||
}
|
||||
|
||||
func getPackage(executor exec.Executor, paragraph string) (pkg *AptPackage, err error) {
|
||||
errMsgs := []string{}
|
||||
for _, splitLine := range GetSplitLines(paragraph, ":", 2) {
|
||||
if len(splitLine.Words) < 2 {
|
||||
logging.Debug("Skipping invalid line: %+v\n", splitLine.Line)
|
||||
continue
|
||||
}
|
||||
switch splitLine.Words[0] {
|
||||
case "Package":
|
||||
// Initialize since this will provide the first struct value if present.
|
||||
pkg = &AptPackage{}
|
||||
pkg.Name = splitLine.Words[1]
|
||||
|
||||
case "Version":
|
||||
pkg.Version = splitLine.Words[1]
|
||||
|
||||
case "N":
|
||||
// e.g. Can't select versions from package 'libvips' as it is purely virtual
|
||||
if strings.Contains(splitLine.Words[1], "as it is purely virtual") {
|
||||
return getNonVirtualPackage(executor, GetSplitLine(splitLine.Words[1], "'", 4).Words[2])
|
||||
}
|
||||
if strings.HasPrefix(splitLine.Words[1], "Unable to locate package") && !ArrContainsString(errMsgs, splitLine.Line) {
|
||||
errMsgs = append(errMsgs, splitLine.Line)
|
||||
}
|
||||
case "E":
|
||||
if !ArrContainsString(errMsgs, splitLine.Line) {
|
||||
errMsgs = append(errMsgs, splitLine.Line)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(errMsgs) == 0 {
|
||||
return pkg, nil
|
||||
}
|
||||
return pkg, errors.New(strings.Join(errMsgs, "\n"))
|
||||
}
|
||||
|
||||
// Gets the APT based packages as a sorted by package name list (normalized).
|
||||
func GetAptPackages(executor exec.Executor, names []string) (AptPackages, error) {
|
||||
prefixArgs := []string{"--quiet=0", "--no-all-versions", "show"}
|
||||
execution := executor.Exec("apt-cache", append(prefixArgs, names...)...)
|
||||
pkgs := []AptPackage{}
|
||||
|
||||
err := execution.Error()
|
||||
if err != nil {
|
||||
logging.Fatal(err)
|
||||
return pkgs, err
|
||||
}
|
||||
|
||||
errMsgs := []string{}
|
||||
|
||||
for _, paragraph := range strings.Split(execution.CombinedOut, "\n\n") {
|
||||
trimmed := strings.TrimSpace(paragraph)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
pkg, err := getPackage(executor, trimmed)
|
||||
if err != nil {
|
||||
errMsgs = append(errMsgs, err.Error())
|
||||
} else if pkg != nil { // Ignore cases where no package parsed and no errors occurred.
|
||||
pkgs = append(pkgs, *pkg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errMsgs) > 0 {
|
||||
errMsgs = append(errMsgs, strings.Join(errMsgs, "\n"))
|
||||
}
|
||||
|
||||
sort.Slice(pkgs, func(i, j int) bool {
|
||||
return pkgs[i].Name < pkgs[j].Name
|
||||
})
|
||||
if len(errMsgs) > 0 {
|
||||
return pkgs, errors.New(strings.Join(errMsgs, "\n"))
|
||||
}
|
||||
|
||||
return pkgs, nil
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func AppendFile(source string, destination string) error {
|
||||
err := createDirectoryIfNotPresent(filepath.Dir(destination))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
in, err := os.Open(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.OpenFile(destination, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
data, err := io.ReadAll(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = out.Write(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CopyFile(source string, destination string) error {
|
||||
err := createDirectoryIfNotPresent(filepath.Dir(destination))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
in, err := os.Open(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(destination)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
data, err := io.ReadAll(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = out.Write(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func MoveFile(source string, destination string) error {
|
||||
err := createDirectoryIfNotPresent(filepath.Dir(destination))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(source, destination)
|
||||
}
|
||||
|
||||
func createDirectoryIfNotPresent(path string) error {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
err := os.MkdirAll(path, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Checks if an exact string is in an array of strings.
|
||||
func ArrContainsString(arr []string, element string) bool {
|
||||
for _, x := range arr {
|
||||
if x == element {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// A line that has been split into words.
|
||||
type SplitLine struct {
|
||||
Line string // The original line.
|
||||
Words []string // The split words in the line.
|
||||
}
|
||||
|
||||
// Splits a line into words by the delimiter and max number of delimitation.
|
||||
func GetSplitLine(line string, delimiter string, numWords int) SplitLine {
|
||||
words := strings.SplitN(line, delimiter, numWords)
|
||||
trimmedWords := make([]string, len(words))
|
||||
for i, word := range words {
|
||||
trimmedWords[i] = strings.TrimSpace(word)
|
||||
}
|
||||
return SplitLine{line, trimmedWords}
|
||||
}
|
||||
|
||||
// Splits a paragraph into lines by newline and then splits each line into words specified by the delimiter and max number of delimitation.
|
||||
func GetSplitLines(paragraph string, delimiter string, numWords int) []SplitLine {
|
||||
lines := []SplitLine{}
|
||||
for _, line := range strings.Split(paragraph, "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, GetSplitLine(trimmed, delimiter, numWords))
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package exec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/logging"
|
||||
)
|
||||
|
||||
// An executor that proxies command executions from the OS.
|
||||
//
|
||||
// NOTE: Extra abstraction layer needed for testing and replay.
|
||||
type BinExecutor struct{}
|
||||
|
||||
func (c *BinExecutor) Exec(name string, arg ...string) *Execution {
|
||||
cmd := exec.Command(name, arg...)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
logging.Fatal(err)
|
||||
}
|
||||
|
||||
execution := &Execution{
|
||||
Cmd: name + " " + strings.Join(arg, " "),
|
||||
CombinedOut: string(out),
|
||||
ExitCode: cmd.ProcessState.ExitCode(),
|
||||
}
|
||||
|
||||
logging.DebugLazy(func() string {
|
||||
return fmt.Sprintf("EXECUTION-OBJ-START\n%s\nEXECUTION-OBJ-END", execution.Serialize())
|
||||
})
|
||||
if err != nil {
|
||||
logging.Fatal(execution.Error())
|
||||
}
|
||||
return execution
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package exec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/logging"
|
||||
)
|
||||
|
||||
type Executor interface {
|
||||
// Executes a command and either returns the output or exits the programs and writes the output (including error) to STDERR.
|
||||
Exec(name string, arg ...string) *Execution
|
||||
}
|
||||
|
||||
type Execution struct {
|
||||
Cmd string
|
||||
CombinedOut string
|
||||
ExitCode int
|
||||
}
|
||||
|
||||
// Gets the error, if the command ran with a non-zero exit code.
|
||||
func (e *Execution) Error() error {
|
||||
if e.ExitCode == 0 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf(
|
||||
"Error encountered running %s\nExited with status code %d; see combined std[out,err] below:\n%s",
|
||||
e.Cmd,
|
||||
e.ExitCode,
|
||||
e.CombinedOut,
|
||||
)
|
||||
}
|
||||
|
||||
func DeserializeExecution(payload string) *Execution {
|
||||
var execution Execution
|
||||
err := json.Unmarshal([]byte(payload), &execution)
|
||||
if err != nil {
|
||||
logging.Fatalf("Error encountered deserializing Execution object.\n%s", err)
|
||||
}
|
||||
return &execution
|
||||
}
|
||||
|
||||
func (e *Execution) Serialize() string {
|
||||
bytes, err := json.MarshalIndent(e, "", " ")
|
||||
if err != nil {
|
||||
logging.Fatalf("Error encountered serializing Execution object.\n%s", err)
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
package exec
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"awalsh128.com/cache-apt-pkgs-action/src/internal/logging"
|
||||
)
|
||||
|
||||
// An executor that replays execution results from a recorded result.
|
||||
type ReplayExecutor struct {
|
||||
logFilepath string
|
||||
cmdExecs map[string]*Execution
|
||||
}
|
||||
|
||||
func NewReplayExecutor(logFilepath string) *ReplayExecutor {
|
||||
file, err := os.Open(logFilepath)
|
||||
if err != nil {
|
||||
logging.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
cmdExecs := make(map[string]*Execution)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.Contains(line, "EXECUTION-OBJ-START") {
|
||||
payload := ""
|
||||
for scanner.Scan() {
|
||||
line = scanner.Text()
|
||||
if strings.Contains(line, "EXECUTION-OBJ-END") {
|
||||
execution := DeserializeExecution(payload)
|
||||
cmdExecs[execution.Cmd] = execution
|
||||
break
|
||||
} else {
|
||||
payload += line + "\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
logging.Fatal(err)
|
||||
}
|
||||
return &ReplayExecutor{logFilepath, cmdExecs}
|
||||
}
|
||||
|
||||
func (e *ReplayExecutor) getCmds() []string {
|
||||
cmds := []string{}
|
||||
for cmd := range e.cmdExecs {
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
return cmds
|
||||
}
|
||||
|
||||
func (e *ReplayExecutor) Exec(name string, arg ...string) *Execution {
|
||||
cmd := name + " " + strings.Join(arg, " ")
|
||||
value, ok := e.cmdExecs[cmd]
|
||||
if !ok {
|
||||
var available string
|
||||
if len(e.getCmds()) > 0 {
|
||||
available = "\n" + strings.Join(e.getCmds(), "\n")
|
||||
} else {
|
||||
available = " NONE"
|
||||
}
|
||||
logging.Fatalf(
|
||||
"Unable to replay command '%s'.\n"+
|
||||
"No command found in the debug log; available commands:%s", cmd, available)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Logger struct {
|
||||
wrapped *log.Logger
|
||||
Filename string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
var logger *Logger
|
||||
|
||||
var LogFilepath = os.Args[0] + ".log"
|
||||
|
||||
func Init(filename string, debug bool) *Logger {
|
||||
os.Remove(LogFilepath)
|
||||
file, err := os.OpenFile(LogFilepath, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
os.Exit(2)
|
||||
}
|
||||
cwd, _ := os.Getwd()
|
||||
logger = &Logger{
|
||||
wrapped: log.New(file, "", log.LstdFlags),
|
||||
Filename: filepath.Join(cwd, file.Name()),
|
||||
Debug: debug,
|
||||
}
|
||||
Debug("Debug log created at %s", logger.Filename)
|
||||
return logger
|
||||
}
|
||||
|
||||
func DebugLazy(getLine func() string) {
|
||||
if logger.Debug {
|
||||
logger.wrapped.Println(getLine())
|
||||
}
|
||||
}
|
||||
|
||||
func Debug(format string, a ...any) {
|
||||
if logger.Debug {
|
||||
logger.wrapped.Printf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
func Fatal(err error) {
|
||||
fmt.Fprintf(os.Stderr, "%s", err.Error())
|
||||
logger.wrapped.Fatal(err)
|
||||
}
|
||||
|
||||
func Fatalf(format string, a ...any) {
|
||||
fmt.Fprintf(os.Stderr, format+"\n", a...)
|
||||
logger.wrapped.Fatalf(format, a...)
|
||||
}
|
||||
106
src/io.ts
Normal file
106
src/io.ts
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as crypto from "crypto";
|
||||
import * as os from "os";
|
||||
import { type CommandRunner } from "../../ts-apt/dist/index.js";
|
||||
|
||||
export function isAptListsFresh(): boolean {
|
||||
const aptListsPath = "/var/lib/apt/lists";
|
||||
const maxDepth = 5;
|
||||
|
||||
function search(currentPath: string, currentDepth: number): boolean {
|
||||
if (currentDepth > maxDepth) return false;
|
||||
|
||||
try {
|
||||
const stats = fs.statSync(currentPath);
|
||||
if (stats.isDirectory()) {
|
||||
const entries = fs.readdirSync(currentPath);
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(currentPath, entry);
|
||||
if (search(fullPath, currentDepth + 1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore permission errors or inaccessible paths
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return search(aptListsPath, 0);
|
||||
}
|
||||
|
||||
export class Package {
|
||||
constructor(
|
||||
readonly name: string,
|
||||
readonly version: string,
|
||||
) {}
|
||||
|
||||
serialize(): string {
|
||||
return `${this.name}@${this.version}`;
|
||||
}
|
||||
}
|
||||
|
||||
const FORCE_UPDATE_INCREMENT = "4";
|
||||
const CACHE_DIRNAME = "cache-apt-pkgs";
|
||||
const CACHE_PREFIX = "cache-apt-pkgs_";
|
||||
|
||||
export class CacheKey {
|
||||
readonly version: string,
|
||||
readonly forceUpdateIncrement: string,
|
||||
readonly arch: string,
|
||||
readonly normalizedPackages: PackageName[],
|
||||
|
||||
constructor(version: string, forceUpdateIncrement: string, arch: string, normalizedPackages: PackageName[]) {
|
||||
this.version = version;
|
||||
this.forceUpdateIncrement = forceUpdateIncrement;
|
||||
this.arch = arch;
|
||||
this.normalizedPackages = normalizedPackages;
|
||||
}
|
||||
|
||||
serialize(): string {
|
||||
return `${this.version}|${this.forceUpdateIncrement}|${this.arch}|${this.normalizedPackages.join(",")}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function deserializeCacheKey(serialized: string): CacheKey {
|
||||
const parts = serialized.split("|");
|
||||
if (parts.length !== 4) {
|
||||
throw new Error(`Invalid serialized cache key: ${serialized}`);
|
||||
}
|
||||
const [version, forceUpdateIncrement, arch, normalizedPackagesStr] = parts;
|
||||
const normalizedPackages = normalizedPackagesStr!.split(",");
|
||||
return new CacheKey(
|
||||
version!,
|
||||
forceUpdateIncrement!,
|
||||
arch!,
|
||||
normalizedPackages,
|
||||
);
|
||||
}
|
||||
|
||||
export class Cache {
|
||||
private readonly cachePath: string;
|
||||
private readonly commandRunner: CommandRunner;
|
||||
|
||||
constructor(cacheDir: string = CACHE_DIRNAME, commandRunner: CommandRunner) {
|
||||
this.cachePath = path.join(os.homedir(), cacheDir);
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
|
||||
async getKey(normalizedPackages: string[], version: string): Promise<string> {
|
||||
const architecture = await (
|
||||
await this.commandRunner.run("arch")
|
||||
).stdout.trim();
|
||||
let value = `${normalizedPackages.join(" ")} @ ${version} ${FORCE_UPDATE_INCREMENT}`;
|
||||
|
||||
if (architecture !== "x86_64") {
|
||||
value = `${value} ${architecture}`;
|
||||
}
|
||||
|
||||
const hash = crypto.createHash("md5").update(value).digest("hex");
|
||||
return `${CACHE_PREFIX}${hash}`;
|
||||
}
|
||||
}
|
||||
35
src/manifest.ts
Normal file
35
src/manifest.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { ActionPackageName } from "./action.js";
|
||||
import fs from "fs";
|
||||
import { CacheKey, deserializeCacheKey } from "./io.js";
|
||||
|
||||
class ManifestEntry {
|
||||
readonly packageName: ActionPackageName;
|
||||
readonly filepaths: string[];
|
||||
|
||||
constructor(packageName: ActionPackageName, filepaths: string[]) {
|
||||
this.packageName = packageName;
|
||||
this.filepaths = filepaths;
|
||||
}
|
||||
}
|
||||
|
||||
class Manifest {
|
||||
readonly cacheTimestamp: string;
|
||||
readonly cacheTimestampMs: string;
|
||||
readonly cacheKey: CacheKey;
|
||||
readonly entries: ManifestEntry[];
|
||||
|
||||
constructor(cacheDate: Date, cacheKey: CacheKey, entries: ManifestEntry[]) {
|
||||
this.cacheTimestamp = cacheDate.toISOString();
|
||||
this.cacheTimestampMs = new Date(this.cacheTimestamp).getTime().toString();
|
||||
this.cacheKey = cacheKey;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
readFromFile(filepath: string): Manifest | null {
|
||||
fs.readFileSync(file, JSON.parse())
|
||||
}
|
||||
|
||||
writeToFile(filePath: string): void {
|
||||
fs.writeFileSync(filePath, JSON.stringify(this, null, 2), "utf-8");
|
||||
}
|
||||
}
|
||||
18
test/action.test.ts
Normal file
18
test/action.test.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { normalizeInputPackages, parseBoolean } from "../src/action.js";
|
||||
|
||||
describe("action utils", () => {
|
||||
it("normalizes package list syntax", () => {
|
||||
const input = " git, curl \\\n jq ";
|
||||
expect(normalizeInputPackages(input)).toEqual(["curl", "git", "jq"]);
|
||||
});
|
||||
|
||||
it("parses true/false values", () => {
|
||||
expect(parseBoolean("true", "debug")).toBe(true);
|
||||
expect(parseBoolean("false", "debug")).toBe(false);
|
||||
});
|
||||
|
||||
it("fails for invalid booleans", () => {
|
||||
expect(() => parseBoolean("TRUE", "debug")).toThrow();
|
||||
});
|
||||
});
|
||||
22
test/manifest.test.ts
Normal file
22
test/manifest.test.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readManifestAsCsv, writeManifest } from "../src/manifest.js";
|
||||
|
||||
describe("manifest", () => {
|
||||
it("writes sorted entries and reads csv output", () => {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "manifest-test-"));
|
||||
const filePath = path.join(tempDir, "manifest.log");
|
||||
|
||||
writeManifest(filePath, ["z=2", "a=1", "m=9"]);
|
||||
|
||||
expect(fs.readFileSync(filePath, "utf8")).toBe("a=1\nm=9\nz=2");
|
||||
expect(readManifestAsCsv(filePath)).toBe("a=1,m=9,z=2");
|
||||
});
|
||||
|
||||
it("returns empty csv for missing files", () => {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "manifest-missing-"));
|
||||
expect(readManifestAsCsv(path.join(tempDir, "none.log"))).toBe("");
|
||||
});
|
||||
});
|
||||
17
tsconfig.base.json
Normal file
17
tsconfig.base.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2023",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true,
|
||||
"lib": [
|
||||
"ES2023"
|
||||
]
|
||||
}
|
||||
}
|
||||
18
tsconfig.build.json
Normal file
18
tsconfig.build.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test",
|
||||
"dist"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
0
tsconfig.dev.json
Normal file
0
tsconfig.dev.json
Normal file
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"test/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
"node",
|
||||
"vitest/globals"
|
||||
],
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
10
vitest.config.ts
Normal file
10
vitest.config.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: "node",
|
||||
include: ["test/**/*.test.ts"],
|
||||
testTimeout: 120000,
|
||||
},
|
||||
});
|
||||
Loading…
Reference in a new issue