Skip to content

Commit

Permalink
ci: add linting for yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Sep 11, 2024
1 parent 1bbe4f7 commit 6165bf2
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 43 deletions.
35 changes: 35 additions & 0 deletions .github/scripts/get-yamlfmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

if [ $# -ne 3 ]; then
echo "Usage: $0 <os> <arch> <version>"
echo "eg: $0 Linux x86_64 0.13.0"
exit 1
fi

OS="$1"
ARCH="$2"
VERSION="$3"

cwd=$(pwd)

temp_dir=$(mktemp -d)
if [ ! -e ${temp_dir} ]; then
echo "Failed to create temporary directory."
exit 1
fi

cd $temp_dir

curl -sSLO "https://github.com/google/yamlfmt/releases/download/v${VERSION}/yamlfmt_${VERSION}_${OS}_${ARCH}.tar.gz"
curl -sSLO "https://github.com/google/yamlfmt/releases/download/v${VERSION}/checksums.txt"

sha256sum --ignore-missing -c checksums.txt

tar -xzf "yamlfmt_${VERSION}_${OS}_${ARCH}.tar.gz" -C ${temp_dir}/
cd $cwd

cp "${temp_dir}/yamlfmt" .

rm -r ${temp_dir}
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: build

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
paths:
- "go.*"
Expand All @@ -20,14 +20,14 @@ jobs:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go build
run: go build -v ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go build
run: go build -v ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
22 changes: 22 additions & 0 deletions .github/workflows/lint-yml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lint-yml

on:
push:
branches: ["main"]
paths:
- "**.yml"
pull_request:
paths:
- "**.yml"

jobs:
lint-yml:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get yamlfmt
run: |
LATEST_VERSION=$(curl -s https://api.github.com/repos/google/yamlfmt/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/^v//')
./.github/scripts/get-yamlfmt.sh "Linux" "x86_64" "$LATEST_VERSION"
- name: Run yamlfmt
run: ./yamlfmt -lint -quiet $(find . -name '*.yml')
40 changes: 20 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build
run: go build -v ./...
- name: Install Cosign
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.3'
- name: Release Binaries
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{secrets.GH_PAT}}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build
run: go build -v ./...
- name: Install Cosign
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.3'
- name: Release Binaries
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{secrets.GH_PAT}}
22 changes: 11 additions & 11 deletions .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: vulncheck
on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
paths:
- "go.*"
Expand All @@ -19,13 +19,13 @@ jobs:
name: vulncheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: govulncheck
shell: bash
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: govulncheck
shell: bash
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
2 changes: 2 additions & 0 deletions yamlfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
formatter:
retain_line_breaks_single: true

0 comments on commit 6165bf2

Please sign in to comment.