Package build and publish #59
Workflow file for this run
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
name: Package build and publish | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'version' | |
required: true | |
type: string | |
npm_tag: | |
description: 'release tag' | |
required: false | |
type: string | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
submodules: 'recursive' | |
fetch-depth: 0 | |
- name: Enable corepack | |
run: corepack enable | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 18.x | |
cache: 'yarn' | |
- name: 'validation' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const permission = await github.rest.repos.getCollaboratorPermissionLevel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
username: context.actor | |
}); | |
if (permission.data.permission !== 'admin' && permission.data.permission !== 'write') { | |
core.setFailed(`User ${context.actor} does not have write or admin permissions to this repository.`); | |
} | |
const currentBranch = context.ref.replace('refs/heads/', ''); | |
if (currentBranch !== `release/v${{ github.event.inputs.version }}`) { | |
core.setFailed(`Current branch ${currentBranch} does not match release/v${{ github.event.inputs.version }}`); | |
} | |
const pullRequests = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
sort: 'created', | |
direction: 'desc', | |
}); | |
const pr = pullRequests.data.find(pr => pr.head.ref === currentBranch && pr.base.ref === 'develop'); | |
if (!pr) { | |
core.setFailed(`No open pull request found for ${currentBranch} to develop`); | |
} | |
- name: Check if the release branch exists | |
run: | | |
set -x | |
branch_name="release/v${{ github.event.inputs.version }}" | |
if ! git ls-remote --exit-code --heads origin "$branch_name" > /dev/null; then | |
echo "Branch $branch_name does not exist. Make sure to create the branch and create a Jira ticket with pr-comment-bot." | |
exit 1 | |
fi | |
- name: Setup jq | |
if: ${{ github.event.inputs.npm_tag }} | |
uses: dcarbone/install-jq-action@v2 | |
- name: Update version in package.json if npm_tag is provided | |
if: ${{ github.event.inputs.npm_tag }} | |
run: | | |
npm_version="${{ github.event.inputs.version }}-${{ github.event.inputs.npm_tag }}" | |
jq --arg npm_version "$npm_version" '.version = $npm_version' package.json > package.json.tmp && mv package.json.tmp package.json | |
- name: Set environments | |
run: | | |
git config --global user.name "sendbird-sdk-deployment" | |
git config --global user.email "[email protected]" | |
- name: Install and Build | |
run: | | |
yarn install | |
git diff | |
touch .env.production | |
echo "VITE_CHAT_AI_WIDGET_KEY=${{ secrets.chat_ai_widget_key }}" >> .env.production && \ | |
yarn build:npm | |
- name: Publish to npm | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.npm_token }}" >> .npmrc | |
if [ -z "${{ github.event.inputs.npm_tag }}" ]; then | |
npm publish --access=public | |
else | |
npm publish --tag ${{ github.event.inputs.npm_tag }} --access=public | |
echo "npm_tag is provided; Skipping the rest of the steps." | |
exit 1 | |
fi | |
- name: Update installed chat-ai-widget version to latest under packages/* | |
run: | | |
packages=( "self-service" ) | |
for package in "${packages[@]}"; do | |
cd ./packages/$package | |
yarn add @sendbird/chat-ai-widget@${{ github.event.inputs.version }} | |
cd - | |
done | |
git add . | |
git commit -m "chore: update chat-ai-widget version to v${{ github.event.inputs.version }}" | |
git push origin release/v${{ github.event.inputs.version }} | |
- name: Tag new target and push to origin | |
run: | | |
git tag v${{ github.event.inputs.version }} | |
git push origin v${{ github.event.inputs.version }} | |
- name: Approve PR | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
if [ -z "${{ github.event.inputs.npm_tag }}" ]; then | |
gh pr review --approve --body "approved by automation" | |
fi |