Skip to content

Commit

Permalink
Merge pull request #296 from open-genes/develop
Browse files Browse the repository at this point in the history
release 1.1.1
  • Loading branch information
const8ine authored Aug 6, 2023
2 parents 6379f7f + f09a903 commit 12b9e88
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 47,307 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build
run: |
npm install
node setversion.js
node .utils/write-build-number.js
npm run build-demo
- name: Delete temporary files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build
run: |
npm install
node setversion.js
node .utils/write-build-number.js
npm run build-prod
- name: Delete temporary files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Build
run: |
npm install
node setversion.js
node .utils/write-build-number.js
npm run build-dev
- name: Delete temporary files
run: |
Expand Down
28 changes: 28 additions & 0 deletions .utils/generate-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env es6 */
const fs = require('fs');
const { exec } = require('child_process');
const changelogFile = 'CHANGELOG.md';

if (process.argv.length < 3) {
console.error('Usage: node generateChangelog.js <tag>');
process.exit(1);
}

const tag = process.argv[2];

exec(`git log ${tag}..HEAD --pretty=format:"- %s" --no-merges`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
process.exit(1);
}
if (stderr) {
console.error(`Error: ${stderr}`);
process.exit(1);
}
const strippedText = stdout.replace(/#/g, ''); // Remove '#' symbols
const changelogContent = `\n#Release v${tag}\n\n${strippedText}\n`;

fs.appendFileSync(changelogFile, changelogContent);

console.log(`Changelog has been updated and saved to ${changelogFile}`);
});
44 changes: 44 additions & 0 deletions .utils/update-version-and-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-env es6 */
const fs = require('fs');
const { exec } = require('child_process');

if (process.argv.length < 3) {
console.error('Usage: node .utils/update-version-and-changelog.js <version>');
process.exit(1);
}

const newVersion = process.argv[2];

// Read package.json and update the version field
fs.readFile('package.json', 'utf8', (err, data) => {
if (err) {
console.error(`Error reading package.json: ${err}`);
process.exit(1);
}

const packageJson = JSON.parse(data);
packageJson.version = newVersion;

// Write the updated package.json back to the file
fs.writeFile('package.json', JSON.stringify(packageJson, null, 2), 'utf8', (err) => {
if (err) {
console.error(`Error writing to package.json: ${err}`);
process.exit(1);
}

// Run the generate-changelog.js script with the new version
exec(`node .utils/generate-changelog.js ${newVersion}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error running generate-changelog.js: ${error.message}`);
process.exit(1);
}
if (stderr) {
console.error(`Error: ${stderr}`);
process.exit(1);
}

console.log(stdout);
console.log('Version updated in package.json and changelog generated successfully.');
});
});
});
59 changes: 59 additions & 0 deletions .utils/versioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-env es6 */
const readline = require('readline');
const fs = require('fs');

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question('What type of commit did you stage? (bug fix (B) / feature (F)): ', (answer) => {
const lowerCaseAnswer = answer.toLowerCase();
if (lowerCaseAnswer === 'b') {
updateVersion('patch');
} else if (lowerCaseAnswer === 'f') {
updateVersion('minor');
} else {
console.log('Invalid input. Please provide either "B" or "F".');
}

rl.close();
});

function updateVersion(bumpType) {
const packageJsonPath = 'package.json';

fs.readFile(packageJsonPath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading ${packageJsonPath}: ${err}`);
process.exit(1);
}

const packageJson = JSON.parse(data);
const currentVersion = packageJson.version.split('.').map(Number);
let newVersion;

// Raise version depending on the type of changes
if (bumpType === 'patch') {
newVersion = [currentVersion[0], currentVersion[1], currentVersion[2] + 1];
} else if (bumpType === 'minor') {
newVersion = [currentVersion[0], currentVersion[1] + 1, 0];
}

if (newVersion[1] === 10) {
newVersion[0]++;
newVersion[1] = 0;
}

packageJson.version = newVersion.join('.');

fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8', (err) => {
if (err) {
console.error(`Error writing to ${packageJsonPath}: ${err}`);
process.exit(1);
}

console.log(`Version updated to ${packageJson.version} for ${bumpType} commit.`);
});
});
}
2 changes: 1 addition & 1 deletion setversion.js → .utils/write-build-number.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env es6 */
const fs = require('fs');
const version = require('./package.json').version;
const version = require('../package.json').version;
const buildNumber = fs.readFileSync('.env', 'utf8');

const build = buildNumber.replace(/(\r\n|\n|\r)/gm, '').replace(/,/gm);
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Release v1.1.0

- Added a release cycle
- OG-923. Transfer scripts to .utils folder, fix versioning script
- OG-923. Add a tool for incrementing a version. Update CONTRIBUTING.md
- OG-923. Update CONTRIBUTING.md
- OG-923. Rename a script for writing a build number to the env files
- OG-923. Add CONTRIBUTING.md
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Release cycle

## Before Making a PR
Remember to set an app version and add changes to a changelog after working on a feature branch or fixing a bug. This process is automated. All you need to do is set a tag for the first commit preceding the other commits that should be in the release.
Then run:

```
npm run versioning
```

You can also use the following tasks to do the same thing manually:

```
npm run version-and-changelog 2.0.1
```

to write any version to package.json and update the changelog

or

```
npm run update-changelog 2.0.1
```

to only update the changelog.

---

<small>
Replace examples with your own version. Please specify the version number without any prefix, such as "v".
</small>

## Version Numbers

Version numbers follow a pattern known as Semantic Versioning ([SemVer](https://semver.org/)), which consists of three components: `major.minor.patch`.

- **Major Version**: This number increases when there are significant changes that might introduce backward-incompatible features or major restructuring. New major versions may require you to update your code to accommodate these changes.

- **Minor Version**: Minor version bumps occur for backward-compatible feature additions or improvements. New features are introduced in a backward-compatible manner, so you can adopt them without breaking your existing code.

- **Patch Version**: Patch versions are for backward-compatible bug fixes or minor enhancements. These updates typically address issues without altering existing features or introducing new ones.

**Examples:**

- Version `1.0.0`: Initial release.
- Version `1.1.0`: Added a new feature without breaking existing functionality.
- Version `1.1.1`: Fixed a bug while maintaining compatibility.

When you're considering which version to use or upgrade to, consult the release notes and changelog provided in the repository to understand the changes introduced in each version. This information will help you make informed decisions about updating your dependencies and codebase.
Loading

0 comments on commit 12b9e88

Please sign in to comment.