Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
narze committed Oct 21, 2023
1 parent 12608ec commit 7cf6a7c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 69 deletions.
24 changes: 11 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Append on Merge"
description: "Github Action to combine files while preventing PR conflicts"
name: "Merge on Merge"
description: "Github Action to combine JSON files while preventing PR conflicts"
inputs:
github_token:
description: "Github Token"
Expand All @@ -10,17 +10,21 @@ inputs:
required: false
default: "preview"
input_path:
description: "input_path"
description: "JSON input folder"
required: false
default: "input"
base:
description: "base"
required: false
default: "README.md"
default: "out.json"
merge_json_path:
description: "JSON traverse path to merge the input in, use dot notation"
required: false
default: "json.path.to.merge"
output:
description: "output"
required: false
default: "README.md"
default: "out.json"
processed_path:
description: "processed_path"
required: false
Expand All @@ -34,16 +38,10 @@ runs:
steps:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
ruby-version: 3.2

# Change path, run the code
# - run: echo "${{ github.action_path }}" >> $GITHUB_PATH
# shell: bash
- shell: bash
run: ruby ${{ github.action_path }}/append_on_merge.rb "${{ inputs.input_path }}" "${{ inputs.base }}" "${{ inputs.output }}" "${{ inputs.processed_path }}"

# - shell: bash
# run: git status
run: ruby ${{ github.action_path }}/merge_on_merge.rb "${{ inputs.input_path }}" "${{ inputs.base }}" "${{ inputs.merge_json_path }}" "${{ inputs.output }}" "${{ inputs.processed_path }}"

# See diff & output diff for comment
- id: diff
Expand Down
47 changes: 0 additions & 47 deletions append_on_merge.rb

This file was deleted.

44 changes: 44 additions & 0 deletions merge_on_merge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby

require 'fileutils'
require 'json'
require "debug"

def run(input_path, base, merge_json_path, output, processed_path)
FileUtils.mkdir_p(processed_path)
FileUtils.mkdir_p(input_path)

puts "Consuming files in #{input_path} path"

files = Dir.open(input_path) do |input_dir|
FileUtils.touch File.join(Dir.pwd, input_dir, '.gitkeep')

Dir.glob(File.join(Dir.pwd, input_dir, '*.json'))
end

puts "Merging files to #{output}, using #{base} as base"

base = JSON.load_file!(base)
base_dest = base.dig(*merge_json_path.split("."))

files.each do |input_path|
json = JSON.load_file!(input_path)

base_dest.append(json)
end

output_json = JSON.pretty_generate(base)

puts "Writing to #{output}:"
puts output_json
puts '<EOF>'

File.open(output, 'w') do |f|
f.write(output_json)
end

# Move files to processed_path folder
FileUtils.mv files, processed_path, verbose: true
end

run(*ARGV)
4 changes: 0 additions & 4 deletions processed/test.md

This file was deleted.

5 changes: 0 additions & 5 deletions processed/test2.md

This file was deleted.

0 comments on commit 7cf6a7c

Please sign in to comment.