Skip to content

Commit 3f506b1

Browse files
committed
ci: add publish package workflow
1 parent 84ba784 commit 3f506b1

File tree

6 files changed

+124
-23
lines changed

6 files changed

+124
-23
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ aliases:
66
key: v{{ .Environment.CACHE_VERSION }}-yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
77
- &install_node_modules
88
name: Install node_modules
9-
command: yarn install --immutable
9+
command: yarn install --frozen-lockfile
1010
- &save_node_modules_base
1111
key: v{{ .Environment.CACHE_VERSION }}-yarn-base-{{ arch }}-{{ checksum "yarn.lock" }}
1212
paths:

.github/workflows/ci.yml

+17-17
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
matrix:
2020
node-version: [16.x]
2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v3
24+
uses: actions/setup-node@v4
2525
with:
2626
node-version: ${{ matrix.node-version }}
2727

@@ -31,14 +31,14 @@ jobs:
3131

3232
- name: Check cached node_modules
3333
id: check_cache
34-
uses: actions/cache@v3
34+
uses: actions/cache@v4
3535
with:
3636
path: ${{ env.CACHE_NODE_MODULES_PATH }}
3737
key: ${{ steps.lockfile_hash.outputs.hash }}
3838

3939
- name: Install dependencies
4040
if: steps.check_cache.outputs.cache-hit == ''
41-
run: yarn install --immutable
41+
run: yarn install --frozen-lockfile
4242
outputs:
4343
cache_node_modules_key: ${{ steps.lockfile_hash.outputs.hash }}
4444

@@ -49,14 +49,14 @@ jobs:
4949
matrix:
5050
node-version: [16.x]
5151
steps:
52-
- uses: actions/checkout@v3
52+
- uses: actions/checkout@v4
5353
- name: Use Node.js ${{ matrix.node-version }}
54-
uses: actions/setup-node@v3
54+
uses: actions/setup-node@v4
5555
with:
5656
node-version: ${{ matrix.node-version }}
5757

5858
- name: Check cached node_modules
59-
uses: actions/cache@v3
59+
uses: actions/cache@v4
6060
with:
6161
path: ${{ env.CACHE_NODE_MODULES_PATH }}
6262
key: ${{ needs.prepare.outputs.cache_node_modules_key }}
@@ -71,14 +71,14 @@ jobs:
7171
matrix:
7272
node-version: [16.x, 18.x]
7373
steps:
74-
- uses: actions/checkout@v3
74+
- uses: actions/checkout@v4
7575
- name: Use Node.js ${{ matrix.node-version }}
76-
uses: actions/setup-node@v3
76+
uses: actions/setup-node@v4
7777
with:
7878
node-version: ${{ matrix.node-version }}
7979

8080
- name: Check cached node_modules
81-
uses: actions/cache@v3
81+
uses: actions/cache@v4
8282
with:
8383
path: ${{ env.CACHE_NODE_MODULES_PATH }}
8484
key: ${{ needs.prepare.outputs.cache_node_modules_key }}
@@ -93,14 +93,14 @@ jobs:
9393
matrix:
9494
node-version: [16.x]
9595
steps:
96-
- uses: actions/checkout@v3
96+
- uses: actions/checkout@v4
9797
- name: Use Node.js ${{ matrix.node-version }}
98-
uses: actions/setup-node@v3
98+
uses: actions/setup-node@v4
9999
with:
100100
node-version: ${{ matrix.node-version }}
101101

102102
- name: Check cached node_modules
103-
uses: actions/cache@v3
103+
uses: actions/cache@v4
104104
with:
105105
path: ${{ env.CACHE_NODE_MODULES_PATH }}
106106
key: ${{ needs.prepare.outputs.cache_node_modules_key }}
@@ -109,7 +109,7 @@ jobs:
109109
run: yarn test --collect-coverage
110110

111111
- name: Upload coverage reports to Codecov
112-
uses: codecov/codecov-action@v3
112+
uses: codecov/codecov-action@v4
113113
with:
114114
token: ${{ secrets.CODECOV_TOKEN }}
115115
verbose: true
@@ -121,14 +121,14 @@ jobs:
121121
matrix:
122122
node-version: [16.x]
123123
steps:
124-
- uses: actions/checkout@v3
124+
- uses: actions/checkout@v4
125125
- name: Use Node.js ${{ matrix.node-version }}
126-
uses: actions/setup-node@v3
126+
uses: actions/setup-node@v4
127127
with:
128128
node-version: ${{ matrix.node-version }}
129129

130130
- name: Check cached node_modules
131-
uses: actions/cache@v3
131+
uses: actions/cache@v4
132132
with:
133133
path: ${{ env.CACHE_NODE_MODULES_PATH }}
134134
key: ${{ needs.prepare.outputs.cache_node_modules_key }}

