Skip to content

Commit 61de495

Browse files
authored
Merge pull request #2 from ioncakephper:feature/add-release-ci
Update project for semantic release and name change
2 parents 8e945ea + cc62af8 commit 61de495

File tree

7 files changed

+9320
-3431
lines changed

7 files changed

+9320
-3431
lines changed

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Semantic Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
issues: write
14+
pull-requests: write
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
# Fetch all history for semantic-release to analyze
20+
fetch-depth: 0
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '18'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Run semantic-release
31+
run: npx semantic-release
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
34+
# If publishing to npm, you would also need:
35+
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.releaserc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
branches: ['main'],
3+
plugins: [
4+
'@semantic-release/commit-analyzer',
5+
'@semantic-release/release-notes-generator',
6+
[
7+
'@semantic-release/changelog',
8+
{
9+
changelogFile: 'CHANGELOG.md',
10+
},
11+
],
12+
['@semantic-release/npm', { npmPublish: false }], // Set to true to publish to npm
13+
'@semantic-release/github',
14+
[
15+
'@semantic-release/git',
16+
{
17+
assets: ['package.json', 'package-lock.json', 'CHANGELOG.md'],
18+
message:
19+
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
20+
},
21+
],
22+
],
23+
};

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Contributing to js-quality-starter
1+
# Contributing to js-quality-starter-with-release
22

3-
We welcome contributions to the `js-quality-starter` template! By contributing, you help improve this foundation for JavaScript projects for everyone.
3+
We welcome contributions to the `js-quality-starter-with-release` template! By contributing, you help improve this foundation for JavaScript projects for everyone.
44

55
Please take a moment to review this document to understand our contribution guidelines.
66

@@ -20,7 +20,7 @@ Please take a moment to review this document to understand our contribution guid
2020

2121
## Code of Conduct
2222

