Skip to content

Commit

Permalink
ci: setup CI/CD, add automated releases
Browse files Browse the repository at this point in the history
  • Loading branch information
lesha1201 committed Nov 24, 2023
1 parent 123ed32 commit 4bd6a54
Show file tree
Hide file tree
Showing 8 changed files with 1,332 additions and 20 deletions.
20 changes: 20 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Setup Environment
description: Sets up environment by installing all necessary dependencies.

runs:
using: composite
steps:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Install dependencies
shell: bash
run: pnpm i
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release

on:
push:
branches: [main, canary]

jobs:
release:
name: Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Environment
uses: ./.github/actions/setup-environment

- name: Release
run: pnpm semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Validate

on:
push:
branches: [main, canary]
pull_request:
branches: [main, canary]

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Set Git fetch depth
run: echo "CHECKOUT_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV

- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
# We fetch all PR commits to lint them.
fetch-depth: ${{ env.CHECKOUT_FETCH_DEPTH }}

- name: Setup Environment
uses: ./.github/actions/setup-environment

- name: Lint PR commits
if: github.event_name == 'pull_request'
run: pnpm commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }}

- name: Validate code format
run: pnpm prettier:check

- name: Lint code
run: pnpm lint
10 changes: 10 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
branches: ['main', { name: 'canary', channel: 'canary', prerelease: true }],
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/npm',
'@semantic-release/github',
['@semantic-release/git', { message: 'release: ${nextRelease.version}' }],
],
};
42 changes: 41 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ npm link @datarockets/style-guide
Follow [README](./README.md) to find out how to use the configs.

#### Creating a commit
### Commits

Commit messages should be in the format:

Expand All @@ -58,3 +58,43 @@ type(scope?): message

The scope should be included most of the time, and all allowed types and scopes
are documented in [.commitlintrc.js](./.commitlintrc.js).

Commits are used to automatically generate releases (see [Releases](#releases)).

## Releases

The default branch for this repository is `canary`. Each relevant commit into
`canary` triggers an automated pre-release. Merging `canary` into `main` will
trigger a release.

We use [semantic-release](https://semantic-release.gitbook.io/semantic-release/)
to automate releases. It will automatically generate Git tag, create release
notes based on the commits, publish to npm, etc.

### How commits affect versions

By default, commits with the `feat` type will cause a minor version bump, and
commits with the `fix` or `perf` type will cause a patch version bump.

If your commit is a breaking change, which will create new major release, you
should add a footer with `BREAKING CHANGE: [message]`

```
feat(eslint): migrate to ESLint 8
Resolves #1
BREAKING CHANGE: see the ESLint 8 release notes for all breaking changes
```

In this example, the release notes would look like this:

> # 1.0.0 (2023-01-01)
>
> ### Features
>
> - eslint: migrate to ESLint 8 ([commit-hash])
>
> ### BREAKING CHANGES
>
> - eslint: see the ESLint 8 release notes for all breaking changes
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The following configs are available, and are designed to be used together.

- [Prettier](#prettier)
- [ESLint](#eslint)
- [TypeScript](#typescript)

## Contributing

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datarockets/style-guide",
"version": "0.0.1",
"version": "1.0.0-canary.1",
"description": "Datarockets' style guide",
"homepage": "https://github.com/datarockets/style-guide#readme",
"bugs": {
Expand Down Expand Up @@ -52,10 +52,12 @@
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@semantic-release/git": "^10.0.1",
"@types/eslint": "^8.44.7",
"eslint": "^8.54.0",
"husky": "^8.0.3",
"prettier": "^3.1.0",
"semantic-release": "^22.0.8",
"typescript": "^5.3.2"
},
"peerDependencies": {
Expand All @@ -77,5 +79,8 @@
"typescript": {
"optional": true
}
},
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit 4bd6a54

Please sign in to comment.