diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c4ecb2..6d848f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,3 +22,35 @@ jobs: run: | npm run test npm run build + + release: + needs: build + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check for version bump + id: version + run: | + PACKAGE_VERSION=$(node -p "require('./package.json').version") + if git rev-parse "${PACKAGE_VERSION}" >/dev/null 2>&1; then + echo "Tag ${PACKAGE_VERSION} already exists, skipping release." + echo "changed=false" >> "$GITHUB_OUTPUT" + else + echo "New version detected: ${PACKAGE_VERSION}" + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "version=${PACKAGE_VERSION}" >> "$GITHUB_OUTPUT" + fi + - name: Create tag and GitHub Release + if: steps.version.outputs.changed == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + VERSION=${{ steps.version.outputs.version }} + git tag "${VERSION}" + git push origin "${VERSION}" + gh release create "${VERSION}" --title "${VERSION}" --generate-notes diff --git a/README.md b/README.md index d0b90af..4068e4b 100644 --- a/README.md +++ b/README.md @@ -219,12 +219,14 @@ parser.parse('COUNTIF(A1:E2, ">5")'); // returns `5` To publish a new version of the package: -1. **Create a release** by running: +1. **Bump the version** on a feature branch: ```sh - $ npm run release + $ npm run release patch # or minor, or major ``` - This uses [`generate-release`](https://www.npmjs.com/package/generate-release) to bump the version in `package.json`, create a git tag, and push changes. + This updates the version in `package.json` without committing or tagging. -2. **Publish to GitHub Packages** happens automatically — the `.github/workflows/publish.yml` workflow triggers when a GitHub Release is published, building and publishing the package to the GitHub Packages registry. +2. **Commit and open a PR** to `main`. + +3. **After the PR is merged**, CI will automatically detect the version bump, create a git tag and a GitHub Release, which triggers the publish workflow to build and publish the package to the GitHub Packages registry. Before publishing, the `prepublishOnly` hook automatically runs linting, tests, and the build to ensure the package is in a good state. diff --git a/package-lock.json b/package-lock.json index 275c22c..388f31e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@time-loop/hot-formula-parser", - "version": "4.3.1", + "version": "4.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@time-loop/hot-formula-parser", - "version": "4.3.1", + "version": "4.3.2", "dependencies": { "@formulajs/formulajs": "^2.3.0", "json5": "^2.2.3", diff --git a/package.json b/package.json index 9b70238..0f22886 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@time-loop/hot-formula-parser", - "version": "4.3.1", + "version": "4.3.2", "description": "Formula parser", "type": "commonjs", "main": "dist/index.js", @@ -19,7 +19,7 @@ "test:generate": "ts-node test/scripts/generatePerfTestData.ts", "build": "tsc", "generate-parser": "cd src/grammar-parser && jison grammar-parser.jison", - "release": "generate-release", + "release": "npm version --no-git-tag-version", "prepublishOnly": "npm run clean && npm run check && npm run build" }, "repository": { @@ -48,7 +48,6 @@ "@types/jest": "^29.5.12", "eslint": "^9.9.0", "eslint-plugin-jest": "^28.8.0", - "generate-release": "^1.1.1", "globals": "^15.9.0", "jest": "^29.7.0", "jest-cli": "^29.7.0",