.github/workflows/comment-bot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
pr-comment:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
10-
- uses: sendbird/release-automation-action@0.0.4
9+
- uses: actions/checkout@v4
10+
- uses: sendbird/release-automation-action@latest
1111
with:
1212
gh_token: ${{ secrets.GITHUB_TOKEN }}
1313
circleci_token: ${{ secrets.CIRCLECI_BOT_TOKEN }}

.github/workflows/publish-package.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: publish package to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'version'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- uses: actions/setup-node@v4
19+
- name: 'validation'
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
const permission = await github.repos.getCollaboratorPermissionLevel({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
username: context.actor
27+
});
28+
if (permission.data.permission !== 'admin' && permission.data.permission !== 'write') {
29+
core.setFailed(`User ${context.actor} does not have write or admin permissions to this repository.`);
30+
}
31+
const currentBranch = context.ref.replace('refs/heads/', '');
32+
if (currentBranch !== `release/${{ github.event.inputs.version }}`) {
33+
core.setFailed(`Current branch ${currentBranch} does not match release/${{ github.event.inputs.version }}`);
34+
}
35+
const pullRequests = await github.pulls.list({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
state: 'open',
39+
sort: 'created',
40+
direction: 'desc',
41+
});
42+
const pr = pullRequests.data.find(pr => pr.head.ref === currentBranch && pr.base.ref === 'main');
43+
if (!pr) {
44+
core.setFailed(`No open pull request found for ${currentBranch} to main`);
45+
}
46+
core.exportVariable('PR_NUMBER', pr.number);
47+
- run: yarn install --frozen-lockfile
48+
- name: 'set environments'
49+
run: |
50+
echo "//registry.npmjs.org/:_authToken=${{ secrets.npm_token }}" >> .npmrc
51+
git config --global user.email "[email protected]"
52+
git config --global user.name "sendbird-sdk-deployment"
53+
- name: 'publish to npm'
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
run: |
57+
lerna version ${{ github.event.inputs.version }} --yes
58+
lerna publish from-git --yes
59+
- name: 'approve a pull request'
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
gh pr review ${{ env.PR_NUMBER }} --approve --body "approved by automation"

.github/workflows/trigger-deploy.yml renamed to .github/workflows/publish-sample.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: deployment trigger
1+
name: publish sample application
22

33
on:
44
workflow_dispatch:
@@ -64,7 +64,7 @@ jobs:
6464
# key: ${{ steps.lockfile_hash.outputs.hash }}
6565
# - name: Install dependencies
6666
# if: steps.check_cache.outputs.cache-hit == ''
67-
# run: yarn install --immutable
67+
# run: yarn install --frozen-lockfile
6868
# - name: Create env.ts
6969
# run:
7070
# echo "export const APP_ID = '${{ secrets.sendbird_app_id }}';" >> sample/src/env.ts
@@ -117,7 +117,7 @@ jobs:
117117
# - name: Install dependencies
118118
# if: steps.check_cache.outputs.cache-hit == ''
119119
# run:
120-
# yarn install --immutable
120+
# yarn install --frozen-lockfile
121121
# - name: Install pods
122122
# run: cd sample/ios && pod install
123123
# - name: Create env.ts

RELEASE_GUIDE.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Release Guide
2+
3+
This guide describes how to create and deploy a new release of the project.
4+
5+
## Step 1: Create a release branch
6+
7+
Create a branch for the new release. The branch name should follow the `release/X.Y.Z` format, where `X.Y.Z` represents the release version.
8+
9+
```bash
10+
git checkout -b release/X.Y.Z
11+
```
12+
13+
## Step 2: Write CHANGELOG_DRAFT.md
14+
15+
Record the changes for this release in the `CHANGELOG_DRAFT.md` file.
16+
17+
## Step 3: Commit and push changes
18+
19+
Commit the changes you've made and push the branch to the remote repository.
20+
21+
```bash
22+
git add .
23+
git commit -m "chore: update changelog draft"
24+
git push origin release/X.Y.Z
25+
```
26+
27+
## Step 4: Create a PR and ticket
28+
29+
Create a Pull Request for the newly pushed branch. The PR should be requested to the `main` branch.
30+
And add a `/bot create ticket` comment to create a ticket in the project management tool.
31+
32+
## Step 5: Run the publish-package workflow
33+
34+
Execute the `publish-package` workflow in GitHub Actions. This workflow is defined in the `.github/workflows/publish-package.yml` file.
35+
36+
1. workflow uses `lerna` to update the `changelog.md` file based on the commit history and creates a GitHub release.
37+
2. The workflow also publishes the package to NPM.
38+
3. If all the steps are completed successfully, the PR is approved by the bot.

0 commit comments

Comments
 (0)