Skip to content

Commit cb245ba

Browse files
committed
feat: Add more/better logging
1 parent 9466304 commit cb245ba

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

.github/actions/gh-cache/cache/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,31 @@ runs:
2929
path: ${{ inputs.key }}
3030
token: ${{ inputs.token }}
3131
fail_on_cache_miss: ${{ inputs.fail_on_cache_miss }}
32+
3233
- if: ${{ inputs.value }}
3334
name: Update cached value
3435
shell: bash
3536
run: |
3637
mkdir -p "$(dirname "${{ inputs.key }}")"
3738
echo '${{ inputs.value }}' > "${{ inputs.key }}"
39+
echo "Updated contents of '${{ inputs.key }}'"
40+
3841
- if: ${{ inputs.value }}
3942
name: Save cached value
4043
uses: github/continuous-accessibility-scanner/.github/actions/gh-cache/save@smockle/cache-findings
4144
with:
4245
path: ${{ inputs.key }}
4346
token: ${{ inputs.token }}
47+
4448
- name: Output cached value
4549
shell: bash
4650
run: |
4751
echo "value<<EOF" >> $GITHUB_OUTPUT
4852
if [ -f "${{ inputs.key }}" ]; then
4953
cat "${{ inputs.key }}" >> $GITHUB_OUTPUT
54+
echo "Outputted 'value: $(cat "${{ inputs.key }}")'"
55+
else
56+
echo "Skipped outputting 'value'"
5057
fi
5158
echo "EOF" >> $GITHUB_OUTPUT
5259

.github/actions/gh-cache/restore/action.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ runs:
2828
working-directory: .gh-cache-${{ github.run_id }}
2929
run: |
3030
if git ls-remote --exit-code --heads origin gh-cache >/dev/null; then
31-
git fetch origin gh-cache:gh-cache
32-
git checkout gh-cache
33-
elif [[ "${{ inputs.fail_on_cache_miss }}" == "true" ]]; then
34-
echo "Branch does not exist and 'fail_on_cache_miss' is 'true'."
35-
exit 1
31+
git fetch origin gh-cache:gh-cache >/dev/null 2>&1
32+
git checkout gh-cache >/dev/null 2>&1
33+
else
34+
echo "Branch 'gh-cache' does not exist"
35+
if [[ "${{ inputs.fail_on_cache_miss }}" == "true" ]]; then
36+
echo "Exiting with error because 'fail_on_cache_miss' is 'true'"
37+
exit 1
38+
fi
3639
fi
3740
3841
- name: Restore cached item
@@ -43,9 +46,13 @@ runs:
4346
if [ -e "$src" ]; then
4447
mkdir -p "$(dirname "$dest")"
4548
cp -Rf "$src" "$dest"
46-
elif [[ "${{ inputs.fail_on_cache_miss }}" == "true" ]]; then
47-
echo "File or directory does not exist and 'fail_on_cache_miss' is 'true'."
48-
exit 1
49+
echo "Restored '${{ inputs.path }}' from cache"
50+
else
51+
echo "'${{ inputs.path }}' not found in cache"
52+
if [[ "${{ inputs.fail_on_cache_miss }}" == "true" ]]; then
53+
echo "Exiting with error because 'fail_on_cache_miss' is 'true'"
54+
exit 1
55+
fi
4956
fi
5057
5158
- name: Clean up temporary directory

.github/actions/gh-cache/save/action.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ runs:
2424
working-directory: .gh-cache-${{ github.run_id }}
2525
run: |
2626
if git ls-remote --exit-code --heads origin gh-cache >/dev/null; then
27-
git checkout gh-cache
27+
git checkout gh-cache >/dev/null 2>&1
28+
echo "Checked out existing 'gh-cache' branch"
2829
else
29-
git checkout --orphan gh-cache
30+
git checkout --orphan gh-cache >/dev/null 2>&1
3031
git rm -rfq . # Clear files from the initial checkout, to avoid adding them to the orphaned branch
32+
echo "Created new orphaned 'gh-cache' branch"
3133
fi
3234
3335
- name: Copy file to repo
3436
shell: bash
3537
run: |
3638
if [ -f "${{ inputs.path }}" ]; then
3739
cp -Rf "${{ inputs.path }}" ".gh-cache-${{ github.run_id }}/${{ inputs.path }}"
40+
echo "Copied '${{ inputs.path }}' to 'gh-cache' branch"
3841
fi
3942
4043
- name: Commit and push
@@ -45,8 +48,13 @@ runs:
4548
git add "${{ inputs.path }}"
4649
git config user.name "github-actions[bot]"
4750
git config user.email "github-actions[bot]@users.noreply.github.com"
48-
git commit -m "$(printf 'Save artifact: %s' "${{ inputs.path }}")" || echo "No changes to commit"
51+
git commit -m "$(printf 'Save artifact: %s' "${{ inputs.path }}")" \
52+
&& echo "Committed '${{ inputs.path }}' to 'gh-cache' branch" \
53+
|| echo "No changes to commit"
4954
git push origin gh-cache
55+
else
56+
echo "'${{ inputs.path }}' does not exist"
57+
echo "Skipping commit and push"
5058
fi
5159
5260
- name: Clean up temporary directory

0 commit comments

Comments
 (0)