Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-lab committed Aug 12, 2024
1 parent 9d8e68b commit 22bb045
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: yamllint
uses: reviewdog/action-yamllint@v1
with:
github_token: ${{ secrets.github_token }}
fail_on_error: true
- name: yamlfmt
uses: yk-lab/yamlfmt-action@main
with:
path: .
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"bluebrown.yamlfmt"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.formatOnSave": true,
"[yaml]": {
"editor.tabSize": 2,
"editor.defaultFormatter": "bluebrown.yamlfmt"
}
}
2 changes: 2 additions & 0 deletions .yamlfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
formatter:
retain_line_breaks: true
120 changes: 120 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: 'yamlfmt action'
description: 'Format YAML files using yamlfmt'

branding:
icon: zap
color: gray-dark

inputs:
path:
description: 'Path to the YAML file or directory to format'
required: false
default: '.'
dstar:
description: 'Enable double-star expansion'
required: false
default: ''
exclude:
description: 'Exclude files matching the given pattern'
required: false
default: ''
gitignore_excludes:
description: 'Exclude files matching the patterns in .gitignore'
required: false
default: true
gitignore_path:
description: 'Path to the .gitignore file'
required: false
default: ''
extensions:
description: 'Comma-separated list of file extensions to include'
required: false
default: ''
formatter:
description: 'Configures the formatter to use'
required: false
default: ''

runs:
using: "composite"
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
cache: false

- id: get_gobin
name: Get GOBIN
run: |
gobin=$(go env GOBIN)
if [ -z "$gobin" ]; then
gobin=$(go env GOPATH)/bin
fi
echo "path=$gobin" >> $GITHUB_OUTPUT
shell: bash

- id: get_yamlfmt_version
name: Get yamlfmt latest version
run: echo "version=$(go list -m -versions -json github.com/google/yamlfmt | jq -r '.Versions[-1]')" >> $GITHUB_OUTPUT
shell: bash

- id: cache_gobin
name: Cache GOBIN
uses: actions/cache@v4
with:
path: ${{ steps.get_gobin.outputs.path }}
key: yamlfmt-${{ runner.os }}-${{ runner.arch }}-${{ steps.get_yamlfmt_version.outputs.version }}

- name: Install yamlfmt
if: steps.cache_gobin.outputs.cache-hit != 'true'
run: go install github.com/google/yamlfmt/cmd/yamlfmt@latest
shell: bash

- id: build_command
name: Build command options
run: |
cmd="yamlfmt -lint"
# Check if 'path' is not the default value
if [ "${{ inputs.path }}" != "" ]; then
cmd="$cmd ${{ inputs.path }}"
fi
# Check if 'dstar' is enabled
if [ "${{ inputs.dstar }}" != "" ]; then
cmd="$cmd --dstar ${{ inputs.dstar }}"
fi
# Check if 'exclude' has a value
if [ "${{ inputs.exclude }}" != "" ]; then
cmd="$cmd --exclude ${{ inputs.exclude }}"
fi
# Check if 'gitignore_excludes' is true
if [ "${{ inputs.gitignore_excludes }}" == "true" ]; then
cmd="$cmd --gitignore-excludes"
fi
# Check if 'gitignore_path' has a value
if [ "${{ inputs.gitignore_path }}" != "" ]; then
cmd="$cmd --gitignore-path ${{ inputs.gitignore_path }}"
fi
# Check if 'extensions' has a value
if [ "${{ inputs.extensions }}" != "" ]; then
cmd="$cmd --extensions ${{ inputs.extensions }}"
fi
# Check if 'formatter' has a value
if [ "${{ inputs.formatter }}" != "" ]; then
cmd="$cmd --formatter ${{ inputs.formatter }}"
fi
echo "command=$cmd" >> $GITHUB_OUTPUT
shell: bash

- name: Run yamlfmt
run: ${{ steps.build_command.outputs.command }}
shell: bash

0 comments on commit 22bb045

Please sign in to comment.