Skip to content

Commit 6f4278b

Browse files
committed
ci: adding GitHub Actions workflow formatting check
1 parent 227841d commit 6f4278b

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

.github/workflows/github-actions-workflows.yml

+10
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ jobs:
1717
uses: actions/checkout@v3
1818
- name: Check GitHub Actions workflows linting.
1919
run: earthly +check-github-actions-workflows-linting
20+
formatting:
21+
name: Formatting
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Download Earthly v0.8.6.
25+
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.6/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
26+
- name: Checkout code.
27+
uses: actions/checkout@v3
28+
- name: Check formatting.
29+
run: earthly +check-yaml-formatting

Earthfile

+27-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,34 @@ check-conventional-commits-linting:
3333
RUN ./ci/check-conventional-commits-linting.sh --from-reference "${from_reference}"
3434

3535

36-
check-github-actions-workflows-linting:
36+
golang-base:
3737
FROM golang:1.20.13
38+
ENV GOPROXY=direct
39+
ENV CGO_ENABLED=0
40+
ENV GOOS=linux
41+
ENV GOARCH=amd64
42+
43+
44+
yaml-formatting-base:
45+
FROM +golang-base
46+
RUN go install github.com/google/yamlfmt/cmd/yamlfmt@v0.10.0
47+
COPY ".yamlfmt" "./"
48+
DO +COPY_CI_DATA
49+
50+
51+
check-yaml-formatting:
52+
FROM +yaml-formatting-base
53+
RUN ./ci/check-yaml-formatting.sh
54+
55+
56+
fix-yaml-formatting:
57+
FROM +yaml-formatting-base
58+
RUN ./ci/fix-yaml-formatting.sh
59+
SAVE ARTIFACT ".github/" AS LOCAL "./"
60+
61+
62+
check-github-actions-workflows-linting:
63+
FROM +golang-base
3864
RUN go install github.com/rhysd/actionlint/cmd/actionlint@v1.6.26
3965
DO +COPY_CI_DATA
4066
RUN ./ci/check-github-actions-workflows-linting.sh

ci/check-yaml-formatting.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o xtrace
5+
6+
yamlfmt -lint -dstar .github/**/*

ci/fix-yaml-formatting.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
3+
set -o errexit
4+
set -o xtrace
5+
6+
yamlfmt -dstar ./github/**/*

0 commit comments

Comments
 (0)