This repository was archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Release itself #14
Open
FagnerMartinsBrack
wants to merge
18
commits into
master
Choose a base branch
from
release-itself
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Release itself #14
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
44ef066
Release itself
FagnerMartinsBrack 23aa129
Create a default commit hash for fake runs
FagnerMartinsBrack 7c1e220
Create push tag function
FagnerMartinsBrack ba92bb4
Run eslint on release.js file
FagnerMartinsBrack c0d6a0f
Create const ffor git push tag spec to avoid typos and false positive…
FagnerMartinsBrack e3687e6
Rename 'operations' to 'functions' in the API Docs (README)
FagnerMartinsBrack cec9786
Let's manually publish on npm for now
FagnerMartinsBrack e49944c
Add project description in the README
FagnerMartinsBrack 0d73d12
Release new version
FagnerMartinsBrack 82631cd
Prepare release commands to do the real thing
FagnerMartinsBrack 3b3c3ab
Release new version
FagnerMartinsBrack 30d8f59
Add TODOs
FagnerMartinsBrack be3fbab
Release new version
FagnerMartinsBrack ca54934
Rewrite package json bumper
FagnerMartinsBrack 76db9d2
keep package.json identation after bump
FagnerMartinsBrack 057f9b5
Release new version
FagnerMartinsBrack 6adeab2
Review README docs
FagnerMartinsBrack 53048c2
Release new version
FagnerMartinsBrack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,18 @@ | ||
# JS Cookie Release API | ||
|
||
Release routines for JavaScript Cookie library | ||
|
||
## Functions | ||
|
||
#### `Promise bumpPackageJSON(String bumpSpec, String filePath)` | ||
|
||
Bumps the "version" property from a list of file paths that matches the [JSON](http://json.org/) spec. | ||
|
||
#### `Promise gitCommit(String message, NodeGitRepository gitRepository)` | ||
|
||
Add all the changes to the staging area and create a commit to the given repository. | ||
|
||
## Release Steps | ||
|
||
* Run `npm run release <bumpSpec>`, where `bumpSpec` is either `patch`, `minor` or `major` | ||
* Run `npm publish ./` |
This file contains hidden or 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
This file contains hidden or 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,64 @@ | ||
const Promise = require("bluebird"); | ||
const Git = require("nodegit"); | ||
|
||
const bumpPackageJSON = require("./src/file/bump-package-json"); | ||
const gitCommit = require("./src/git/git-commit"); | ||
const gitTag = require("./src/git/git-tag"); | ||
const gitPushTag = require("./src/git/git-push-tag"); | ||
|
||
let targetBumpSpec; | ||
if (process.argv.includes("patch")) { | ||
targetBumpSpec = "patch"; | ||
} | ||
if (process.argv.includes("minor")) { | ||
targetBumpSpec = "minor"; | ||
} | ||
if (process.argv.includes("major")) { | ||
targetBumpSpec = "major"; | ||
} | ||
if (!targetBumpSpec) { | ||
console.log("Invalid bump spec, use \"patch\", \"minor\" or \"major\""); | ||
return; | ||
} | ||
|
||
const isFakeRun = process.argv.includes("fake"); | ||
|
||
let localRepo; | ||
|
||
Promise.try(() => { | ||
console.log("Bumping package.json..."); | ||
if (!isFakeRun) { | ||
return bumpPackageJSON(targetBumpSpec, "package.json"); | ||
} | ||
}).then(() => { | ||
return Git.Repository.discover(".", 0, "."); | ||
}).then((foundRepositoryPath) => { | ||
console.log("Found repository on:", foundRepositoryPath); | ||
return Git.Repository.open(foundRepositoryPath); | ||
}).then((_localRepo) => { | ||
localRepo = _localRepo; | ||
}).then(() => { | ||
console.log("Creating release commit..."); | ||
if (!isFakeRun) { | ||
return gitCommit("Release new version", localRepo); | ||
} | ||
return "fake44ef0665e9e8e5fdf7c6bfcd61f95fe8b699"; | ||
}).then((commitObjectId) => { | ||
const tagName = commitObjectId && commitObjectId.substring(0, 8); | ||
const tagReferenceCommit = commitObjectId; | ||
console.log("Creating tag:", tagName); | ||
if (!isFakeRun) { | ||
return gitTag(tagName, tagReferenceCommit, localRepo); | ||
} | ||
return /* FakeTag */ { name: () => "fake_tag_name" }; | ||
}).then((tag) => { | ||
console.log("Created tag '" + tag.name() + "'"); | ||
return localRepo.getRemotes().then((localRemotes) => { | ||
if (!isFakeRun) { | ||
return gitPushTag(tag.name(), localRemotes[0], localRepo); | ||
} | ||
}); | ||
}); | ||
|
||
// TODO Don't leak NodeGitRepository to gitCommit | ||
// TODO Allow the input of password? |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 @@ | ||
const root = require("app-root-path"); | ||
const writeFile = require("util").promisify(require("fs").writeFile); | ||
const readFile = require("util").promisify(require("fs").readFile); | ||
|
||
const bumpVersion = require(root + "/src/bump-version"); | ||
|
||
module.exports = async (bumpSpec, filePath) => { | ||
const VERSION_KEY_VALUE_REGEX = /"version":( +)?"(.+)"/; | ||
const fileContent = await readFile(filePath, "UTF-8"); | ||
const matchedVersion = fileContent.match(VERSION_KEY_VALUE_REGEX); | ||
if (matchedVersion === null) { | ||
throw new Error( | ||
"Could not find 'version' property in package.json to bump" | ||
); | ||
} | ||
const version = matchedVersion[2]; | ||
const bumpedVersion = bumpVersion(version, bumpSpec); | ||
const replacedFileContent = fileContent.replace( | ||
VERSION_KEY_VALUE_REGEX, | ||
`"version":$1"${bumpedVersion}"` | ||
); | ||
await writeFile(filePath, replacedFileContent); | ||
}; |
File renamed without changes.
This file contains hidden or 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 @@ | ||
module.exports = function(tagName, remoteName, repository) { | ||
return repository.getRemote(remoteName).then(function(remote) { | ||
return remote.push([`refs/tags/${tagName}:refs/tags/${tagName}`]); | ||
}); | ||
}; |
This file contains hidden or 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 |
---|---|---|
@@ -1,33 +1,48 @@ | ||
const root = require("app-root-path"); | ||
const expect = require("chai").expect; | ||
const Promise = require("bluebird"); | ||
const loadJSON = Promise.promisify(require("json-update").load); | ||
|
||
const bumpJSONFiles = require(root + "/src/file/bump-json-files"); | ||
const createFileSync = require(root + "/test/dummy-data/create-file-sync"); | ||
|
||
describe("bump-json-files", function() { | ||
|
||
describe("Given a dummy file in JSON format", function() { | ||
const targetFilename = "bump-minor.json"; | ||
let removeDummyJSONFileSync; | ||
|
||
beforeEach(function() { | ||
removeDummyJSONFileSync = createFileSync(targetFilename, JSON.stringify({ | ||
version: "0.0.0" | ||
})); | ||
}); | ||
|
||
afterEach(function() { | ||
removeDummyJSONFileSync(); | ||
}); | ||
|
||
it("should bump the 'minor' version attribute", function() { | ||
return bumpJSONFiles("minor", [targetFilename]).then(function() { | ||
return loadJSON(targetFilename); | ||
}).then(function(targetFile) { | ||
expect(targetFile).to.have.property("version", "0.1.0"); | ||
}); | ||
}); | ||
const readFile = require("util").promisify(require("fs").readFile); | ||
const writeFile = require("util").promisify(require("fs").writeFile); | ||
const unlink = require("util").promisify(require("fs").unlink); | ||
|
||
const bumpPackageJSON = require(require("app-root-path") + "/src/file/bump-package-json"); | ||
|
||
describe("Bump Package JSON", () => { | ||
|
||
it("bumps the patch version in the package.json", async () => { | ||
await writeFile("target-package.json", "{\"version\":\"0.0.0\"}"); | ||
await bumpPackageJSON("patch", "target-package.json"); | ||
const targetFileContent = await readFile("target-package.json", "UTF-8"); | ||
expect(targetFileContent).to.equal("{\"version\":\"0.0.1\"}"); | ||
await unlink("target-package.json"); | ||
|
||
await writeFile("another-target-package.json", "{\"version\":\"0.0.0\"}"); | ||
await bumpPackageJSON("patch", "another-target-package.json"); | ||
const anotherTargetFileContent = await readFile("another-target-package.json", "UTF-8"); | ||
expect(anotherTargetFileContent).to.equal("{\"version\":\"0.0.1\"}"); | ||
await unlink("another-target-package.json"); | ||
}); | ||
|
||
it("keeps existing properties intact", async () => { | ||
await writeFile("target-package.json", "{\"existing\":1,\"version\":\"0.0.0\"}"); | ||
await bumpPackageJSON("patch", "target-package.json"); | ||
const bumpedFile = await readFile("target-package.json", "UTF-8"); | ||
expect(bumpedFile).to.equal("{\"existing\":1,\"version\":\"0.0.1\"}"); | ||
await unlink("target-package.json"); | ||
}); | ||
|
||
it("keeps existing spacing intact", async () => { | ||
await writeFile("target-package.json", "{ \"version\": \"0.0.0\" }"); | ||
await bumpPackageJSON("patch", "target-package.json"); | ||
const bumpedFile = await readFile("target-package.json", "UTF-8"); | ||
expect(bumpedFile).to.equal("{ \"version\": \"0.0.1\" }"); | ||
await unlink("target-package.json"); | ||
}); | ||
|
||
it("keep existing multiple spacing intact", async () => { | ||
await writeFile("target-package.json", "{ \"version\": \"0.0.0\" }"); | ||
await bumpPackageJSON("patch", "target-package.json"); | ||
const bumpedFile = await readFile("target-package.json", "UTF-8"); | ||
expect(bumpedFile).to.equal("{ \"version\": \"0.0.1\" }"); | ||
await unlink("target-package.json"); | ||
}); | ||
|
||
}); |
This file contains hidden or 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 |
---|---|---|
|
@@ -2,40 +2,62 @@ const root = require("app-root-path"); | |
const expect = require("chai").expect; | ||
|
||
const startGitRepoWithServer = require(root + "/test/dummy-data/start-git-repo-with-server"); | ||
const gitPush = require(root + "/src/git/git-push"); | ||
const gitPushMaster = require(root + "/src/git/git-push-master"); | ||
const gitPushTag = require(root + "/src/git/git-push-tag"); | ||
const gitCommit = require(root + "/src/git/git-commit"); | ||
const gitTag = require(root + "/src/git/git-tag"); | ||
const cloneToLocalDir = require(root + "/test/dummy-data/clone-repo-to-local-dir"); | ||
|
||
describe("git-push", function() { | ||
describe("Given a dummy server with git enabled cloned to local dir", function() { | ||
let defaultTestRepository; | ||
let clonedTestRepository; | ||
|
||
describe("Given a dummy server with git enabled cloned to local dir", function() { | ||
|
||
beforeEach(function() { | ||
return startGitRepoWithServer().then(function(defaultTestRepositoryResult) { | ||
defaultTestRepository = defaultTestRepositoryResult; | ||
return cloneToLocalDir(defaultTestRepository.gitHttpUrl); | ||
}).then(function(clonedTestRepositoryResult) { | ||
clonedTestRepository = clonedTestRepositoryResult; | ||
}); | ||
beforeEach(function() { | ||
return startGitRepoWithServer().then(function(defaultTestRepositoryResult) { | ||
defaultTestRepository = defaultTestRepositoryResult; | ||
return cloneToLocalDir(defaultTestRepository.gitHttpUrl); | ||
}).then(function(clonedTestRepositoryResult) { | ||
clonedTestRepository = clonedTestRepositoryResult; | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
defaultTestRepository.destroy(); | ||
clonedTestRepository.remove(); | ||
}); | ||
afterEach(function() { | ||
defaultTestRepository.destroy(); | ||
clonedTestRepository.remove(); | ||
}); | ||
|
||
describe("Git Push Master To Remote", function() { | ||
it("should commit and push the repository sucessfully to the remote", function() { | ||
let dummyCommitId; | ||
return gitCommit("Dummy commit", clonedTestRepository.repository).then(function(oid) { | ||
dummyCommitId = oid; | ||
return gitPush(defaultTestRepository.remotes[0].name, clonedTestRepository.repository); | ||
return gitPushMaster(defaultTestRepository.remotes[0].name, clonedTestRepository.repository); | ||
}).then(function() { | ||
return defaultTestRepository.remotes[0].repository.getCommit(dummyCommitId); | ||
}).then(function(commit) { | ||
expect(commit.message()).to.equal("Dummy commit"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Git Push Tag To Remote", function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
it("should commit, create a tag and push successfully to the remote", function() { | ||
const DUMMY_TAG_NAME = "dummy_tag_name"; | ||
return gitCommit("Dummy commit", clonedTestRepository.repository).then(function(dummyCommitId) { | ||
return gitTag(DUMMY_TAG_NAME, dummyCommitId, clonedTestRepository.repository); | ||
}).then(function() { | ||
return gitPushTag(DUMMY_TAG_NAME, defaultTestRepository.remotes[0].name, clonedTestRepository.repository); | ||
}).then(function deleteLocalTag() { | ||
return require("nodegit").Tag.delete(clonedTestRepository.repository, DUMMY_TAG_NAME); | ||
}).then(function fetchRemoteTag() { | ||
return clonedTestRepository.repository.getRemote(defaultTestRepository.remotes[0].name).then(function(remote) { | ||
return remote.fetch([`refs/tags/${DUMMY_TAG_NAME}`]); | ||
}); | ||
}).then(function() { | ||
return clonedTestRepository.repository.getTagByName(DUMMY_TAG_NAME).then(function(tag) { | ||
expect(tag.name()).to.equal(DUMMY_TAG_NAME); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
async
/await