Skip to content

Commit

Permalink
chore: enable npm @next tag version release (#1122)
Browse files Browse the repository at this point in the history
**Background**
So far in npm we have stable versions, such as `1.0.0-rc.3, 1.0.0-rc.4, 1.0.0-rc.5`.
Now, we decided to release intermediate versions on demand as a preview with `@next` tag,
that would look like: `0.0.0-{hash}`

**How to install it**
To get the last published version under the 'next' tag,
 you need to append `@next` as below:
```js
npm install @ui5/webcomponents@next
```
Without the tag, as you usually install dependencies,
you get the latest released and stable version
```js
npm install @ui5/webcomponents
```
  • Loading branch information
ilhan007 authored Jan 10, 2020
1 parent 59e5972 commit d0bcf47
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
70 changes: 70 additions & 0 deletions .github/actions/pre-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const fs = require("fs");
const { promisify } = require("util");
const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
const child_process = require("child_process");
const glob = require("glob-promise");
const execSync = child_process.execSync;
const gitRev = execSync("git rev-parse HEAD").toString();

const PACKAGES = {};
const NPM_ORG = "@ui5/webcomponents";
const OTP = process.argv[2];

const run = async () => {
const FILES = await glob("**/packages/**/package.json", {
"ignore": ["**/node_modules/**/*.*", "**/dist/**/*.*", "**/playground/**/*.*"]
});

// Step 1: process package.json files
const pkgs = await Promise.all(FILES.map(processPackageJSON));

// Step 2: update package.json files
await Promise.all(pkgs.map(updatePackageJSON));

// Step 3: publish each package to npm
pkgs.forEach(publishPackage);
};

const processPackageJSON = async file => {
const folder = file.split("package.json")[0];
const fileRead = await readFileAsync(file);
const fileContent = JSON.parse(fileRead.toString());
const name = fileContent.name;

const version = `0.0.0-${gitRev.slice(0,9,)}`;

PACKAGES[name] = { name, file, fileContent, version, folder };
return PACKAGES[name];
};

const updatePackageJSON = async pkg => {
const file = pkg.file;
const fileContent = pkg.fileContent;
const dependencies = fileContent.dependencies;
const devDependencies = fileContent.devDependencies;

fileContent.version = pkg.version;
dependencies && getDependencies(dependencies).forEach(dep => {
fileContent.dependencies[dep] = PACKAGES[dep].version;
});
devDependencies && getDependencies(devDependencies).forEach(dep => {
fileContent.devDependencies[dep] = PACKAGES[dep].version;
});

return writeFileAsync(file, JSON.stringify(fileContent, null, " "));
};

const getDependencies = (dependencies) => {
return Object.keys(dependencies).filter(dep => dep.startsWith(NPM_ORG));
};

const publishPackage = pkg => {
console.info(`Publish ${pkg.name}: ${pkg.version} ...`); // eslint-disable-line
const OTP_PARAM = OTP ? `--otp=${OTP}` : ``;
execSync(`yarn publish ${pkg.folder} --tag=next --new-version=${pkg.version} ${OTP_PARAM}`);
};

run().catch(error => {
console.error("Release of @next version failed", error); // eslint-disable-line
});
35 changes: 35 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish

on:
push:
branches:
- master
jobs:
build:
if: "contains(github.event.head_commit.message, '#prerelease')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Install
run: yarn

- name: Build
run: yarn build

- name: Auth
run: npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm
env:
NPM_USERNAME: ${{ secrets.NPM_USERNAME }}
NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
node ./.github/actions/pre-release.js
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
"test": "npm-run-all --sequential test:base test:main test:fiori",
"lint": "wsrun --exclude-missing lint",
"link-all": "wsrun link",
"unlink-all": "wsrun unlink"
"unlink-all": "wsrun unlink",
"prerelease": "node ./.github/actions/pre-release.js"
},
"devDependencies": {
"nps": "^5.9.8",
"cross-env": "^5.2.0",
"glob-promise": "^3.4.0",
"npm-run-all": "^4.1.3",
"nps": "^5.9.8",
"rimraf": "^2.6.2",
"wsrun": "^3.6.4"
},
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==

"@types/glob@^7.1.1":
"@types/glob@*", "@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
Expand Down Expand Up @@ -3578,6 +3578,13 @@ glob-parent@^5.0.0, glob-parent@~5.1.0:
dependencies:
is-glob "^4.0.1"

glob-promise@^3.4.0:
version "3.4.0"
resolved "https://registry.npmjs.org/glob-promise/-/glob-promise-3.4.0.tgz#b6b8f084504216f702dc2ce8c9bc9ac8866fdb20"
integrity sha512-q08RJ6O+eJn+dVanerAndJwIcumgbDdYiUT7zFQl3Wm1xD6fBKtah7H8ZJChj4wP+8C+QfeVy8xautR7rdmKEw==
dependencies:
"@types/glob" "*"

glob-to-regexp@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
Expand Down

0 comments on commit d0bcf47

Please sign in to comment.