Skip to content

Commit 0f5d764

Browse files
KenEkanemdmathieu
andauthored
[chore] Added a workflow to lint YAML files using actionlint (#12721)
#### Description This pull request builds on the work done in #11493 This PR introduces Actionlint as part of the project to enable linting of GitHub Workflow files. The changes ensure that Actionlint is installed locally within the project and is automatically run during pull requests to enforce consistency and best practices for workflow files. - Added a `actionlint` target to the Makefile for running Actionlint on workflow files. - Added actionlint configuration to `.github/actionlint.yaml` - update `internal/tools/go.mod` and `internal/tools/go.sum` - Ignored some shellcheck errors (with comments) since shellcheck isn't always right. #### Link to tracking issue #9676 #### Fixes - Addresses potential linting errors in workflow files after changes are made. #### Testing - The workflow has been tested to ensure the changes resolve identified issues and maintain functionality. - Verified that `make actionlint` runs correctly using the local binary. - Confirmed that the GitHub Actions workflow triggers automatically when relevant files are changed in a pull request. - Tested for proper error handling and feedback during linting failures. #### Documentation No new documentation added, as this change is self-explanatory within the context of CI. --------- Co-authored-by: Damien Mathieu <[email protected]>
1 parent 079c78c commit 0f5d764

File tree

7 files changed

+103
-2
lines changed

7 files changed

+103
-2
lines changed

.github/actionlint.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
self-hosted-runner:
2+
labels: []
3+
4+
config-variables: null
5+
6+
paths:
7+
.github/workflows/**/*.{yml,yaml}:
8+
ignore:
9+
# SC1070: Suppressing because scripts intentionally contain valid but unusual characters,
10+
# Escape characters like `\o` used purposefully, and tested for clarity
11+
- '.*shellcheck reported issue in this script: SC1070:.+'
12+
13+
# SC1133: ShellCheck suggests optimizing conditional expressions, but these scripts
14+
# operate correctly and readability is prioritized in real-world use. This ensures familiarity for contributors.
15+
- '.*shellcheck reported issue in this script: SC1133:.+'
16+
17+
# SC2086: Ignored because word splitting is intentional in commands like `git diff`,
18+
# where simple, predictable paths are passed as arguments. No unintended globbing occurs in this context.
19+
- '.*shellcheck reported issue in this script: SC2086:.+'
20+
21+
# SC2046: Suppressed because word splitting is desired and necessary in certain scenarios,
22+
# PR_HEAD is set by GitHub Actions and paths are fixed/controlled.
23+
- '.*shellcheck reported issue in this script: SC2046:.+'
24+
25+
# SC2059: Format strings in `printf` are deliberately designed and controlled for specific outputs.
26+
# ShellCheck’s safeguard warning is appreciated but not critical in these cases.
27+
- '.*shellcheck reported issue in this script: SC2059:.+'
28+
29+
# SC2236: Both `! -z` and `-n` achieve the same result, and while `-n` is idiomatic. (Just a style suggestion)
30+
# suppressing this warning allows scripts to remain consistent with existing standards.
31+
- '.*shellcheck reported issue in this script: SC2236:.+'
32+
33+
# SC1001: Escaped characters (like `\o`) are deliberate in certain scripts for expected functionality.
34+
# ShellCheck’s flagging of these characters as potential issues isn’t applicable to this use case.
35+
- '.*shellcheck reported issue in this script: SC1001:.+'
36+
37+
# SC2129: Individual redirections are chosen for simplicity and clarity in the workflows.
38+
# combining them is technically efficient, the current approach ensures more readable scripts.
39+
- '.*shellcheck reported issue in this script: SC2129:.+'
40+
41+
# Runner warnings ignored because scripts are validated against specific configurations
42+
# and tested on GitHub Actions, ensuring compatibility. These warnings do not affect functionality.
43+
- '.*the runner of ".+" action is too old to run on GitHub Actions.+'
44+

.github/workflows/generate-semantic-conventions-pr.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
VERSION: ${{ needs.check-versions.outputs.latest-version }}
8383
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
8484
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
85+
8586
run: |
8687
message="Add semantic conventions version $VERSION"
8788
body="Add semantic conventions version \`$VERSION\`. Related to #10842"
@@ -105,5 +106,7 @@ jobs:
105106
url=$(gh pr create --title "$message" \
106107
--body "$body" \
107108
--base main)
108-
109-
pull_request_number=${url//*\//}
109+
# The SC2034 warning is disabled because 'pull_request_number' is assigned but not used directly.
110+
# ShellCheck flags this as unused, but it's stored for potential external usage.
111+
# shellcheck disable=SC2034
112+
pull_request_number=${url//*\//}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Lint GitHub Workflow YAML Files
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/*.yml'
7+
- '.github/workflows/*.yaml'
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.24'
21+
22+
- name: Install Actionlint
23+
run: |
24+
mkdir -p .tools
25+
cd internal/tools
26+
go install github.com/rhysd/actionlint/cmd/[email protected]
27+
mv $(go env GOPATH)/bin/actionlint ../../.tools/actionlint
28+
29+
- name: Run Actionlint
30+
run: |
31+
make actionlint
32+
33+
- name: Reminder to Address Linting Errors
34+
if: failure()
35+
run: echo "⚠️ Please address all linting errors before merging this pull request."
36+
37+
- name: All linting checks passed
38+
if: success()
39+
run: echo "✅ All linting checks passed."

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ otelcorecol:
163163
genotelcorecol: install-tools
164164
pushd cmd/builder/ && $(GOCMD) run ./ --skip-compilation --config ../otelcorecol/builder-config.yaml --output-path ../otelcorecol && popd
165165
$(MAKE) -C cmd/otelcorecol fmt
166+
cd internal/tools && $(GOCMD) install github.com/rhysd/actionlint/cmd/[email protected]
167+
168+
.PHONY: actionlint
169+
actionlint:
170+
./.tools/actionlint -config-file .github/actionlint.yaml -color .github/workflows/*.yml .github/workflows/*.yaml
166171

167172
.PHONY: ocb
168173
ocb:

internal/tools/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/google/addlicense v1.1.1
1212
github.com/jcchavezs/porto v0.7.0
1313
github.com/pavius/impi v0.0.3
14+
github.com/rhysd/actionlint v1.7.7
1415
go.opentelemetry.io/build-tools/checkfile v0.21.0
1516
go.opentelemetry.io/build-tools/chloggen v0.21.0
1617
go.opentelemetry.io/build-tools/crosslink v0.21.0
@@ -151,6 +152,7 @@ require (
151152
github.com/mattn/go-colorable v0.1.14 // indirect
152153
github.com/mattn/go-isatty v0.0.20 // indirect
153154
github.com/mattn/go-runewidth v0.0.16 // indirect
155+
github.com/mattn/go-shellwords v1.0.12 // indirect
154156
github.com/mgechev/revive v1.7.0 // indirect
155157
github.com/mitchellh/go-homedir v1.1.0 // indirect
156158
github.com/moricho/tparallel v0.3.2 // indirect
@@ -175,6 +177,7 @@ require (
175177
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
176178
github.com/raeperd/recvcheck v0.2.0 // indirect
177179
github.com/rivo/uniseg v0.4.7 // indirect
180+
github.com/robfig/cron/v3 v3.0.1 // indirect
178181
github.com/rogpeppe/go-internal v1.14.1 // indirect
179182
github.com/ryancurrah/gomodguard v1.4.1 // indirect
180183
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect

internal/tools/go.sum

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tools/tools.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
_ "github.com/google/addlicense"
1818
_ "github.com/jcchavezs/porto/cmd/porto"
1919
_ "github.com/pavius/impi/cmd/impi"
20+
_ "github.com/rhysd/actionlint/cmd/actionlint"
2021
_ "go.opentelemetry.io/build-tools/checkfile"
2122
_ "go.opentelemetry.io/build-tools/chloggen"
2223
_ "go.opentelemetry.io/build-tools/crosslink"

0 commit comments

Comments
 (0)