Skip to content

Commit

Permalink
Add publish action
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrung committed Dec 30, 2021
1 parent f7977c7 commit fee1ec4
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/script/get-current-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

const pjson = require('../../package.json');
console.log(pjson.version);
9 changes: 9 additions & 0 deletions .github/script/get-pre-release-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

const version = require('../../package.json').version;
const preRelease = version.split('-');
if (preRelease[1]) {
console.log(preRelease[1].split('.')[0]);
} else {
console.log('');
}
16 changes: 16 additions & 0 deletions .github/script/get-prev-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

// eslint-disable-next-line @typescript-eslint/no-var-requires
const exec = require('child_process').execSync;

const versions = exec('npm view amazon-chime-sdk-js versions --json').toString().trim().split("\n");
// The output would be something like
// [
// "1.0.0",
// ...
// "2.8.0", <- previous version
// "2.9.0" <- latest version
// ]

const prev_version = versions[versions.length-3];
console.log(prev_version.substring(3,prev_version.length-2))
15 changes: 15 additions & 0 deletions .github/script/send-test-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Send test report is a minimal script that makes a HTTP POST call to a webhook to send a slack message.
// For example, this script passes results of the browser compatibility report to the webhook so that the amazon-chime-js-sdk team can be notified of the results.

const axios = require('axios');

var myArgs = process.argv.slice(2);

axios.post(myArgs[0], {
'github_workflow_url': myArgs[1],
'browser_compatibility_tests_status': myArgs[2].toUpperCase()
}, res => {
console.log(res);
}, err => {
console.log(err);
});
39 changes: 39 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish
# When a new Github Release is created, publish to NPM
on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Package
uses: actions/checkout@v2
with:
ref: ${{ github.event.release.tag_name }}
- name: Setup Node environment
uses: actions/setup-node@v1
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- name: NPM Install
run: npm install
- name: NPM run build
run: npm run build
- name: Get npm tag name if needed
id: npm_tag
run: |
pre_release_name=$(.github/script/get-pre-release-name.js)
echo "Pre release name:" $pre_release_name
echo ::set-output name=npm_tag::$pre_release_name
- name: Publish to NPM latest
if: steps.npm_tag.outputs.npm_tag == ''
run: echo "npm publish"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Publish to NPM with tag
if: steps.npm_tag.outputs.npm_tag != ''
run: echo "npm publish --tag ${{ steps.npm_tag.outputs.npm_tag }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
7 changes: 6 additions & 1 deletion script/release.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

const { versionBump, currentVersion } = require('./version-util');
const { versionBump, currentVersion, isPreRelease } = require('./version-util');
const { logger, spawnOrFail, prompt, shouldContinuePrompt, quit, process, path } = require('./cli-utils');

const deployDemo = (version) => {
Expand Down Expand Up @@ -49,6 +49,11 @@ const release = async () => {
};

const hotfix = async () => {
logger.log(currentVersion);
if (isPreRelease(currentVersion)) {
logger.error(`We currently do not do hotfix for pre-release version.`);
quit(1);
}
await cleanUp();

buildAndPack();
Expand Down
4 changes: 2 additions & 2 deletions script/version-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { logger, spawnOrFail, prompt, shouldContinuePrompt, quit, fs, process, pa
const currentVersion = require('../package.json').version;

const isPreRelease = (version) => {
return version.split('.')[3] >0;
return version.split('.')[3] >= 0;
};

const getNewVersion = (currentVersion, versionIncrement) => {
Expand Down Expand Up @@ -122,5 +122,5 @@ const versionBump = async (option, branchName) => {
module.exports = {
versionBump,
currentVersion,
updateBaseBranch
isPreRelease
};

0 comments on commit fee1ec4

Please sign in to comment.