23-
This project and everyone participating in it is governed by the [js-quality-starter Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [YOUR_PROJECT_CONTACT_EMAIL].
23+
This project and everyone participating in it is governed by the js-quality-starter-with-release Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [YOUR_PROJECT_CONTACT_EMAIL].
2424

2525
## How to Contribute
2626

@@ -50,8 +50,8 @@ If you're new to contributing to open source or this project, here's a general w
5050
2. **Clone** your forked repository to your local machine:
5151

5252
```bash
53-
git clone https://github.com/your-username/your-forked-repo.git # Replace with your forked repository URL
54-
cd js-quality-starter
53+
git clone https://github.com/your-username/js-quality-starter-with-release.git # Replace with your username
54+
cd js-quality-starter-with-release
5555
```
5656

5757
3. **Install dependencies**:
@@ -76,7 +76,7 @@ If you're new to contributing to open source or this project, here's a general w
7676
git push origin feature/your-feature-name
7777
```
7878

79-
9. Open a **Pull Request** to the `main` branch of the original `js-quality-starter` repository.
79+
9. Open a **Pull Request** to the `main` branch of the original `js-quality-starter-with-release` repository.
8080

8181
### Pull Request Guidelines
8282

@@ -125,4 +125,4 @@ We encourage the use of Conventional Commits for clear and consistent commit his
125125

126126
## License
127127

128-
By contributing to `js-quality-starter`, you agree that your contributions will be licensed under its MIT License.
128+
By contributing to `js-quality-starter-with-release`, you agree that your contributions will be licensed under its MIT License.

README.md

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
# js-quality-starter-with-release
22

3-
[![CI](https://github.com/your-username/your-new-repo/actions/workflows/ci.yml/badge.svg)](https://github.com/your-username/your-new-repo/actions/workflows/ci.yml)
3+
[![Release](https://github.com/your-username/your-new-repo/actions/workflows/release.yml/badge.svg)](https://github.com/your-username/your-new-repo/actions/workflows/release.yml)
4+
[![semantic-release](https://img.shields.io/badge/semantic--release-e10079?logo=semantic-release&logoColor=white)](https://github.com/semantic-release/semantic-release)
45
[![codecov](https://codecov.io/gh/your-username/your-new-repo/graph/badge.svg?token=YOUR_CODECOV_TOKEN)](https://codecov.io/gh/your-username/your-new-repo)
56
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
67
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
78

8-
A template repository for modern JavaScript projects with pre-configured linting, formatting, testing, and CI/CD using GitHub Actions.
9+
A template repository for modern JavaScript projects with pre-configured linting, formatting, testing, and a fully automated release pipeline using `semantic-release`.
910

1011
This template provides a solid foundation for any new JavaScript project, ensuring code quality and consistency from the start.
1112

1213
## Table of Contents <!-- omit in toc -->
1314

1415
- [Quick Start](#quick-start)
15-
- [Why Choose `js-quality-started`?](#why-choose-js-quality-started)
16+
- [Why Choose `js-quality-started-with-release`?](#why-choose-js-quality-started-with-release)
1617
- [What's Inside?](#whats-inside)
1718
- [Getting Started](#getting-started)
1819
- [Using as a Template](#using-as-a-template)
1920
- [Manual Setup](#manual-setup)
2021
- [Post-Template Setup](#post-template-setup)
2122
- [Available Scripts](#available-scripts)
2223
- [How It Works](#how-it-works)
23-
- [Pre-commit Hooks](#pre-commit-hooks)
24-
- [CI/CD Pipelines](#cicd-pipelines)
24+
- [Pre-commit and Commit Message Hooks](#pre-commit-and-commit-message-hooks)
25+
- [Automated Release Generation](#automated-release-generation)
2526
- [Customization](#customization)
2627
- [Code Coverage](#code-coverage)
2728
- [Contributing](#contributing)
@@ -30,18 +31,18 @@ This template provides a solid foundation for any new JavaScript project, ensuri
3031
## Quick Start
3132

3233
```bash
33-
npx degit your-github-username/js-quality-started my-new-project
34+
npx degit your-github-username/js-quality-starter-with-release my-new-project --force
3435
cd my-new-project
3536
npm install
3637
npm test
3738
# Start building!
3839
```
3940

40-
## Why Choose `js-quality-started`?
41+
## Why Choose `js-quality-started-with-release`?
4142

42-
Tired of repetitive setup, inconsistent code, and integration headaches? See how `js-quality-started` provides a superior foundation compared to starting from scratch or using basic boilerplates.
43+
Tired of repetitive setup, inconsistent code, and integration headaches? See how `js-quality-started-with-release` provides a superior foundation compared to starting from scratch or using basic boilerplates.
4344

44-
| Criteria | Minimal/Empty Repository | Basic Boilerplate | `js-quality-started` Template |
45+
| Criteria | Minimal/Empty Repository | Basic Boilerplate | `js-quality-started-with-release` Template |
4546
| :--------------------------------- | :----------------------- | :------------------------------- | :----------------------------------------------------------- |
4647
| **Core Purpose** | Blank slate | Quick start, basic structure | Quality, consistency, efficiency |
4748
| **Linting (e.g., ESLint)** | ❌ No | ⚙️ Manual setup required / Basic | ✅ Pre-configured, opinionated |
@@ -107,6 +108,8 @@ After creating your repository from this template, be sure to:
107108
1. **Update `package.json`**: Change the `name`, `description`, and `author` fields.
108109
2. **Update `LICENSE`**: Modify the `[year]` and `[fullname]` to reflect your project's ownership.
109110
3. **Update `CODE_OF_CONDUCT.md` and `CONTRIBUTING.md`**: Replace the `[YOUR_PROJECT_CONTACT_EMAIL]` placeholder with a valid project contact email.
111+
4. **Update `README.md` badges**: Replace `your-username/your-new-repo` in the badge URLs with your actual GitHub username and repository name.
112+
5. **Configure Publishing (Optional)**: In `.releaserc.js`, change `npmPublish: false` to `npmPublish: true` if you want to publish to the npm registry. You will also need to add an `NPM_TOKEN` secret to your repository.
110113

111114
## Available Scripts
112115

@@ -124,27 +127,35 @@ In the project directory, you can run:
124127

125128
## How It Works
126129

127-
### Pre-commit Hooks
130+
This template is built around a fully automated, commit-driven workflow.
128131

129-
This project uses `Husky` and `lint-staged` to run `eslint --fix`, `prettier --write` (for both code and Markdown), and `markdownlint --fix` on staged files every time you make a commit. This automated quality gate ensures that no code or documentation that violates the style guide ever gets into the codebase.
132+
### Pre-commit and Commit Message Hooks
130133

131-
If a file has linting or formatting errors, the tools will attempt to fix them automatically. If they can, the fixed code is what gets committed. If they can't, the commit is aborted so you can fix the issues manually.
134+
This project uses `Husky`, `lint-staged`, and `commitlint` to enforce code quality and consistent commit messages.
132135

133-
### CI/CD Pipelines
136+
1. **On Staging:** When you stage files (`git add`), `lint-staged` runs formatters (`Prettier`) and linters (`ESLint`, `markdownlint`) on them. This ensures your code and documentation are clean _before_ you even write a commit message.
137+
2. **On Commit:** When you write a commit message (`git commit`), `commitlint` validates it against the **Conventional Commits** specification. This is the most critical step, as these structured commit messages power the automated release process. If your message is not compliant (e.g., `git commit -m "updated stuff"`), the commit will be aborted.
134138

135-
This template includes one GitHub Action workflow located in the `.github/workflows` directory:
139+
### Automated Release Generation
136140

137-
- **`ci.yml`**: This workflow runs on every push and pull request to the `main` branch. It acts as a final validation gate, ensuring that all tests, linting, and formatting checks pass before code is merged.
141+
This template uses **`semantic-release`** to automate the entire release process. The manual step of deciding on a version number and creating a release is completely removed.
138142

139-
The workflow performs the following steps across multiple Node.js versions (18.x, 20.x):
143+
The process is triggered every time a commit is merged into the `main` branch. Here’s what happens:
140144

141-
1. **Install dependencies** using `npm ci` for fast, reliable installs.
142-
2. **Lint code** with `npm run lint`.
143-
3. **Lint Markdown files** with `npm run lint:md`.
144-
4. **Check code formatting** with `npm run format`.
145-
5. **Check Markdown formatting** with `npm run format:md`.
146-
6. **Audit for vulnerabilities** with `npm audit --production`.
147-
7. **Run tests** with `npm test`.
145+
1. **Trigger:** A push or merge to the `main` branch starts the `release.yml` GitHub Actions workflow.
146+
2. **Analysis:** `semantic-release` analyzes the commit messages since the last release.
147+
3. **Versioning:** It automatically determines the next version number based on the types of commits:
148+
- `fix:` commits result in a **PATCH** release (e.g., `1.0.0` -> `1.0.1`).
149+
- `feat:` commits result in a **MINOR** release (e.g., `1.0.1` -> `1.1.0`).
150+
- Commits with `BREAKING CHANGE:` in the body result in a **MAJOR** release (e.g., `1.1.0` -> `2.0.0`).
151+
4. **Release Generation:** If a release is warranted, `semantic-release` performs the following actions:
152+
- Updates `CHANGELOG.md` with the new release notes.
153+
- Updates the `version` in `package.json`.
154+
- Creates a new Git tag for the new version.
155+
- Creates a new GitHub Release with the generated notes.
156+
- Commits the updated `package.json` and `CHANGELOG.md` files back to the `main` branch.
157+
158+
This means you no longer need to manually tag versions. Your release cycle is tied directly to the features and fixes you merge into your main branch.
148159

149160
## Customization
150161

@@ -154,7 +165,7 @@ This template is a starting point. You can easily customize it to fit your proje
154165
- **Formatting Options**: Adjust the `.prettierrc` file to change Prettier's formatting options.
155166
- **Markdown Linting**: Customize `markdownlint` rules by editing the `.markdownlint.json` file.
156167
- **Testing**: The `jest.config.js` file can be configured for more advanced testing scenarios.
157-
- **CI/CD**: Edit the workflow files in `.github/workflows` to add new steps, such as deployment or notifications.
168+
- **Release Configuration**: Edit the `.releaserc.js` file to customize the `semantic-release` plugins and behavior.
158169

159170
## Code Coverage
160171

cliff.toml

Whitespace-only changes.

0 commit comments

Comments
 (0)