Skip to content

Commit

Permalink
ci: update deploy workflows (#336)
Browse files Browse the repository at this point in the history
## Changes

- Update deploy workflow
  >AS-IS: A tag creation triggers the self-service deploy workflow.
  >TO-BE: A merge event triggers the self-service deploy workflow.

ticket: [SECURE-601]

[SECURE-601]:
https://sendbird.atlassian.net/browse/SECURE-601?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
bang9 authored Aug 14, 2024
1 parent 84a0975 commit 1cba826
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
28 changes: 21 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ orbs:
aws-cli: circleci/[email protected]
aws-s3: circleci/[email protected]

parameters:
run_deploy_prod:
type: boolean
default: false

executors:
ci-aws:
docker:
Expand Down Expand Up @@ -104,6 +109,9 @@ jobs:
# Publish - build self-service
build:
executor: node
parameters:
widget_version:
type: string
steps:
- checkout
- run:
Expand All @@ -114,7 +122,7 @@ jobs:
command: |
cd ./packages/self-service
npm install
npm run build version=${CIRCLE_TAG}
npm run build version=<< parameters.widget_version >>
# TODO: update self-service to use yarn workspaces
# yarn install --immutable --immutable-cache
# yarn build
Expand Down Expand Up @@ -174,27 +182,33 @@ workflows:
- run-test:
requires:
- prepare
deploy_to_s3:

deploy_prod:
when: << pipeline.parameters.run_deploy_prod >>
jobs:
- build:
name: build
filters: &only_version_tag_trigger
tags:
only: /^v\d+\.\d+\.\d+$/
widget_version: ""
filters: &default_branch_trigger
branches:
ignore: /.*/
only:
- develop
- upload_to_s3_and_invalidate_cache:
name: upload_to_s3_and_invalidate_cache
filters: *only_version_tag_trigger
filters: *default_branch_trigger
s3_bucket: $S3_BUCKET
distribution_id: $DISTRIBUTION_ID
role_arn: $ROLE_ARN
requires:
- build
context:
- circleci-dashboard-bot

deploy_stg:
jobs:
- build:
name: build_staging
widget_version: $CIRCLE_TAG
filters: &only_version_tag_trigger_staging
tags:
only: /^v\d+\.\d+\.\d+-staging(\.\d+)?$/
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/self-service-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: self-service build and publish

env:
DEFAULT_BRANCH: develop

on:
pull_request:
branches:
- ${{ env.DEFAULT_BRANCH }}
types:
- closed

jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
env:
CIRCLECI_TOKEN: ${{ secrets.CIRCLECI_API_TOKEN }}
DEFAULT_BRANCH: ${{ env.DEFAULT_BRANCH }}
steps:
- name: Check if the source branch is a release branch
run: |
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
echo "Source branch is $PR_BRANCH"
if [[ "$PR_BRANCH" == release/* ]]; then
echo "The source branch is a release branch, proceed with deployment."
curl -d '{\"branch\": \"${DEFAULT_BRANCH}\", \"parameters\": {\"run_deploy_prod\": true}}' \
-H 'Content-Type: application/json' \
-H 'Circle-Token: ${CIRCLECI_TOKEN}' \
-X POST https://circleci.com/api/v2/project/gh/sendbird/chat-ai-widget/pipeline
else
echo "The source branch is not a release branch, skipping deployment."
exit 0
fi
9 changes: 8 additions & 1 deletion packages/self-service/scripts/getWidgetVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ const packageJson = JSON.parse(fs.readFileSync('../../package.json', 'utf8'));
* */
export function getWidgetVersion() {
const version = process.argv[2];
return version ? `${version.split('version=')[1]}` : `v${packageJson.version}`;

if (!version.startsWith('version=') || version === 'version=') {
return `v${packageJson.version}`;
}

return version.split('version=')[1];
}

console.log('widget version:', getWidgetVersion());
11 changes: 7 additions & 4 deletions release-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
3. Enter the target version (e.g., 1.3.1) in the version field, and specify `rc` / `alpha` / `beta` for the `npm_tag` field if necessary.
<img width="450px" alt="workflow-guide" src="screenshot/workflow-guide.png">
4. Hit "Run workflow" button.

Once all the steps in the workflow are successfully completed:
5. Once all the steps in the workflow are successfully completed:
- The build output will be published to npm. (if `npm_tag` is provided, we stop the workflow from here)
- A commit will be pushed to the release PR created in Step 0. This commit includes:
- `@sendbird/chat-ai-widget` dependency version updated in `/packages/*`.
- A new tag(`v{version}`) will be pushed to the origin to trigger the self-service script deployment.
- Check the progress in [Circle CI dashboard](https://app.circleci.com/pipelines/github/sendbird/chat-ai-widget).
- A new tag(`v{version}`) will be pushed to the origin ~~to trigger the self-service script deployment.~~

## Step 2 - Publish a new self-service script (using automated workflow)
1. Merge the PR created in Step 0.
2. When the release branch is merged into the default branch, the [self-service-publish](./.github/workflows/self-service-publish.yml) workflow will deploy the self-service script.
- Check the progress in [Circle CI dashboard](https://app.circleci.com/pipelines/github/sendbird/chat-ai-widget).

### Want to publish `@sendbird/chat-ai-widget` manually?
1. Update the `version` field in `package.json`.
Expand Down

0 comments on commit 1cba826

Please sign in to comment.