Skip to content

Commit

Permalink
ci: add go-test-monorepo-action windows support
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Kungla <[email protected]>
  • Loading branch information
mkungla committed Jan 29, 2024
1 parent 5fe299e commit 51cf3bd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
15 changes: 14 additions & 1 deletion .github/actions/go-test-monorepo-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ runs:
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Determine OS
id: determine-os
run: echo "::set-output name=os::$(echo $RUNNER_OS | tr '[:upper:]' '[:lower:]')"

- name: Run tests and generate coverage for all modules
id: coveredmodules
run: ./.github/actions/go-test-monorepo-action/go-test-monorepo-action.sh ${{ inputs.only-module-list }}
run: |
if [[ "${{ steps.determine-os.outputs.os }}" == "linux" ]]; then
./.github/actions/go-test-monorepo-action/go-test-monorepo-action.sh ${{ inputs.only-module-list }}
elif [[ "${{ steps.determine-os.outputs.os }}" == "windows" ]]; then
pwsh -File ./.github/actions/go-test-monorepo-action/go-test-monorepo-action.ps1 ${{ inputs.only-module-list }}
else
echo "Unsupported OS"
exit 1
fi
shell: bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Check if only module list should be outputted
$ONLY_MODULE_LIST = $args[0]

# Array to hold module paths
$modules = @()

# Find all directories containing a go.mod file
Get-ChildItem -File -Recurse -Filter "go.mod" | ForEach-Object {
$module = $_.DirectoryName
$modules += $module

# Run tests only if ONLY_MODULE_LIST is not "true"
if ($ONLY_MODULE_LIST -ne "true") {
Write-Host "Testing and generating coverage for module: $module"
Set-Location $module
go test -race -coverpkg=./... -coverprofile=coverage.out -timeout=1m ./...
Set-Location ..
}
}

# Convert modules array to JSON array format
$modules_json = $modules | ConvertTo-Json

# Output the modules for the matrix
Write-Host "modules=$modules_json"

# If running in GitHub Actions, set info message
if ($env:GITHUB_ACTIONS -eq "true") {
Write-Host "::info::Monorepo modules: $modules_json"
}
26 changes: 13 additions & 13 deletions .github/workflows/main.yml → .github/workflows/monorepo-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Lint all packages
uses: ./.github/actions/golangci-lint-monorepo-action
uses: ./.github/actions/golangci-lint-action
with:
go-version: '>=1.21.0'
golangci-lint-version: latest

list-monorepo-modules:
list-modules:
needs: lint
runs-on: ubuntu-latest
outputs:
Expand All @@ -36,24 +36,24 @@ jobs:

- name: Get monorepo modules
id: modulelist
uses: ./.github/actions/go-test-monorepo-action
uses: ./.github/actions/go-test-action
with:
go-version: '>=1.21.0'
only-module-list: true

monorepo-coverage-linux:
needs: list-monorepo-modules
coverage-linux:
needs: list-modules
runs-on: ubuntu-latest
strategy:
matrix:
module: ${{ fromJson(needs.list-monorepo-modules.outputs.modules) }}
module: ${{ fromJson(needs.list-modules.outputs.modules) }}
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Run tests and generate coverage reports
id: modulelist
uses: ./.github/actions/go-test-monorepo-action
uses: ./.github/actions/go-test-action
with:
go-version: '>=1.21.0'

Expand Down Expand Up @@ -88,19 +88,19 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ matrix.module }}/coverage.out

monorepo-coverage-windows:
needs: list-monorepo-modules
coverage-windows:
needs: list-modules
runs-on: windows-latest
strategy:
matrix:
module: ${{ fromJson(needs.list-monorepo-modules.outputs.modules) }}
module: ${{ fromJson(needs.list-modules.outputs.modules) }}
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Run tests and generate coverage reports on Windows
id: modulelist-windows
uses: ./.github/actions/go-test-monorepo-action
uses: ./.github/actions/go-test-action
with:
go-version: '>=1.21.0'
platform: windows
Expand Down Expand Up @@ -138,8 +138,8 @@ jobs:

finish-coverage-report:
needs:
- monorepo-coverage-linux
- monorepo-coverage-windows
- coverage-linux
- coverage-windows
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down

0 comments on commit 51cf3bd

Please sign in to comment.