From 80701c4e8cb0db2c3068d40c575a2704b7b51092 Mon Sep 17 00:00:00 2001 From: Irene Ryu Date: Wed, 3 Apr 2024 18:21:58 +0900 Subject: [PATCH] Another trial --- .github/workflows/package-publish.yml | 72 +++++++++++------ .github/workflows/pr-comment-bot.yml | 19 +++++ .github/workflows/release-ticket-creation.yml | 79 ------------------- 3 files changed, 69 insertions(+), 101 deletions(-) create mode 100644 .github/workflows/pr-comment-bot.yml delete mode 100644 .github/workflows/release-ticket-creation.yml diff --git a/.github/workflows/package-publish.yml b/.github/workflows/package-publish.yml index 4d17e277c..90411cb49 100644 --- a/.github/workflows/package-publish.yml +++ b/.github/workflows/package-publish.yml @@ -1,49 +1,77 @@ -name: npm publish +name: publish + on: workflow_dispatch: inputs: version: - description: 'Target version' + description: 'version' required: true - push: - branches: - - 'feat/AC-1856' + type: string + npm_tag: + description: 'release tag' + required: false + type: string jobs: publish: - name: Publish runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Check if branch exists - id: check-branch + - uses: actions/setup-node@v3 + with: + node-version: 16.x + - name: Check if the release branch exists run: | - if git ls-remote --heads origin release/v${{ github.event.inputs.version }} | grep -q refs/heads/release/v${{ github.event.inputs.version }}; then - echo "Branch exists." - else - echo "Branch does not exist." + 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 - - uses: actions/setup-node@v3 - - name: Install and Build 🔧 + - name: Install and Build run: | npm install - npm version ${{ github.event.inputs.version }} touch .env.production echo "VITE_CHAT_AI_WIDGET_KEY=${{ secrets.chat_ai_widget_key }}" >> .env.production npm run build:npm - - name: 'set environments' + - name: Publish to npm + run: | + if [ -z "${{ github.event.inputs.npm_tag }}" ]; then + npm publish --access=public + else + npm publish --tag ${{ github.event.inputs.npm_tag }} --access=public + fi + - name: Set environments run: | - echo "//registry.npmjs.org/:_authToken=${{ secrets.npm_token }}" >> .npmrc - git config --global user.email "sha.sdk_deployment@sendbird.com" git config --global user.name "sendbird-sdk-deployment" - - name: 'build and publish to npm' + git config --global user.email "sha.sdk_deployment@sendbird.com" + echo "RELEASE_DATE=$(date +'%b %d %Y')" >> $GITHUB_ENV + echo "LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV + - name: Generate CHANEGLOG run: | - npm publish -access=public - - name: 'create a pull request' + echo "## [$LATEST_TAG] - $RELEASE_DATE" > temp-changelog.md + git log $LATEST_TAG..develop --oneline >> temp-changelog.md + echo "" >> temp-changelog.md + cat CHANGELOG.md >> temp-changelog.md + mv temp-changelog.md CHANGELOG.md + git commit -m "Update CHANGELOG.md for $LATEST_TAG" + git push origin v${{ github.event.inputs.version }} + - name: Update installed chat-ai-widget version to latest under packages/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh pr create --title "chore(release): publish ${{ github.event.inputs.version }}" --body "created by automation" + packages=( "url-webdemo" "self-service" ) + for package in "${packages[@]}"; do + cd ./packages/$package + npm install @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 }} diff --git a/.github/workflows/pr-comment-bot.yml b/.github/workflows/pr-comment-bot.yml new file mode 100644 index 000000000..5e9090412 --- /dev/null +++ b/.github/workflows/pr-comment-bot.yml @@ -0,0 +1,19 @@ +name: PR comment bot +on: + issue_comment: + types: [created] +jobs: + pr-comment: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # see list of commands: https://github.com/sendbird/release-automation-action#commands + - uses: sendbird/release-automation-action@latest + with: + gh_token: ${{ secrets.GITHUB_TOKEN }} + circleci_token: ${{ secrets.CIRCLECI_API_TOKEN }} + product: 'chat-ai-widget' + platform: 'js' + framework: 'react' + product_jira_project_key: 'AC' + product_jira_version_prefix: 'js_chat_ai_widget' diff --git a/.github/workflows/release-ticket-creation.yml b/.github/workflows/release-ticket-creation.yml deleted file mode 100644 index 6847fa7b4..000000000 --- a/.github/workflows/release-ticket-creation.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Trigger Release Ticket Creation -on: - workflow_dispatch: - inputs: - branch_name: - description: 'Type a branch name starting with `release/v`' - required: true - push: - branches: - - 'feat/AC-1856' - -jobs: - trigger-release-ticket-creation: - name: Trigger release ticket creation - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Verify branch name - run: | - if [[ ! ${{ github.event.inputs.branch_name }} =~ ^release/v ]]; then - echo "Branch name should start with 'release/v'" - exit 1 - fi - - - name: Check if branch exists - id: check_branch - run: | - set -x - set -o pipefail - branch_name="${{ github.event.inputs.branch_name }}" - git ls-remote --exit-code --heads origin "$branch_name" | grep -q "$branch_name" - if [[ ${PIPESTATUS[1]} -eq 0 ]]; then - echo "BRANCH_EXISTS=true" >> $GITHUB_ENV - else - echo "BRANCH_EXISTS=false" >> $GITHUB_ENV - fi - - - name: Create branch if it doesn't exist - if: steps.check_branch.outputs.branch_exists == 1 - run: | - branch_name="${{ github.event.inputs.branch_name }}" - git checkout -b "$branch_name" - git push origin "$branch_name" - - - name: Trigger CircleCI Job - run: | - set -x - API_RESULT=$(curl --request POST \ - --url "https://circleci.com/api/v2/project/gh/${{ github.repository }}/pipeline" \ - --header "Circle-Token: ${{ secrets.CIRCLECI_API_TOKEN }}" \ - --header "content-type: application/json" \ - --data '{ - "branch": "${{ github.event.inputs.branch_name }}", - "parameters": { - "run_workflow_create_ticket": true - } - }') - echo "API_RESULT: ${API_RESULT}" - CIRCLE_CI_JOB_NUMBER=$(echo "${API_RESULT}" | jq -r '.number') - - if [[ $? -eq 0 ]]; then - HTTP_STATUS=$(echo "${API_RESULT}" | jq -r '.status') - - if [[ $HTTP_STATUS == "success" ]]; then - echo "CircleCI Job Triggered: $CIRCLE_CI_JOB_NUMBER" - echo "DEPLOY_COMMENT_BODY=https://app.circleci.com/pipelines/github/${{ github.repository }}/$CIRCLE_CI_JOB_NUMBER" >> $GITHUB_ENV - echo "JOB_STATUS=success" >> $GITHUB_OUTPUT - else - echo "CircleCI Job Trigger Failed" - echo "JOB_STATUS=failure" >> $GITHUB_OUTPUT - exit 1 - fi - else - echo "API request failed" - echo "JOB_STATUS=failure" >> $GITHUB_OUTPUT - exit 1 - fi