Skip to content

Commit

Permalink
chore(CI): Create workflow to release to NPM (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadjow authored Feb 28, 2025
1 parent 5a72a2d commit c830361
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to NPM

on:
workflow_dispatch:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn dev:build
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.4

[compare changes](https://github.com/stackbuilders/nuxt-utm/compare/v0.2.3...v0.2.4)

## v0.2.2

[compare changes](https://github.com/stackbuilders/nuxt-utm/compare/v0.1.5...v0.2.2)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ yarn test:watch
yarn release
```

For detailed information about the release process, please refer to our [Release Documentation](/docs/RELEASING.md).

## License

<!-- NOTE: If you need a different type of licence, please check with the OSS team before changing it -->
Expand Down
92 changes: 92 additions & 0 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Release Process

This document outlines the release process for the Nuxt UTM module.

## Release Workflow

We follow a two-step release process:

1. **Manual Release Preparation (Local)**:

- Version bump
- CHANGELOG update
- Tag creation
- Git commit

2. **Automated NPM Publishing (GitHub Actions)**:
- Triggered by the newly created release/tag
- Builds and publishes the package to NPM

## Manual Release Steps

To create a new release:

1. Ensure you have the latest changes from the main branch:

```bash
git checkout main
git pull origin main
```

2. Make sure all tests pass:

```bash
yarn test
```

3. Run the release script, which will:

- Bump the version in package.json
- Update the CHANGELOG.md
- Create a git tag
- Commit changes

```bash
yarn release
```

4. Push the changes including the new tag:
```bash
# This will be done automatically by the release script
```

## Automated NPM Publishing

After the manual release process:

1. GitHub Actions workflow [npm-publish.yml](../.github/workflows/npm-publish.yml) will be triggered automatically when:

- A new GitHub release is created
- OR manually triggered via workflow_dispatch

2. The workflow will:
- Check out the repository
- Set up Node.js
- Install dependencies
- Build the module
- Publish to NPM using the credentials stored in GitHub secrets

## Version Numbering

We follow [Semantic Versioning](https://semver.org/) for this project:

- **MAJOR** version for incompatible API changes
- **MINOR** version for backwards-compatible functionality additions
- **PATCH** version for backwards-compatible bug fixes

## Troubleshooting

If the automated publishing fails:

1. Check the GitHub Actions logs for errors
2. Ensure the `npm_token` secret is correctly set in the repository settings
3. Verify that the version in package.json hasn't already been published

## Additional Notes

- The release process uses [changelogen](https://github.com/unjs/changelogen) to generate CHANGELOG entries
- Always verify that the published package works correctly by installing it in a test project

---

For questions or assistance with the release process, please contact the maintainers or email [[email protected]](mailto:[email protected]).
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-utm",
"version": "0.2.3",
"version": "0.2.4",
"description": "A Nuxt 3 module for tracking UTM parameters.",
"keywords": [
"nuxt",
Expand Down Expand Up @@ -39,7 +39,8 @@
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxt-module-build prepare && nuxi prepare playground",
"release": "npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"release": "npm run prepack && changelogen --release && git push --follow-tags",
"publish": "npm run prepack && npm publish",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch"
Expand Down

0 comments on commit c830361

Please sign in to comment.