Skip to content

Commit

Permalink
feat: add enhanced cache (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardityawahyu authored May 31, 2024
1 parent 9f7821a commit 33598f0
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions backend/tools/setuptools/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ inputs:
description: "Activate cache"
default: 'false'

enhanced_cache:
required: false
description: "Activate enhanced cache"
default: 'false'

setup_go:
required: false
description: "Setup Go"
Expand Down Expand Up @@ -85,23 +90,28 @@ runs:
restore-keys: |
${{ runner.os }}-golang-
# # Cache go build cache, used to speedup go test
# - name: Go Build Cache
# uses: actions/cache@v4
# with:
# path: /home/runner/.cache/go-build
# key: ${{ runner.os }}-go-build-${{ hashFiles(format('{0}/{1}',inputs.hash_files,'go.sum')) }}
# restore-keys: |
# ${{ runner.os }}-go-build-

# # Cache go mod cache, used to speedup builds
# - name: Go Mod Cache
# uses: actions/cache@v4
# with:
# path: /home/runner/go/pkg/mod
# key: ${{ runner.os }}-go-build-${{ hashFiles(format('{0}/{1}',inputs.hash_files,'go.sum')) }}
# restore-keys: |
# ${{ runner.os }}-go-build-
# enhanced caching mechanism
- name: Determine Golang cache paths and construct cache key
if: "${{ inputs.enhanced_cache == 'true' }}"
id: golang-env
run: |
echo "build-cache-path=$(go env GOCACHE)" >>"$GITHUB_OUTPUT"
echo "module-cache-path=$(go env GOMODCACHE)" >>"$GITHUB_OUTPUT"
cacheKeyRoot="${{ runner.os }}-golang${{ inputs.cache_key_suffix && format('-{0}',inputs.cache_key_suffix) }}-"
echo "cache-key-restore=$cacheKeyRoot" >>"$GITHUB_OUTPUT"
echo "cache-key=${cacheKeyRoot}${{ hashFiles(format('{0}/{1}',inputs.hash_files,'go.sum')) }}" >>"$GITHUB_OUTPUT"
shell: bash

- name: Setup Golang cache
if: "${{ inputs.enhanced_cache == 'true' }}"
uses: actions/cache/restore@v4
with:
path: |
${{ steps.golang-env.outputs.build-cache-path }}
${{ steps.golang-env.outputs.module-cache-path }}
key: ${{ steps.golang-env.outputs.cache-key }}
restore-keys: |
${{ steps.golang-env.outputs.cache-key-restore }}
- name: Custom Command
shell: bash
Expand Down

0 comments on commit 33598f0

Please sign in to comment.