-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: enable npm @next tag version release (#1122)
**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
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters