diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..fabf8f6 --- /dev/null +++ b/.github/workflows/linter.yaml @@ -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 \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..6e7ecff --- /dev/null +++ b/.github/workflows/release.yaml @@ -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-* \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..03cbda9 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5e82d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8e748b0 --- /dev/null +++ b/Makefile @@ -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) \ No newline at end of file diff --git a/README.md b/README.md index 71d6a32..bb132f9 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,54 @@ -# YAML File Merger +yaml-merger +[![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 && 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. @@ -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: @@ -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. diff --git a/doc/yaml-merger.png b/doc/yaml-merger.png new file mode 100644 index 0000000..5c97f5f Binary files /dev/null and b/doc/yaml-merger.png differ diff --git a/example/helm/README.md b/example/helm/README.md new file mode 100644 index 0000000..b1bd4ee --- /dev/null +++ b/example/helm/README.md @@ -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. diff --git a/example/helm/deployment.yaml b/example/helm/deployment.yaml new file mode 100644 index 0000000..e69de29 diff --git a/example/swagger/config_file_1.yaml b/example/swagger/config_file_1.yaml new file mode 100644 index 0000000..eecf675 --- /dev/null +++ b/example/swagger/config_file_1.yaml @@ -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" \ No newline at end of file diff --git a/examples/swagger/config_file_2.yaml b/example/swagger/config_file_2.yaml similarity index 100% rename from examples/swagger/config_file_2.yaml rename to example/swagger/config_file_2.yaml diff --git a/examples/swagger/config_file_3.yaml b/example/swagger/config_file_3.yaml similarity index 100% rename from examples/swagger/config_file_3.yaml rename to example/swagger/config_file_3.yaml diff --git a/examples/swagger/config_file_1.yaml b/examples/swagger/config_file_1.yaml deleted file mode 100644 index ba5f44e..0000000 --- a/examples/swagger/config_file_1.yaml +++ /dev/null @@ -1,29 +0,0 @@ -openapi: 3.0.0 -info: - title: Sample API 1 - version: 1.0.0 -paths: - /api/v1/resource1: - get: - summary: Get Resource 1 - responses: - '200': - description: Successful response - content: - application/json: - schema: - type: object - properties: - id: - type: string - name: - type: string -components: - schemas: - Resource1: - type: object - properties: - id: - type: string - name: - type: string diff --git a/merge.go b/merge.go new file mode 100644 index 0000000..85f0393 --- /dev/null +++ b/merge.go @@ -0,0 +1 @@ +package main \ No newline at end of file diff --git a/openapi.go b/openapi.go new file mode 100644 index 0000000..85f0393 --- /dev/null +++ b/openapi.go @@ -0,0 +1 @@ +package main \ No newline at end of file diff --git a/yaml.go b/yaml.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/yaml.go @@ -0,0 +1 @@ +package main