Skip to content

Commit

Permalink
Merge pull request #10 from dhyanio/dhyanio@6
Browse files Browse the repository at this point in the history
feat: improve README & setup
  • Loading branch information
dhyanio authored Dec 13, 2024
2 parents a18ae23 + b82554c commit e4c4afb
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 44 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: linter

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
linter:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
go_version_file: go.mod
github_token: ${{ secrets.GITHUB_TOKEN }}
tool_name: golangci-lint
37 changes: 37 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "tagged-release"
on:
workflow_dispatch:
inputs:
version:
description: Bump Version
required: true
jobs:
tagged-release:
name: "Tagged Release"
runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Test
run: go build -v && go test ./...
- name: Build for linux/amd64
run: go build -o yaml-merger-linux-amd64
- name: Build for linux/arm64
run: GOOS=linux GOARCH=arm64 go build -o yaml-merger-linux-arm64
- name: Build for mac
run: GOOS=darwin go build -o yaml-merger-darwin-amd64
- name: Build for mac Apple Silicon
run: GOOS=darwin GOARCH=arm64 go build -o yaml-merger-darwin-arm64

- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ github.event.inputs.version }}
prerelease: false
files: |
yaml-merger-*
27 changes: 27 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Go Mod Tidy
run: go mod tidy
- name: Test
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Variables
BINARY_NAME := yaml-merger
BINARY_DIR := bin
BINARY_PATH := $(BINARY_DIR)/$(BINARY_NAME)
GO_FILES := $(shell find . -type f -name '*.go')

# Targets
.PHONY: all build clean run runfollower test lint fmt

all: build

build: $(GO_FILES)
@mkdir -p $(BINARY_DIR)
go build -o $(BINARY_PATH)

test: build
@go test -v $(BINARY_PATH)/...

lint:
@golangci-lint run ./...

fmt:
@go fmt ./...

clean:
@rm -rf $(BINARY_DIR)
60 changes: 45 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
# YAML File Merger
<img src="./doc/yaml-merger.png" alt="yaml-merger" width="300"/>

[![tests](https://github.com/dhyanio/yaml-merger/actions/workflows/test.yaml/badge.svg)](https://github.com/dhyanio/yaml-merger/actions/workflows/test.yaml)
[![linter](https://github.com/dhyanio/yaml-merger/actions/workflows/linter.yaml/badge.svg)](https://github.com/dhyanio/yaml-merger/actions/workflows/linter.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/dhyanio/yaml-merger)](https://goreportcard.com/report/github.com/dhyanio/yaml-merger)
![Go Version](https://img.shields.io/badge/go%20version-%3E=1.23-61CFDD.svg?style=flat-square)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)

A simple yet powerful tool written in Go for merging multiple YAML files. This tool allows you to merge complex YAML structures such as lists and maps, with the ability to ignore specific keys during the merge process.

# Table of Contents
- [Installation](#installation)
- [Cli](#cli)

### 🚀 Installation

#### yaml-merger

**From releases**
This installs binary.

* Linux
```
curl -LO "https://github.com/dhyanio/yaml-merger/releases/download/$(curl -s https://api.github.com/repos/dhyanio/yaml-merger/releases/latest | grep tag_name | cut -d '"' -f 4)/yaml-merger-linux-amd64"
chmod +x yaml-merger-linux-amd64
sudo mv yaml-merger-linux-amd64 /usr/local/bin/yaml-merger
```
* MacOS
```
curl -LO "https://github.com/dhyanio/yaml-merger/releases/download/$(curl -s https://api.github.com/repos/dhyanio/discache/releases/latest | grep tag_name | cut -d '"' -f 4)/yaml-merger-darwin-amd64"
chmod +x yaml-merger-darwin-amd64
sudo mv yaml-merger-darwin-amd64 /usr/local/bin/yaml-merger
```

**From source**
1. Run `git clone <yaml-merger repo> && cd yaml-merger/`
2. Run `make build`

**Go install the tool, use the go install command:**

```bash
go install github.com/dhyanio/yaml-merger@latest
```
This will install the yaml-merger binary, which you can run from your terminal.

## CLI
A CLI tool has commands

## Use cases
- [Swagger](./examples/swagger/): Merge multiple swagger files into a swagger file, support JSON/YAML.

A simple yet powerful tool written in Go for merging multiple YAML files. This tool allows you to merge complex YAML structures such as lists and maps, with the ability to ignore specific keys during the merge process.

## 🔧 Features
- **Recursive Merging**: Handles nested structures, including lists and maps.
- **Ignore Keys**: Optionally exclude specific keys from merging.
Expand All @@ -17,17 +58,6 @@ A simple yet powerful tool written in Go for merging multiple YAML files. This t
- **Output**: Output merged content to the specified file.
- **Custom Merge Strategies**: Choose between merge (deep merge) and override for key conflicts.

## 🚀 Installation
To install the tool, use the go install command:

```bash
go install github.com/dhyanio/yaml-merger@latest
```
This will install the yaml-merger binary, which you can run from your terminal.

## Prerequisites
Go 1.16+ is required for the go install command.

## 📚 Usage
After installing the tool, you can run it from the command line:

Expand Down Expand Up @@ -113,7 +143,7 @@ The tool uses https://github.com/dhyanio/gogger for structured logging. Logs are
LOG_LEVEL=debug yaml-merger file1.yaml file2.yaml
```

##❗Error Handling
## ❗Error Handling
The tool provides detailed error messages in case of:

- File Read Errors: The tool will display an error message if a file cannot be read.
Expand Down
Binary file added doc/yaml-merger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions example/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## How Yaml-Merger helps in Helm charts

A YAML merger in Helm is helpful because Helm charts heavily rely on YAML files for configuration, and merging simplifies and streamlines the management of complex configurations. Here’s how it helps in the context of Helm:

1. Combine Values from Multiple Sources
Helm allows the use of multiple values.yaml files to override default chart configurations. A YAML merger ensures that:

Default values defined in values.yaml can be overridden with environment-specific configurations using custom files (e.g., production-values.yaml or staging-values.yaml).
Conflicts between these files are handled systematically, allowing overrides without overwriting unrelated keys.
Empty file added example/helm/deployment.yaml
Empty file.
30 changes: 30 additions & 0 deletions example/swagger/config_file_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
swagger: '2.0'
info:
version: 1.0.0
title: Echo
description: |
#### Echos back every URL, method, parameter and header
Feel free to make a path or an operation and use **Try Operation** to test it. The echo server will
render back everything.
schemes:
- http
host: mazimi-prod.apigee.net
basePath: /echo
paths:
/:
get:
responses:
$ref: "./responses.yaml#/components/root/get"
post:
responses:
$ref: "./responses.yaml#/components/root/post"
parameters:
- $ref: "./name.yaml"
- $ref: "./year.yaml"
/test-path/{id}:
parameters:
- $ref: "./id.yaml"
get:
responses:
$ref: "./responses.yaml#/components/test-path"
File renamed without changes.
File renamed without changes.
29 changes: 0 additions & 29 deletions examples/swagger/config_file_1.yaml

This file was deleted.

1 change: 1 addition & 0 deletions merge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
1 change: 1 addition & 0 deletions openapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
1 change: 1 addition & 0 deletions yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main

0 comments on commit e4c4afb

Please sign in to comment.