Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use yamlfmt binary directly #26

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
22 changes: 4 additions & 18 deletions .github/workflows/lint-yml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@ on:
paths:
- "**.yml"

env:
GO_VERSION: '1.23.0'

jobs:
lint-yml:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
yml:
- added|modified: '**.yml'
- name: Set up Go
if: steps.changes.outputs.yml == 'true'
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Get yamlfmt
if: steps.changes.outputs.yml == 'true'
run: go install github.com/google/yamlfmt/cmd/yamlfmt@latest
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
if: steps.changes.outputs.yml == 'true'
run: yamlfmt -lint -quiet $(find . -name '*.yml')
run: ./yamlfmt -lint -quiet $(find . -name '*.yml')
Loading