Skip to content

Commit

Permalink
feat: Update action.yml for yamlfmt version handling (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-lab authored Sep 16, 2024
1 parent 0f32674 commit 09b4792
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
28 changes: 28 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@

YAML ファイルを自動的に整形するための GitHub Actions 用アクションです。コードの一貫性を保ち、レビューやデバッグを容易にします。

## TL;DR

```yaml
name: YAML Formatting

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@v1
```
## 特徴
- **自動フォーマット**: `yamlfmt` を使用して YAML ファイルを統一的に整形。
Expand Down Expand Up @@ -50,6 +77,7 @@ jobs:

アクションには以下の入力パラメータがあります。

- `version`: `yamlfmt` のバージョン (デフォルト: `latest`, 例: `v0.13.0`)
- `path`: フォーマットする YAML ファイルまたはディレクトリのパス
- `dstar`: ダブルスター展開を有効にする
- `exclude`: 指定したパターンに一致するファイルを除外
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ English | [日本語](README.ja.md)

Automatically format YAML files using `yamlfmt` in your GitHub Actions workflows. This action helps maintain consistent code style, making reviews and debugging easier.

## TL;DR

```yaml
name: YAML Formatting

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@v1
```
## Features
- **Automatic Formatting**: Uses `yamlfmt` to standardize the formatting of YAML files.
Expand Down Expand Up @@ -50,6 +77,7 @@ jobs:

The action supports the following input parameters:

- `version`: Version of `yamlfmt` to use (default: `latest`, e.g., `v0.13.0`)
- `path`: Path to the YAML file or directory to format
- `dstar`: Enable double-star expansion
- `exclude`: Exclude files matching the specified pattern
Expand Down
16 changes: 13 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ branding:
color: gray-dark

inputs:
version:
description: 'The version of yamlfmt to use'
required: false
default: 'latest'
path:
description: 'Path to the YAML file or directory to format'
required: false
Expand Down Expand Up @@ -56,8 +60,14 @@ runs:
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
name: Get yamlfmt version
run: |
if [ "${{ inputs.version }}" = "latest" ]; then
version=$(go list -m -versions -json github.com/google/yamlfmt | jq -r '.Versions[-1]')
else
version="${{ inputs.version }}"
fi
echo "version=$version" >> $GITHUB_OUTPUT
shell: bash

- id: cache_gobin
Expand All @@ -69,7 +79,7 @@ runs:

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

- id: build_command
Expand Down

0 comments on commit 09b4792

Please sign in to comment.