Skip to content

Commit e455e01

Browse files
authored
Add support to release dev packages (#493)
* Refactor current build and publish steps Signed-off-by: Shubham Sharma <[email protected]> * Move npm install to correct place Signed-off-by: Shubham Sharma <[email protected]> * Add dev publish steps Signed-off-by: Shubham Sharma <[email protected]> * Add package details to README Signed-off-by: Shubham Sharma <[email protected]> * Shared node_ver env; Signed-off-by: Shubham Sharma <[email protected]> * Revert matrix Signed-off-by: Shubham Sharma <[email protected]> * Use commit hash in version Signed-off-by: Shubham Sharma <[email protected]> --------- Signed-off-by: Shubham Sharma <[email protected]>
1 parent e46d17c commit e455e01

File tree

5 files changed

+83
-52
lines changed

5 files changed

+83
-52
lines changed

.github/workflows/build.yml

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@ on:
2626
# Manual trigger
2727
workflow_dispatch: {}
2828

29+
env:
30+
NODE_VER: 16.14.0
31+
2932
jobs:
3033
build:
3134
runs-on: ubuntu-latest
32-
environment: production
33-
env:
34-
NODE_VER: 16.14.0
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
node_version: [16.14.0]
3539
steps:
3640
- uses: actions/checkout@v3
3741

38-
# Setup .npmrc file to publish to npm
39-
- name: Configure .npmrc for NPM publish to @dapr
42+
- name: Setup Node ${{ matrix.node_version }}
4043
uses: actions/setup-node@v3
4144
with:
42-
node-version: ${{ env.NODE_VER }}
43-
registry-url: "https://registry.npmjs.org"
45+
node-version: ${{ matrix.node_version }}
4446

45-
- name: Build Package
47+
- name: Build package (install dependencies, lint, prettier, build)
4648
run: npm run build
4749

4850
# @TODO: add a depend on the test-e2e pipeline?
@@ -53,30 +55,85 @@ jobs:
5355
- name: Upload test coverage
5456
uses: codecov/codecov-action@v1
5557

56-
- name: Is Release?
57-
if: startswith(github.ref, 'refs/tags/v')
58-
run: echo "DEPLOY_PACKAGE=true" >> $GITHUB_ENV
58+
publish:
59+
needs: build
60+
if: startswith(github.ref, 'refs/tags/v')
61+
runs-on: ubuntu-latest
62+
environment: production
63+
steps:
64+
- uses: actions/checkout@v3
65+
66+
- name: Setup Node ${{ env.NODE_VER }}
67+
uses: actions/setup-node@v3
68+
with:
69+
node-version: ${{ env.NODE_VER }}
70+
registry-url: "https://registry.npmjs.org"
71+
72+
- name: Install dependencies
73+
run: npm install
74+
75+
- name: Build package
76+
run: npm run build-ci
5977

60-
# note: package.json gets updated here for the new package name
6178
- name: Publish to npm (@dapr/dapr)
62-
if: env.DEPLOY_PACKAGE == 'true'
6379
run: npm publish build/ --access public
6480
env:
6581
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6682

83+
# dapr-client is deprecated, but we still want to publish it for a while.
6784
- name: "[dapr-client] Configure to publish to dapr-client for deprecation notice reasons"
68-
if: env.DEPLOY_PACKAGE == 'true'
6985
run: |
7086
sed -i s#"@dapr/dapr"#"dapr-client"# package.json
7187
echo "This has been deprecated and will not be updated anymore, please use https://www.npmjs.com/package/@dapr/dapr" > README.md
7288
89+
- name: "[dapr-client] Install dependencies"
90+
run: npm install
91+
7392
- name: "[dapr-client] Build Package"
74-
if: env.DEPLOY_PACKAGE == 'true'
75-
run: npm run build
93+
run: npm run build-ci
7694

77-
# note: package.json gets updated here for the new package name
7895
- name: "[dapr-client] Publish to npm (dapr-client)"
79-
if: env.DEPLOY_PACKAGE == 'true'
96+
run: npm publish build/ --access public
97+
env:
98+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
99+
100+
publish-dev:
101+
needs: build
102+
if: startsWith(github.ref, 'refs/heads/main')
103+
runs-on: ubuntu-latest
104+
environment: development
105+
steps:
106+
- uses: actions/checkout@v3
107+
108+
- name: Setup Node ${{ env.NODE_VER }}
109+
uses: actions/setup-node@v3
110+
with:
111+
node-version: ${{ env.NODE_VER }}
112+
registry-url: "https://registry.npmjs.org"
113+
114+
- name: Configure package name
115+
run: |
116+
sed -i s#"@dapr/dapr"#"@dapr/dapr-dev"# package.json
117+
cat <(echo "WARNING: This is a development version of the SDK. It is not recommended to use this version in production.\n") README.md > README.md.tmp
118+
mv README.md.tmp README.md
119+
120+
- name: Configure version
121+
run: |
122+
# Version should be in the format of <version>-<timestamp>-<commit-hash>
123+
# e.g. 1.0.0-20220101000000-abcdef
124+
VERSION=$(npm version | grep '@dapr/dapr' | awk -F':' '{print $2}' | tr -d "[:space:],'")
125+
TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")
126+
COMMIT_HASH=$(git rev-parse --short HEAD)
127+
128+
sed -i s#"\"version\": \"$VERSION\""#"\"version\": \"$VERSION-$TIMESTAMP-$COMMIT_HASH\""# package.json
129+
130+
- name: Install dependencies
131+
run: npm install
132+
133+
- name: Build package
134+
run: npm run build-ci
135+
136+
- name: Publish to npm (@dapr/dapr-dev)
80137
run: npm publish build/ --access public
81138
env:
82139
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Instantly get started by installing the Dapr JS SDK and reading the [getting sta
2525
npm install --save @dapr/dapr
2626
```
2727

28+
You can also use the development version of the SDK which is built from the `main` branch. Make sure to remove the `@dapr/dapr` package first. This package is not meant for production use, and should only be used for development purposes.
29+
30+
```
31+
npm install --save @dapr/dapr-dev
32+
```
33+
2834
## Documentation
2935

3036
Visit [https://docs.dapr.io/developing-applications/sdks/js/](https://docs.dapr.io/developing-applications/sdks/js/) to view the full documentation.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"test:unit:utils": "NODE_ENV=test npm run test:unit 'test/unit/utils/.*\\.test\\.ts'",
3030
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
3131
"prebuild": "./scripts/prebuild.sh",
32-
"build": "./scripts/build.sh",
32+
"build-ci": "./scripts/build.sh",
33+
"build": "npm install && npm run lint && npm run pretty && npm run build-ci",
3334
"start:dev": "npm run build && nodemon --ext \".ts,.js\" --watch \"./src\" --exec \"npm run build\"",
3435
"pretty": "prettier --list-different \"**/*.{ts,tsx,js,jsx,json,md}\"",
3536
"pretty-fix": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\""

scripts/build.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ echo "Executing in $(pwd)"
2121
echo "Description: Build the package in build/"
2222
echo "====================================================="
2323

24-
echo "Installing Dependencies"
25-
npm install > /dev/null
26-
2724
# Prepare build
2825
echo "Preparing Build"
2926
rm -rf build/
@@ -35,10 +32,6 @@ mkdir build/
3532
# ./build-grpc.sh
3633

3734
# Build Package
38-
echo "Running eslint"
39-
npm run lint
40-
echo "Running prettier"
41-
npm run pretty
4235
echo "Building Library"
4336
npx tsc --outDir ./build/
4437

scripts/publish.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)