diff --git a/.github/workflows/go.yml b/.github/workflows/validate.yml similarity index 95% rename from .github/workflows/go.yml rename to .github/workflows/validate.yml index 1bf5121ce..73c19bea2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/validate.yml @@ -1,68 +1,71 @@ ---- -name: Go -on: - pull_request: - push: - branches: - - main - - "release-*" - -# Modified to avoid canceling all matrix jobs when one fails -# Each job type will have its own concurrency group -concurrency: - group: ${{ github.workflow }}-${{ github.job }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} - cancel-in-progress: true - -# Minimal permissions to be inherited by any job that don't declare it's own permissions -permissions: - contents: read - -jobs: - supportedVersions: - name: Fetch supported Go versions - runs-on: ubuntu-latest - outputs: - supported_versions: ${{ steps.matrix.outputs.supported_versions }} - steps: - - name: Checkout code +--- +name: Validate +on: + pull_request: + push: + branches: + - main + - "release-*" + +# Modified to avoid canceling all matrix jobs when one fails +# Each job type will have its own concurrency group +concurrency: + group: ${{ github.workflow }}-${{ github.job }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} + cancel-in-progress: true + +# Minimal permissions to be inherited by any job that don't declare it's own permissions +permissions: + contents: read + +jobs: + supported_versions: + name: Fetch supported Go versions + runs-on: ubuntu-latest + outputs: + supported_versions: ${{ steps.matrix.outputs.supported_versions }} + steps: + - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Read supported_go_versions.txt - id: matrix - run: | - versions=$(cat supported_go_versions.txt) - matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" - echo "supported_versions=$matrix" >> $GITHUB_OUTPUT - - test: - name: Tests (${{ matrix.go_version }}) - runs-on: ubuntu-latest - needs: supportedVersions - # Set fail-fast to false to ensure all Go versions are tested regardless of failures - strategy: - fail-fast: false - matrix: - go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} - # Define concurrency at the job level for matrix jobs - concurrency: - group: ${{ github.workflow }}-test-${{ matrix.go_version }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} - cancel-in-progress: true - - steps: - - name: Checkout code + - name: Read supported_go_versions.txt + id: matrix + run: | + versions=$(cat supported_go_versions.txt) + matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" + echo "supported_versions=$matrix" >> $GITHUB_OUTPUT + + test: + name: Tests (${{ matrix.go_version }}) + runs-on: ubuntu-latest + needs: supportedVersions + # Set fail-fast to false to ensure all Go versions are tested regardless of failures + strategy: + fail-fast: false + matrix: + go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} + # Define concurrency at the job level for matrix jobs + concurrency: + group: ${{ github.workflow }}-test-${{ matrix.go_version }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} + cancel-in-progress: true + + steps: + - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v6.0.0 - with: - go-version: ${{ matrix.go_version }} - check-latest: true - cache-dependency-path: go.sum - - - name: Run tests and check license - run: make check_license test - env: - CI: true - - - name: Run style and unused - if: ${{ matrix.go_version == '1.22' }} - run: make style unused + + - name: Check for CRLF line endings + run: make check-crlf + + - name: Set up Go ${{ matrix.go_version }} + uses: actions/setup-go@v6.0.0 + with: + go-version: ${{ matrix.go_version }} + check-latest: true + cache-dependency-path: go.sum + + - name: Run tests and check license + run: make check_license test + env: + CI: true + + - name: Run style and unused + if: ${{ matrix.go_version == '1.22' }} + run: make style unused diff --git a/Makefile b/Makefile index 2a5817c02..ff01ce882 100644 --- a/Makefile +++ b/Makefile @@ -65,3 +65,23 @@ test-exp: .PHONY: test-exp-short test-exp-short: cd exp && $(GOTEST) -short $(GOOPTS) $(pkgs) + +.PHONY: check-crlf +check-crlf: + @echo ">> checking for CRLF line endings" + @files=$$(find . -type f -not -path "*/\.*" -not -path "*/vendor/*" -exec file {} \; | grep CRLF | cut -d: -f1); \ + if [ -n "$$files" ]; then \ + echo "Files with CRLF line endings found:"; \ + echo "$$files"; \ + echo "Run 'make fix-crlf' to fix them"; \ + exit 1; \ + fi + +.PHONY: fix-crlf +fix-crlf: + @echo ">> fixing CRLF line endings" + @files=$$(find . -type f -not -path "*/\.*" -not -path "*/vendor/*" -exec file {} \; | grep CRLF | cut -d: -f1); \ + for file in $$files; do \ + tr -d '\r' < "$$file" > "$$file.tmp" && mv "$$file.tmp" "$$file"; \ + done + @echo ">> CRLF line endings fixed"