Skip to content

Commit

Permalink
Subtree splitter action
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Aug 16, 2021
0 parents commit 9fd4f90
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
splitsh
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Jeroen Thora

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# subtree-splitter action

This actions synchronizes a monolithic repository to standalone repositories by using [splitsh-lite](https://github.com/splitsh/lite).

## Usage

### Inputs

> Specify using `with` keyword
* `config-path` - **(Required)** Location of the subtree split mapping configuration
* `source-branch` - Source branch to execute the subtree split from

### Example workflow

#### Configuration

Create a configuration file with the mapping of the different subtree splits. Each subtree split item contains a name (must be unique),
directory in the current repository and a target git repository.

```json
{
"subtree-splits": [
{
"name": "core",
"directory": "src/Core",
"target": "[email protected]:example/core-package.git"
}
]
}

```

#### Workflow

Example workflow to sync commits and tags.

```yaml
on:
push:
create:
tags:
- '*'
delete:
tags:
- '*'

jobs:
sync_commits:
runs-on: ubuntu-latest
name: Sync commits
steps:
- uses: actions/checkout@v2

# Add a personal access token to the repository secrets. This will allow the splitter action to push the new commits
- uses: frankdejonge/[email protected]
with:
authentication: 'username:${{ secrets.PERSONAL_GITHUB_TOKEN }}'
user_name: 'Committer name'
user_email: 'Committer email'

# Cache the splitsh executable to speedup future runs
- name: Cache splitsh-lite
uses: actions/cache@v2
with:
path: './splitsh'
key: '${{ runner.os }}-splitsh-v101'

# Retrieve the branch name of the branch that triggered the build.
- name: Extract branch name
run: echo ::set-output name=branch_name::${GITHUB_REF#refs/*/}

# Sync commits and tags for the configured subtree splits
- name: subtree split
uses: acrobat/subtree-splitter@v1
with:
config-path: .github/subtree-splitter-config.json # Reference the location where you saved your config file
source-branch: ${{ steps.vars.outputs.branch_name }} # The branch name is used when syncing commits, this is ignored when a tag is pushed/deleted
```
15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'subtree-splitter'
description: 'Sync your git repository subtree-splits'
inputs:
config-path:
required: true
description: 'Configuration file path'
source-branch:
description: 'Branch to split from'
required: true
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: shuffle
color: yellow
7 changes: 7 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

198 changes: 198 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "subtree-splitter",
"private": true,
"engines": {
"node": "12"
},
"author": "Jeroen Thora",
"license": "MIT",
"scripts": {
"compile": "ncc build src/index.ts --minify"
},
"dependencies": {
"@actions/core": "^1.4.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@octokit/webhooks-types": "^4.3.0"
},
"devDependencies": {
"@types/node": "^16.6.1",
"typescript": "^4.3.5"
}
}
33 changes: 33 additions & 0 deletions src/helpers/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as fs from "fs";

function dirExists(path: string): void {
try {
fs.mkdirSync(path);
} catch (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
}

function removeDir(path: string) {
try {
fs.rmdirSync(path, { recursive: true });
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
}

function removeFile(path: string) {
try {
fs.unlinkSync(path);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
}

export { dirExists, removeDir, removeFile };
Loading

0 comments on commit 9fd4f90

Please sign in to comment.