Skip to content

Commit

Permalink
Add changesets
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Sep 6, 2024
1 parent 2bc4f8e commit 8951522
Show file tree
Hide file tree
Showing 7 changed files with 653 additions and 50 deletions.
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/spicy-months-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@civic/uca": patch
---

Switch release management to use changesets
30 changes: 1 addition & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: CI Pipeline

on:
push:
release:
types: [created]

jobs:
build:
Expand Down Expand Up @@ -39,30 +37,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: dist-artifact
path: dist/

deploy:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Download dist artifact
uses: actions/download-artifact@v4
with:
name: dist-artifact
path: dist/

- name: Authenticate with npm registry
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > ~/.npmrc

- name: Publish to npm
run: yarn publish --access=public
path: dist/
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# - name: Send a Slack notification if a publish happens
# if: steps.changesets.outputs.published == 'true'
# # You can do something when a publish happens.
# run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
78 changes: 69 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,76 @@ Since you used a function before and the function is not evaluated during build,

This is used on this library on src/services/config.js

## Releases
Certainly! Here's a **README section** that explains to developers how to create new changelogs and release using Changesets, assuming the actual publishing and release process happens automatically via CI.

The release process is fully automated and started by Civic members when it's created a tag on Github following the pattern ^release\\..*$. E.g.: `release.1`.
---

After the creation of the tag, Circle Ci will trigger a job to:
## 📦 Releasing and Versioning with Changesets

build source files
run unit tests
increase version number on package.json
create the stable version and tag it. E.g: v0.2.29
remove the release.N tag
deploy the binary file to NPM
We use [Changesets](https://github.com/changesets/changesets) to manage versioning, changelogs, and releases.
This allows us to generate version updates and changelogs locally, and the release process is automated through our CI pipeline.

### Creating a New Changeset

Whenever you make changes that require a version bump (e.g., a new feature, bug fix, or breaking change), you'll need to create a changeset.

Changesets will automatically handle versioning and updating the changelog.

1. **Run the Changeset Command**:

In your feature branch, run the following command to create a new changeset:

```bash
yarn changeset
```

2. **Choose the Type of Change**:

You'll be prompted to select the type of change:
- **Patch**: Bug fixes or small updates.
- **Minor**: New features that are backwards-compatible.
- **Major**: Breaking changes.

3. **Write a Summary**:

Add a short description of the changes. This will be added to the changelog for the new version.

4. **Commit the Changeset**:

A new Markdown file will be created in the `.changeset` folder. Commit this file to your branch:

```bash
git add .
git commit -m "Add changeset for [your changes]"
```

6. **Push Your Branch and Create a Pull Request**:

Push your feature branch and create a PR. Once this PR is merged, the version bump and release process will automatically be triggered by CI.

```bash
git push origin your-branch
```

### Releasing a New Version

Once your PR is merged into main, the CI pipeline takes care of the rest:

1. Release Branch Creation:
After merging, a GitHub Action will trigger, creating a pull request that contains updated version numbers and changelogs.

This is handled by the Changesets GitHub Action.
2. Versioning and Changelog:
The pull request will include a summary of the changes from all pending changesets.
Once this is merged, the action automatically updates the versions of the packages and edits the changelogs.
3. Publishing to npm:
After the version pull request is merged, the CI workflow will automatically:
• Publish the package to npm using yarn changeset publish.
• Create a GitHub release with the updated changelogs.

### Important Notes

- **Releasing is automated**: As a developer, you don't need to run `yarn publish` or create the GitHub release manually. CI will handle this after your changes are merged into the `main` branch.

- **Keep Changesets in mind**: Always make sure to add a changeset for any meaningful change that should be reflected in the next release (bug fixes, new features, or breaking changes).

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@
"author": "Civic Community",
"license": "MIT",
"dependencies": {
"changesets": "^1.0.2",
"flat": "^4.1.0",
"lodash": "^4.17.21",
"unix-timestamp": "^1.1.0",
"uuid": "^10.0.0",
"winston": "^3.14.2"
},
"devDependencies": {
"@changesets/cli": "^2.27.8",
"audit-ci": "^7.1.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-jest": "^29.7.0",
"babel-minify": "^0.5.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"changesets": "^1.0.2",
"eslint": "^8",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
Expand Down
Loading

0 comments on commit 8951522

Please sign in to comment.