-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02415a5
Showing
37 changed files
with
2,077 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' # Only build tag with semantic versioning format | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# checkout the repository | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
# install upx to compress the binary | ||
- name: Install upx | ||
run: sudo apt-get install -y upx | ||
# Install specific version of go | ||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
# Run goreleaser with command line flag | ||
- name: Release | ||
uses: goreleaser/goreleaser-action@v2 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
version: latest | ||
args: -f .goreleaser.yml release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
on: [push, pull_request] | ||
name: Test | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18.x | ||
- uses: actions/checkout@v3 | ||
- name: Build the stack | ||
run: docker-compose up -d | ||
- name: Sleep while stack is starting | ||
uses: jakejarvis/wait-action@master | ||
with: | ||
time: '2s' | ||
- name: Run tests | ||
run: go test ./... | ||
- name: Run coverage | ||
run: go test ./... -race -coverprofile=coverage.out -covermode=atomic | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea | ||
.vscode | ||
**/.DS_Store | ||
.test/* | ||
!.test/migrations | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
project_name: 'scriptup' | ||
|
||
builds: | ||
- main: './main.go' | ||
goos: ['linux', 'darwin', 'windows'] | ||
goarch: ['386', 'amd64', 'arm', 'arm64'] | ||
goarm: ['6', '7'] | ||
env: | ||
- CGO_ENABLED=0 | ||
|
||
changelog: | ||
sort: 'asc' | ||
filters: | ||
exclude: ['^docs:', '^test:', 'Merge pull request', 'Merge branch'] | ||
|
||
archives: | ||
- format_overrides: | ||
- goos: 'windows' | ||
format: 'zip' | ||
wrap_in_directory: true | ||
files: | ||
- README.md | ||
|
||
nfpms: | ||
- homepage: 'https://github.com/mg98/scriptup' | ||
description: 'Migration tool for shell script executions' | ||
maintainer: 'Marcel Gregoriadis <[email protected]>' | ||
formats: ['deb', 'rpm'] | ||
dependencies: ['git'] | ||
|
||
brews: | ||
- tap: | ||
owner: 'mg98' | ||
name: 'homebrew-tap' | ||
folder: 'Formula' | ||
homepage: 'https://github.com/mg98/scriptup' | ||
description: 'Migration tool for shell script executions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### migrate up ### | ||
echo "hello world" > .test/foo.txt | ||
|
||
### migrate down ### | ||
rm .test/foo.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### migrate up ### | ||
echo 1 >> .test/foo.txt | ||
### migrate down ### | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
sed -i '$ d' .test/foo.txt | ||
else # macos | ||
sed -i '' -e '$ d' .test/foo.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### migrate up ### | ||
echo 2 >> .test/foo.txt | ||
### migrate down ### | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
sed -i '$ d' .test/foo.txt | ||
else # macos | ||
sed -i '' -e '$ d' .test/foo.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### migrate up ### | ||
echo 3 >> .test/foo.txt | ||
### migrate down ### | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
sed -i '$ d' .test/foo.txt | ||
else # macos | ||
sed -i '' -e '$ d' .test/foo.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [year] [fullname] | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<h1 align="center">scriptup ⬆️</h1> | ||
<p align="center"> | ||
A migration tool for shell script executions. | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/mg98/scriptup/actions/workflows/test.yml"> | ||
<img src="https://github.com/mg98/scriptup/actions/workflows/test.yml/badge.svg"> | ||
</a> | ||
<a href="https://pkg.go.dev/github.com/mg98/scriptup"> | ||
<img src="http://img.shields.io/badge/godoc-reference-blue.svg"/> | ||
</a> | ||
<a href="https://codecov.io/gh/mg98/scriptup"> | ||
<img src="https://codecov.io/gh/mg98/scriptup/branch/main/graph/badge.svg?token=R3OYXX1HC7"> | ||
</a> | ||
<a href="https://goreportcard.com/report/github.com/mg98/scriptup"> | ||
<img src="https://goreportcard.com/badge/github.com/mg98/scriptup"> | ||
</a> | ||
<a href="./LICENSE"> | ||
<img src="https://img.shields.io/github/license/mg98/scriptup"> | ||
</a> | ||
</p> | ||
|
||
<hr> | ||
|
||
_scriptup_ is a framework- and language-agnostic tool that enables software projects to maintain code-based migration scripts. | ||
This is very similar to database migration tools, just that it is based on shell instead of SQL executions. | ||
While traditional SQL migration frameworks aid deploying database changes to production systems and to other developer machines, | ||
_scriptup_ is able to perform state migrations using general-purpose code! | ||
Example use cases include complex data alterations in the database (e.g. encryption) or the installation of IDE extensions | ||
or even git hooks on developer machines. | ||
|
||
|
||
## Install and Setup | ||
|
||
The tool is run as a standalone binary. | ||
You can find the appropriate executable for your OS on the [Releases](https://github.com/mg98/scriptup/releases) page. | ||
However, macOS users are very welcome to install it via the package manager [brew](https://brew.sh). | ||
|
||
```sh | ||
brew tap mg98/homebrew-tap | ||
brew install scriptup | ||
|
||
# Verify your installation | ||
scriptup -v | ||
``` | ||
|
||
To setup _scriptup_ in your project, you have to create its configuration file in your project's root directory. | ||
Take [scriptup.yml](./scriptup.yml) as a template and adjust the values as needed. | ||
|
||
## Usage | ||
|
||
Create a new migration, e.g. | ||
|
||
```sh | ||
scriptup new add-git-hook | ||
``` | ||
|
||
This will create a new file in your configured migration folder, something like `20220626135412_add-git-hook.sh`. | ||
Edit the file to contain the script that you want to be executed when running this migration. | ||
|
||
As you will see from the template, the file is subdivided into two sections. | ||
Everything after `### migrate up ###` and before (an optional) `### migrate down ###` will be run on `scriptup up`. | ||
Everything after `### migrate down ###` will be executed on `scriptup down` and is supposed to undo the changes | ||
performed through the script in the _up_-section (your responsibility though). | ||
|
||
### CLI Reference | ||
|
||
``` | ||
COMMANDS: | ||
new, n Generate a new migration file | ||
up, u Execute recent scripts that have not been migrated yet | ||
down, d Undo recently performed migrations | ||
status, s Get status about open migrations and which was run last | ||
help, h Shows a list of commands or help for one command | ||
GLOBAL OPTIONS: | ||
--env value, -e value specify which configuration to use (default: "dev") | ||
--help, -h show help (default: false) | ||
--version, -v print the version (default: false) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: "3.5" | ||
|
||
services: | ||
postgres: | ||
image: postgres:12 | ||
container_name: postgres | ||
ports: | ||
- "6631:5432" | ||
#volumes: | ||
# - /var/lib/postgresql/data | ||
environment: | ||
- POSTGRES_PASSWORD=123 | ||
- POSTGRES_USER=root | ||
- POSTGRES_DB=scriptup | ||
mysql: | ||
image: mysql:8-oracle #arm64v8/mysql:oracle | ||
command: --default-authentication-plugin=mysql_native_password | ||
environment: | ||
- MYSQL_DATABASE=scriptup | ||
- MYSQL_ROOT_PASSWORD=123 | ||
ports: | ||
- '6632:3306' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module github.com/mg98/scriptup | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/go-sql-driver/mysql v1.6.0 | ||
github.com/lib/pq v1.10.6 | ||
github.com/urfave/cli/v2 v2.8.1 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= | ||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | ||
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs= | ||
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4= | ||
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/mg98/scriptup/pkg/scriptup" | ||
"github.com/urfave/cli/v2" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
app := NewApp() | ||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// NewApp creates a new command line app | ||
func NewApp() *cli.App { | ||
app := cli.NewApp() | ||
app.Name = "scriptup" | ||
app.Usage = "A lightweight and agnostic script migration tool." | ||
app.Version = "0.1.0" | ||
|
||
app.Flags = []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "env", | ||
Aliases: []string{"e"}, | ||
Value: "dev", | ||
Usage: "specify which configuration to use", | ||
}, | ||
} | ||
|
||
app.Commands = []*cli.Command{ | ||
{ | ||
Name: "new", | ||
Aliases: []string{"n"}, | ||
Usage: "Generate a new migration file", | ||
Action: func(c *cli.Context) error { | ||
cfg := scriptup.GetConfig(c.String("env")) | ||
return scriptup.NewMigrationFile(cfg, c.Args().Get(0)) | ||
}, | ||
}, | ||
{ | ||
Name: "up", | ||
Aliases: []string{"u"}, | ||
Flags: []cli.Flag{ | ||
&cli.IntFlag{ | ||
Name: "steps", | ||
Value: -1, | ||
Usage: "Limit the number of migrations to run", | ||
}, | ||
}, | ||
Usage: "Execute recent scripts that have not been migrated yet", | ||
Action: func(c *cli.Context) error { | ||
cfg := scriptup.GetConfig(c.String("env")) | ||
return scriptup.MigrateUp(cfg, c.Int("steps")) | ||
}, | ||
}, | ||
{ | ||
Name: "down", | ||
Aliases: []string{"d"}, | ||
Flags: []cli.Flag{ | ||
&cli.IntFlag{ | ||
Name: "steps", | ||
Value: -1, | ||
Usage: "Limit the number of migrations to run", | ||
}, | ||
}, | ||
Usage: "Undo recently performed migrations", | ||
Action: func(c *cli.Context) error { | ||
cfg := scriptup.GetConfig(c.String("env")) | ||
return scriptup.MigrateDown(cfg, c.Int("steps")) | ||
}, | ||
}, | ||
{ | ||
Name: "status", | ||
Aliases: []string{"s"}, | ||
Usage: "Get status about open migrations and which was run last", | ||
Action: func(c *cli.Context) error { | ||
cfg := scriptup.GetConfig(c.String("env")) | ||
return scriptup.Status(cfg) | ||
}, | ||
}, | ||
} | ||
|
||
return app | ||
} |
Oops, something went wrong.