Skip to content

Commit c316de0

Browse files
authored
chore(ci): Add CRLF detection and fix targets to prevent CRLF contamination (#1898)
1 parent a5ae203 commit c316de0

File tree

2 files changed

+89
-66
lines changed

2 files changed

+89
-66
lines changed
Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,71 @@
1-
---
2-
name: Go
3-
on:
4-
pull_request:
5-
push:
6-
branches:
7-
- main
8-
- "release-*"
9-
10-
# Modified to avoid canceling all matrix jobs when one fails
11-
# Each job type will have its own concurrency group
12-
concurrency:
13-
group: ${{ github.workflow }}-${{ github.job }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
14-
cancel-in-progress: true
15-
16-
# Minimal permissions to be inherited by any job that don't declare it's own permissions
17-
permissions:
18-
contents: read
19-
20-
jobs:
21-
supportedVersions:
22-
name: Fetch supported Go versions
23-
runs-on: ubuntu-latest
24-
outputs:
25-
supported_versions: ${{ steps.matrix.outputs.supported_versions }}
26-
steps:
27-
- name: Checkout code
1+
---
2+
name: Validate
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- "release-*"
9+
10+
# Modified to avoid canceling all matrix jobs when one fails
11+
# Each job type will have its own concurrency group
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.job }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
# Minimal permissions to be inherited by any job that don't declare it's own permissions
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
supported_versions:
22+
name: Fetch supported Go versions
23+
runs-on: ubuntu-latest
24+
outputs:
25+
supported_versions: ${{ steps.matrix.outputs.supported_versions }}
26+
steps:
27+
- name: Checkout code
2828
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
29-
- name: Read supported_go_versions.txt
30-
id: matrix
31-
run: |
32-
versions=$(cat supported_go_versions.txt)
33-
matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]"
34-
echo "supported_versions=$matrix" >> $GITHUB_OUTPUT
35-
36-
test:
37-
name: Tests (${{ matrix.go_version }})
38-
runs-on: ubuntu-latest
39-
needs: supportedVersions
40-
# Set fail-fast to false to ensure all Go versions are tested regardless of failures
41-
strategy:
42-
fail-fast: false
43-
matrix:
44-
go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }}
45-
# Define concurrency at the job level for matrix jobs
46-
concurrency:
47-
group: ${{ github.workflow }}-test-${{ matrix.go_version }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
48-
cancel-in-progress: true
49-
50-
steps:
51-
- name: Checkout code
29+
- name: Read supported_go_versions.txt
30+
id: matrix
31+
run: |
32+
versions=$(cat supported_go_versions.txt)
33+
matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]"
34+
echo "supported_versions=$matrix" >> $GITHUB_OUTPUT
35+
36+
test:
37+
name: Tests (${{ matrix.go_version }})
38+
runs-on: ubuntu-latest
39+
needs: supported_versions
40+
# Set fail-fast to false to ensure all Go versions are tested regardless of failures
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
go_version: ${{ fromJSON(needs.supported_versions.outputs.supported_versions) }}
45+
# Define concurrency at the job level for matrix jobs
46+
concurrency:
47+
group: ${{ github.workflow }}-test-${{ matrix.go_version }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }}
48+
cancel-in-progress: true
49+
50+
steps:
51+
- name: Checkout code
5252
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
53-
54-
- name: Set up Go ${{ matrix.go_version }}
55-
uses: actions/[email protected]
56-
with:
57-
go-version: ${{ matrix.go_version }}
58-
check-latest: true
59-
cache-dependency-path: go.sum
60-
61-
- name: Run tests and check license
62-
run: make check_license test
63-
env:
64-
CI: true
65-
66-
- name: Run style and unused
67-
if: ${{ matrix.go_version == '1.22' }}
68-
run: make style unused
53+
54+
- name: Check for CRLF line endings
55+
run: make check-crlf
56+
57+
- name: Set up Go ${{ matrix.go_version }}
58+
uses: actions/[email protected]
59+
with:
60+
go-version: ${{ matrix.go_version }}
61+
check-latest: true
62+
cache-dependency-path: go.sum
63+
64+
- name: Run tests and check license
65+
run: make check_license test
66+
env:
67+
CI: true
68+
69+
- name: Run style and unused
70+
if: ${{ matrix.go_version == '1.22' }}
71+
run: make style unused

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,23 @@ test-exp:
6565
.PHONY: test-exp-short
6666
test-exp-short:
6767
cd exp && $(GOTEST) -short $(GOOPTS) $(pkgs)
68+
69+
.PHONY: check-crlf
70+
check-crlf:
71+
@echo ">> checking for CRLF line endings"
72+
@files=$$(find . -type f -not -path "*/\.*" -not -path "*/vendor/*" -exec file {} \; | grep CRLF | cut -d: -f1); \
73+
if [ -n "$$files" ]; then \
74+
echo "Files with CRLF line endings found:"; \
75+
echo "$$files"; \
76+
echo "Run 'make fix-crlf' to fix them"; \
77+
exit 1; \
78+
fi
79+
80+
.PHONY: fix-crlf
81+
fix-crlf:
82+
@echo ">> fixing CRLF line endings"
83+
@files=$$(find . -type f -not -path "*/\.*" -not -path "*/vendor/*" -exec file {} \; | grep CRLF | cut -d: -f1); \
84+
for file in $$files; do \
85+
tr -d '\r' < "$$file" > "$$file.tmp" && mv "$$file.tmp" "$$file"; \
86+
done
87+
@echo ">> CRLF line endings fixed"

0 commit comments

Comments
 (0)