Semantic versioning & How to use

JTechBlog·2024년 3월 30일

CI&CD

목록 보기
2/2
post-thumbnail

semantic-release automates the whole package release workflow including: determining the next version number, generating the release notes, and publishing the package.

범용적으로 사용되고 있는 버전 관리를 위한 NPM 패키지이다.



1. Semantic versioning ?

간단히 버전 관리를 위한 번호 붙이기 라고 생각하면 된다.

아래와 같이 각 번호는 major, minor, patch 를 의미한다.

구체적으로,

  • major - 이전 버전과 호환되지 않는 변경이 발생한 경우 증가한다.
  • minor - 이전 버전과 호환되는 새로운 기능 API 가 추가 또는 변경되는 경우 증가한다.
  • patch - 기존 기능에 대한 간단한 버그 수정인 경우 증가한다.

이 버저닝에 사용하는 tilde(~) and caret(^) 의 뜻도 알아보자.

  • ~version minor 버전을 올리지 않고 향후 모든 patch 버전으로 업데이트 한다는 뜻이다. 예를 들어, ~1.2.3은 1.2.3에서 <1.3.0까지의 릴리스를 사용한다.
  • ^version 은 major 버전을 증가시키지 않고 향후 모든 minor/patch 버전으로 업데이트 한다. 예를 들어, ^2.3.4는 2.3.4에서 <3.0.0 까지의 릴리스를 사용한다.



2. Semantic versioning 을 프로젝트에 적용하기


  1. package.json 에 semantic release 관련 패키지 설치 명세 및 자동 버전 이력 문서 작성 플러그인 세팅
  2. git action work flow 에 semantic release 를 job 으로 설정

package.json 에 semantic release 세팅하는 법 예시

{
  "name": "semantic-release-example",
  "version": "1.742.4",
  "private": true,
  "dependencies": {
    ...
  },
  "scripts": {
    ...
  },
  "release": {
    "plugins": [
      "@semantic-release/release-notes-generator",
      [
        "@semantic-release/changelog",
        {
          "changelogFile": "src/pages/Version/CHANGELOG.mdx"
        }
      ],
      "@semantic-release/npm",
      [
        "@semantic-release/git",
        {
          "assets": [
            "src/pages/Version/CHANGELOG.mdx",
            "package.json"
          ]
        }
      ]
    ],
    "branches": [
      "staging"
    ]
  },
  ...,
  "devDependencies": {
    "@semantic-release/changelog": "6.0.1",
    "@semantic-release/git": "10.0.1",
    "@semantic-release/npm": "9.0.1",
    "@semantic-release/release-notes-generator": "10.0.3",
    "semantic-release": "19.0.3",
  }
}

위와 같이 플러그인 세팅을 후, 아래 예와 같이 특정 git workflow 에서 이를 실행하도록 설정하면
jobs:
  docker:
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v3
        with:
          extra_plugins: |
            @semantic-release/changelog
            @semantic-release/git

semantic release 가 커밋을 할 수 있는 권한을 이용하여 아래와 같이CHANGELOG.mdx 문서를 만들어준다. 이는 버전 관리에 도움을 준다.

src/pages/Version/CHANGELOG.mdx


## [1.742.0]](https://github.com/repo-name-here/compare/v1.742.3...v1.742.4) (2024-01-04)

### Features

* **[PAGE-A][TAB-B]:** feature commit content here! [#5064](https://github.com/repo-name-here/issues/5064) ([#5071](https://github.com/repo-name-here/issues/5071)) ([f91c2d8](https://github.com/repo-name-here/commit/f91c2d810a5a288e28f0ba5563da03060348c825))

## [1.741.1](https://github.com/repo-name-here/compare/v1.741.0...v1.741.1) (2024-01-03)


### Bug Fixes

* **inquiry-cache:** inquiry re serach ([#5073](https://github.com/repo-name-here/issues/5073)) ([7da7f0b](https://github.com/brepo-name-here/commit/7da7f0bf1522188a191d302d672e1c3573114806))
* **package-status:** add untracked type ([#5072](https://github.com/repo-name-here/issues/5072)) ([34468b4](https://github.com/repo-name-here/commit/34468b48e77ed32c43adc5cca0715a7065a995df))

# [1.741.0](https://github.com/repo-name-here/compare/v1.740.4...v1.741.0) (2024-01-03)




Ref

profile
웹/앱 개발 정보를 공유합니다.

0개의 댓글