Skip to content

Commit

Permalink
ci: add linting for yml files (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth authored Sep 11, 2024
1 parent 1bbe4f7 commit 0872535
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 45 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}
26 changes: 12 additions & 14 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 @@ -17,17 +17,15 @@ env:

jobs:
build:
name: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
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 ./...
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')
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: lint

on:
push:
branches: ["main"]
pull_request:
paths:
- "go.*"
- "**/*.go"
- ".github/workflows/*.yml"

env:
GO_VERSION: '1.23.0'

jobs:
lint:
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: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
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 0872535

Please sign in to comment.