From 5f01de93ff4ceac3ecd993910edb977d47e0e58f Mon Sep 17 00:00:00 2001 From: Dirk Ehrhardt Date: Mon, 19 Aug 2024 11:04:52 +0200 Subject: [PATCH] chore: update release process and scripts --- README.md | 92 ++++++++++------------------------------------ package.json | 3 +- prepare_release.sh | 57 ---------------------------- version.sh | 10 +++++ 4 files changed, 32 insertions(+), 130 deletions(-) delete mode 100644 prepare_release.sh create mode 100755 version.sh diff --git a/README.md b/README.md index c62aeaf..1040186 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,10 @@ Welcome to the PAYONE Commerce Platform Client JavaScript SDK for the PAYONE Com - [PAYONE Commerce Platform Compliant Interfaces](#payone-commerce-platform-compliant-interfaces) - [Demonstration Projects](#demonstration-projects) - [Contributing](#contributing) -- [Releasing](#releasing) - - [How to use the prepare_release.sh script](#how-to-use-the-prepare_releasesh-script) +- [Releasing the library](#releasing-the-library) + - [Preparing the Release](#preparing-the-release) - [Changelog Generation with Conventional Changelog](#changelog-generation-with-conventional-changelog) + - [Merging the Release Branch](#merging-the-release-branch) - [GitHub Action for Release](#github-action-for-release) - [Minimum Supported Browser Versions](#minimum-supported-browser-versions) - [License](#license) @@ -683,63 +684,26 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) **[back to top](#table-of-contents)** -## Releasing +## Releasing the library -To ensure a smooth release process, a pre-release script has been created. This script automates versioning, tagging, and ensuring the working directory is in a proper state before creating a new release. Each release requires creating a new release branch, applying changes there, and verifying the version against the release branch name. +### Preparing the Release -### `prepare_release.sh` Script +- Checkout develop branch +- Create release branch (release/0.1.0) -The [`prepare_release.sh`](./prepare_release.sh) script is a bash script designed to update the version number in your project, commit the changes, and tag the commit with the new version number. - -### How to use the `prepare_release.sh` Script - -1. **Create and switch to a new release branch**: - - - Create a release branch named `release/v`. - - Example: - ```sh - git checkout -b release/v1.2.3 - ``` - -2. **Ensure your working directory is clean**: - - - Make sure you have no uncommitted changes. The script will exit if there are any changes detected. - - Verify that you are on the `release/v` branch before proceeding. - -3. **Run the script with the desired version number**: - - - Open your terminal and navigate to the root directory of your project. - - Execute the script with the version number as an argument. - - ```sh - ./prepare_release.sh - ``` - - - Example: - - ```sh - ./prepare_release.sh 1.2.3 - ``` - -4. **Script Workflow**: +```sh +git checkout -b release/0.1.0 +``` - - The script checks if a version number is provided and validates its format. - - It ensures the working directory is clean and that you are on the `release/v` branch. - - It verifies that the provided version tag matches the release branch name. - - It updates the version number in `package.json` and `package-lock.json`. - - Commits the changes with a message "Update version to ". - - Tags the commit with "v". +- Apply versioning -5. **Handling Mistakes**: - - If you make a mistake, you can undo the commit and delete the tag by running the following commands: - ```sh - git reset --soft HEAD~1 - git tag -d v - ``` +```sh +npm version major|minor|patch +``` ### Changelog Generation with Conventional Changelog -After calling the `prepare_release.sh` script, it is recommended to manually trigger the changelog generation script (which uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)). +The changelog gets generated automatically when the npm version gets bumped via `npm version major|minor|patch` within the `version.sh` script. 1. **Conventional Commit Messages**: @@ -751,32 +715,14 @@ After calling the `prepare_release.sh` script, it is recommended to manually tri - We enforce conventional commit messages using [Lefthook](https://github.com/evilmartians/lefthook) with [commitlint](https://github.com/conventional-changelog/commitlint). - This setup ensures that all commit messages are validated before they are committed. -3. **Generate Changelog**: - - Run the changelog generation script to update the `CHANGELOG.md` file: - ```sh - npm run changelog - ``` - - Review and commit the updated changelog before proceeding with the release. - ### Merging the Release Branch -1. **Open a Pull Request (PR)**: - - - Open a PR from the `release/v` branch to the `master` branch on GitHub. - - Include a clear description of the changes and the new version. - -2. **Code Review**: - - - Request reviews from team members. - - Address feedback and make necessary changes. - -3. **Merge PR**: - - - Once approved, merge the PR to `master`. +- Create PR on `develop` branch +- Merge `develop` in `master` branch ### GitHub Action for Release -After successfully running the `prepare_release.sh` and changelog generation scripts and committing all changes to the `master` branch via a PR, an admin can trigger a GitHub Action to finalize and publish the release. This action ensures that the release process is automated, consistent, and deploys the new release from the `master` branch. +After successfully merging all changes to the `master` branch, an admin can trigger a GitHub Action to finalize and publish the release. This action ensures that the release process is automated, consistent, and deploys the new release from the `master` branch. **Triggering the GitHub Action**: @@ -786,6 +732,8 @@ After successfully running the `prepare_release.sh` and changelog generation scr By following these steps, you can efficiently manage and streamline the release process for the PAYONE Commerce Platform Client JavaScript SDK, ensuring that the new release is published from the `master` branch while maintaining consistency and reliability. +**[back to top](#table-of-contents)** + ## Minimum Supported Browser Versions The PAYONE Commerce Platform Client JavaScript SDK targets ES6 (ECMAScript 2015) and supports the following minimum browser versions: diff --git a/package.json b/package.json index ac8af5c..8ac2825 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "prepack": "npm run lint && npm run prepublishOnly", "test": "vitest", "test:coverage": "vitest run --coverage", - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0" + "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", + "version": "./version.sh" }, "keywords": [ "payone", diff --git a/prepare_release.sh b/prepare_release.sh deleted file mode 100644 index 6e56462..0000000 --- a/prepare_release.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -VERSION=$1 - -# Check if an argument is provided -if [ -z "$VERSION" ]; then - echo "Error: No version number provided." - echo "Usage: $0 " - exit 1 -fi - -# Check if the argument is a valid version number - if yes echo the version number if no exit with an error message -if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Valid version number: $VERSION" -else - echo "Error: Invalid version number format." - echo "Usage: $0 " - exit 1 -fi - -# tag should start with a 'v' -TAG="v$VERSION" - -# Check if the tag already exists -if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then - echo "Error: Tag $TAG already exists." - exit 1 -fi - -# Check if the working directory is clean -if [ -n "$(git status --porcelain)" ]; then - echo "Error: Working directory not clean." - exit 1 -fi - -# Check if the current branch is the correct release branch -if [ "$(git rev-parse --abbrev-ref HEAD)" != "release/$TAG" ]; then - echo "Error: Not on the correct release branch." - exit 1 -fi - -# Update the version number in the package.json file -sed -i '' -e "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" package.json - -# Update the version number in the package-lock.json file -sed -i '' -e "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" package-lock.json - -# Commit the changes -git add package.json package-lock.json -git commit -m "Update version to $VERSION" -git tag -a $TAG -m "Release version $VERSION" - -echo "Version updated to $VERSION and tagged in Git." -echo "" -echo "If this was a mistake, you can run" -echo " git reset --soft HEAD~1" -echo " git tag -d ${TAG}" diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..9e9317a --- /dev/null +++ b/version.sh @@ -0,0 +1,10 @@ +NEW_VERSION=$npm_package_version + +if [ -n "$NEW_VERSION" ]; then + npm run changelog + git add CHANGELOG.md + echo "Updated CHANGELOG.md" + +else + echo "Script can only be run as npm version hook" +fi