I’m refactoring GitHub Actions workflow and I need to have cacheing part in a separate custom action and pass arguments to it. To generate cache I need to pass 3 paths. How can I pass them via inputs of custom action I created?
How workflow looked before:
- name: Setup key for vcpkg cache with pdb dependencies
id: cache-depends-pdb
if: matrix.build-type == 'release'
run: |
echo "vcpkg-key-utils=${{ hashFiles( 'vcpkg.json' ) }}-$env:ImageOS-$env:ImageVersion-depends-pdb-${{ matrix.arch }}" >> $env:GITHUB_OUTPUT
- name: Restore vcpkg cache with pdb dependencies
id: restore-depends-pdb
if: matrix.build-type == 'release'
uses: actions/cache@v3
with:
path: |
C:vcpkgbuildtreesname1${{ matrix.arch }}-windows-static
C:vcpkgbuildtreesname2${{ matrix.arch }}-windows-static
C:vcpkgbuildtreesname3${{ matrix.arch }}-windows-static
key: vcpkg-cache-${{ steps.cache-depends-pdb.outputs.vcpkg-key-utils }}
custom action I created:
name: setup-key-and-restore-dependencies-cache
inputs:
matrix_build_type:
description: 'matrix.build-type'
required: true
matrix_arch:
description: 'matrix.arch'
required: true
fail_on_cache_miss:
description: 'fail_on_cache_miss'
required: false
default: "false"
matrix_toolset:
description: 'matrix.toolset'
required: false
default: 'msvc'
list_of_modules:
description: 'Enter coma separated list of modules for pdb cache. Example name1, name2, name3'
required: true
runs:
using: "composite"
steps:
- name: Setup key for vcpkg cache with pdb dependencies
id: cache-depends-pdb
if: ${{ inputs.matrix_build_type == 'release' && inputs.matrix_toolset == 'msvc' }}
shell: pwsh
run: |
echo "vcpkg-key-utils=${{ hashFiles( 'vcpkg.json' ) }}-$env:ImageOS-$env:ImageVersion-depends-pdb-${{ matrix.arch }}" >> $env:GITHUB_OUTPUT
- name: Prepare list of paths
id: prepare-list
shell: pwsh
run: |
$inputList = "${{ inputs.list_of_modules }}"
# Split the input string into an array
$list = $inputList -split ",s*"
# Initialize an empty array to store the modified items
$modifiedList = @()
# Define the prefix and suffix
$prefix = "C:vcpkgbuildtrees"
$suffix = "${{ inputs.matrix_arch }}-windows-static"
# Iterate through each item in the list
foreach ($item in $list) {
# Add the prefix and suffix to each item
$modifiedItem = "$prefix$item$suffix"
# Add the modified item to the new list
$modifiedList += $modifiedItem
}
$output = $modifiedList -join "n"
# Output the modified list
# Write-Output $output
# Output to github nev
echo "modified_list=$output" >> $env:GITHUB_OUTPUT
- name: Restore vcpkg cache with pdb dependencies
id: restore-depends-pdb
if: ${{ inputs.matrix_build_type == 'release' && inputs.matrix_toolset == 'msvc' }}
uses: actions/cache@v4
with:
path: |
${{ steps.prepare-list.outputs.modified_list }}
key: vcpkg-cache-${{ steps.cache-depends-pdb.outputs.vcpkg-key-utils }}
fail-on-cache-miss: ${{ inputs.fail_on_cache_miss }}
but it fails with no cache found (problem not in fail-on-cache-miss)
New contributor
Тарас Лучик is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.