ci: update workflow for cross-platform compatibility in GitHub Actions #14
This file contains 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: monorepo-main | |
concurrency: | |
group: main-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- 'main' | |
tags-ignore: | |
- 'main' | |
pull_request: | |
branches: | |
- 'main' | |
workflow_dispatch: | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Lint all packages | |
uses: ./.github/actions/golangci-lint-monorepo-action | |
with: | |
go-version: '>=1.21.0' | |
golangci-lint-version: latest | |
list-modules: | |
needs: lint | |
runs-on: ubuntu-latest | |
outputs: | |
modules: ${{ steps.modulelist.outputs.modules }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get monorepo modules | |
id: modulelist | |
uses: ./.github/actions/go-test-monorepo-action | |
with: | |
go-version: '>=1.21.0' | |
only-module-list: true | |
coverage: | |
needs: list-modules | |
strategy: | |
matrix: | |
module: ${{ fromJson(needs.list-modules.outputs.modules) }} | |
platform: [ubuntu-latest, macos-latest, windows-latest] | |
fail-fast: false | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run tests and generate coverage reports | |
id: modulelist | |
uses: ./.github/actions/go-test-monorepo-action | |
with: | |
go-version: '>=1.21.0' | |
- name: Check if coverage data exists | |
if: success() || failure() | |
id: check-coverage | |
working-directory: ${{ matrix.module }} | |
run: | | |
if [[ -f coverage.out && $(wc -l <coverage.out) -gt 1 ]]; then | |
echo "coverage_data_exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "coverage_data_exists=false" >> $GITHUB_OUTPUT | |
fi | |
shell: bash | |
- name: Prepare flag name | |
id: prepare-flag | |
shell: bash | |
run: | | |
if [ "${{ runner.os }}" = "Windows" ]; then | |
# PowerShell commands for Windows runner | |
$module_name = "${{ matrix.module }}" | |
$clean_module_name = $module_name.TrimStart('./') # Remove leading ./ | |
if ($clean_module_name -eq ".") { $clean_module_name = "happy" } | |
echo "clean_module_name=$clean_module_name" | Out-File -Append -FilePath $Env:GITHUB_OUTPUT | |
else | |
# Bash commands for Ubuntu and macOS runners | |
module_name="${{ matrix.module }}" | |
clean_module_name="${module_name#./}" # Remove leading ./ | |
if [[ "$clean_module_name" == "." ]]; then | |
clean_module_name="happy" | |
fi | |
echo "clean_module_name=$clean_module_name" >> $GITHUB_OUTPUT | |
fi | |
- name: Upload coverage | |
if: steps.check-coverage.outputs.coverage_data_exists == 'true' | |
uses: coverallsapp/github-action@v2 | |
with: | |
flag-name: ${{ steps.prepare-flag.outputs.clean_module_name }} | |
parallel: true | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
file: ${{ matrix.module }}/coverage.out | |
finish-coverage-report: | |
needs: coverage | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
steps: | |
- name: Coveralls Finish | |
uses: coverallsapp/github-action@v2 | |
with: | |
parallel-finished: true |