Added more code to handle caching. #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Pre-Build Workflow | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - develop | |
| jobs: | |
| tests: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: | |
| - ubuntu-22.04 | |
| - ubuntu-24.04 | |
| - windows-2019 | |
| - windows-2022 | |
| - windows-2025 | |
| - macos-13 | |
| - macos-14 | |
| - macos-15 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Debugging step | |
| - name: Pre-Cleanup Directory Listing | |
| run: | | |
| if [ "${{ runner.os }}" = "Windows" ]; then | |
| Get-ChildItem -Force -Recurse $env:USERPROFILE\go\pkg\mod || Write-Output "Directory does not exist" | |
| else | |
| ls -la ~/go/pkg/mod || echo "Directory does not exist" | |
| fi | |
| shell: bash | |
| # Clean cache directories on Linux/Mac | |
| - name: Clean Cache on Linux/Mac | |
| if: runner.os != 'Windows' | |
| run: | | |
| rm -rf ~/.cache/go-build ~/go/pkg/mod | |
| shell: bash | |
| # Clean cache directories on Windows | |
| - name: Clean Cache on Windows | |
| if: runner.os == 'Windows' | |
| run: | | |
| if (Test-Path -Path "$env:USERPROFILE\.cache\go-build") { | |
| Remove-Item -Recurse -Force "$env:USERPROFILE\.cache\go-build" | |
| } | |
| if (Test-Path -Path "$env:USERPROFILE\go\pkg\mod") { | |
| Remove-Item -Recurse -Force "$env:USERPROFILE\go\pkg\mod" | |
| } | |
| shell: pwsh | |
| # Cache Go modules to speed up builds | |
| - name: Cache Go Modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: go-mod-${{ matrix.os }}-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| go-mod-${{ matrix.os }}- | |
| # Run tests | |
| - uses: ./.github/actions/test | |
| # Lint the code | |
| - uses: ./.github/actions/lint |