From fe45c69fb6dcb2d2277c2d690d88836c131b00da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 6 Apr 2022 20:34:03 +0200 Subject: [PATCH] chore: add check-relase script as part of perversion validations. --- .github/workflows/release.yaml | 1 - CONTRIBUTING.md | 22 +++++++++++++++++++++- package.json | 3 ++- scripts/check-release.js | 29 +++++++++++++++++++++++++++++ scripts/check-release.sh | 14 ++++++++++++++ tsconfig.json | 3 ++- 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 scripts/check-release.js create mode 100755 scripts/check-release.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index aceec6ad37c..4fc1af55c88 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,7 +22,6 @@ jobs: registry-url: 'https://registry.npmjs.org' - run: | yarn install --frozen-lockfile - yarn lint - run: | TAG=$(echo $GITHUB_REF_NAME | grep -oP '^v\d+\.\d+\.\d+-?\K(\w+)?') npm publish --tag ${TAG:-latest} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 43ae66b1fae..c22a166eb38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,4 +57,24 @@ The controller takes care of the following: - try/catch RequestHandler method - error handling with proper response code if they fail - `await` the RequestHandler method if it returns a promise (so you don't have to) -- access control so that you can just list the required permission for a RequestHandler and the base Controller will make sure the user have these permissions. \ No newline at end of file +- access control so that you can just list the required permission for a RequestHandler and the base Controller will make sure the user have these permissions. + +## Creating a release +In order to produce a release you will need to be a Unleash core team member and have the Unleash admin role assigned on the Unleash organization on GitHub. + +# Step 1: create a new version tag + +Use npm to set the version in package.json and specify a version tag. + +```sh +npm version 3.10.0 +``` + +This command will trigger an internal verification step where we will perform the following steps: + +- *STEP 1. Check unleash-frontend version* - Validate that a latest release of unleash-server does not depend on a pre-release of unleash-frontend (beta, alpha, etc) +- *STEP 2. Lint* - Run lint checks on the code. +- *STEP 3. Build* - Validate that we are able to build the project +- *STEP 4. Test* - Validate that all test runs green. + +If all steps completes a single commit is produced on the main branch where the `version` property in package.json is updated, and a git tag is created to point to that tag specifically. \ No newline at end of file diff --git a/package.json b/package.json index cf714ef254c..a1cea678890 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "test:coverage:jest": "NODE_ENV=test PORT=4243 jest --silent --ci --json --coverage --testLocationInResults --outputFile=\"report.json\" --forceExit --testTimeout=10000", "seed:setup": "ts-node src/test/e2e/seed/segment.seed.ts", "seed:serve": "UNLEASH_DATABASE_NAME=unleash_test UNLEASH_DATABASE_SCHEMA=seed yarn run start:dev", - "clean": "del-cli --force dist" + "clean": "del-cli --force dist", + "preversion": "./scripts/check-release.sh $npm_package_version" }, "jest": { "automock": false, diff --git a/scripts/check-release.js b/scripts/check-release.js new file mode 100644 index 00000000000..ad6fdcd7a66 --- /dev/null +++ b/scripts/check-release.js @@ -0,0 +1,29 @@ +const semver = require('semver'); +//@ts-ignore +const pck = require('../package.json'); + +const newUnleashVersion = process.argv[2]; +const frontendVersion = pck.dependencies['unleash-frontend']; + +function isPrerelease(version) { + const arr = semver.prerelease(version); + return arr && arr.length > 0; +} + +if (!newUnleashVersion) { + console.error('You must provide the new Unleash version as argument'); + process.exit(1); +} + +if (!isPrerelease(newUnleashVersion)) { + if (isPrerelease(frontendVersion)) { + console.error( + `A latest version of unleash-server (${newUnleashVersion}) cannot depend on a pre-release of unleash-frontend (${frontendVersion})`, + ); + process.exit(1); + } +} + +console.log( + ` Passed!\x1b[36m unleash-server v${newUnleashVersion}\x1b[0m can depend on\x1b[36m unleash-frontend v${frontendVersion}\x1b[0m`, +); diff --git a/scripts/check-release.sh b/scripts/check-release.sh new file mode 100755 index 00000000000..4d3b3ab2c9a --- /dev/null +++ b/scripts/check-release.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +echo -e "\n STEP 1. Check unleash-frontend version" +node scripts/check-release.js $1 + +echo -e "\n STEP 2. Lint" +yarn run lint + +echo -e "\n STEP 3. Build" +yarn run build + +echo -e "\n STEP 4. Test" +yarn run test \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 5a20ffaf592..433c29adeea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -76,6 +76,7 @@ "snapshots", "coverage", "website", - "setupJest.js" + "setupJest.js", + "scripts" ] }