Skip to content

Instantly share code, notes, and snippets.

@pysysops
Last active October 17, 2019 12:37
Show Gist options
  • Save pysysops/61bcd3692d8c2a9996eb9695c2b069ce to your computer and use it in GitHub Desktop.
Save pysysops/61bcd3692d8c2a9996eb9695c2b069ce to your computer and use it in GitHub Desktop.
Tag / Version control any git repo with yarn
{
"name": "MyCoolApp",
"description": "Does a really cool thing",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "true",
"gitbranch": "BRANCH=$(git rev-parse --abbrev-ref HEAD); if [[ \"$BRANCH\" != \"master\" ]]; then echo \"you must be on master branch to release\"; exit 1 ; fi",
"gitstatus": "STATUS=$(git status --porcelain 2>&1); echo $STATUS; if [[ ! -z \"$STATUS\" ]]; then exit 1; fi;",
"gittest": "yarn gitbranch && yarn gitstatus",
"preversion": "yarn gittest && yarn test",
"postversion": "git push --follow-tags"
}
}
@pysysops
Copy link
Author

pysysops commented Oct 10, 2019

Add this package.json to any repo, update the test line and then version your thing by running yarn version ...:

~/GoProjects/src/github.com/devopsmakers/xterrafile master *1                      4s ⎈ docker-desktop
❯ yarn version --patch
yarn version v1.19.1
info Current version: 2.1.1
$ yarn gittest && yarn test
yarn run v1.19.1
$ yarn gitbranch && yarn gitstatus
$ BRANCH=$(git rev-parse --abbrev-ref HEAD); if [[ "$BRANCH" != "master" ]]; then echo "you must be on master branch to release"; exit 1 ; fi
$ STATUS=$(git status --porcelain 2>&1); echo $STATUS; if [[ ! -z "$STATUS" ]]; then exit 1; fi;

✨  Done in 0.69s.
yarn run v1.19.1
$ go build -v ; go test -v ./...
=== RUN   TestTerraformWithTerrafilePath
--- PASS: TestTerraformWithTerrafilePath (2.08s)
PASS
ok  	github.com/devopsmakers/xterrafile	2.100s
?   	github.com/devopsmakers/xterrafile/cmd	[no test files]
=== RUN   TestIsLocalSourceAddr
--- PASS: TestIsLocalSourceAddr (0.00s)
=== RUN   TestCopyFile
--- PASS: TestCopyFile (0.00s)
=== RUN   TestIsValidVersion
--- PASS: TestIsValidVersion (0.00s)
=== RUN   TestIsConditionalVersion
--- PASS: TestIsConditionalVersion (0.00s)
=== RUN   TestGetModuleVersion
--- PASS: TestGetModuleVersion (0.00s)
=== RUN   TestIsRegistrySourceAddr
--- PASS: TestIsRegistrySourceAddr (0.00s)
=== RUN   TestGetRegistrySource
--- PASS: TestGetRegistrySource (0.00s)
=== RUN   TestGetModSrc
--- PASS: TestGetModSrc (0.00s)
=== RUN   TestGetRegistryModuleVersions
--- PASS: TestGetRegistryModuleVersions (0.00s)
=== RUN   TestCheckIfError
--- PASS: TestCheckIfError (0.00s)
=== RUN   TestIContains
--- PASS: TestIContains (0.00s)
PASS
ok  	github.com/devopsmakers/xterrafile/pkg	0.023s
✨  Done in 4.30s.
info New version: 2.1.2
$ git push --follow-tags
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 812 bytes | 812.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:devopsmakers/xterrafile.git
   ddd3fc0..b66ff89  HEAD -> master
 * [new tag]         v2.1.2 -> v2.1.2
✨  Done in 9.46s.

See: https://yarnpkg.com/lang/en/docs/cli/version/ for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment