From 14d6da854314f4001a8a55047fb808aadc88e819 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:26:57 +0530 Subject: [PATCH 1/2] ci: add changeset automatically Signed-off-by: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> --- .github/workflows/auto-changeset.yml | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/auto-changeset.yml diff --git a/.github/workflows/auto-changeset.yml b/.github/workflows/auto-changeset.yml new file mode 100644 index 00000000000..67806fc33d9 --- /dev/null +++ b/.github/workflows/auto-changeset.yml @@ -0,0 +1,58 @@ +name: Add changeset automatically + +on: + pull_request_target: + types: + - opened + - edited + +# startsWith(github.repository, 'asyncapi/') && +jobs: + auto-changeset: + if: | + ( startsWith(github.event.pull_request.title, 'fix:') || + startsWith(github.event.pull_request.title, 'feat:') || + startsWith(github.event.pull_request.title, 'fix!:') || + startsWith(github.event.pull_request.title, 'feat!:') + ) + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_TOKEN }} + - name: Checkout PR + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + run: gh pr checkout ${{ github.event.pull_request.number }} + - name: Determine release type + id: determine_release_type + uses: actions/github-script@v7 + with: + script: | + const title = context.payload.pull_request.title; + const releaseType = title.split(':')[0]; + switch (releaseType) { + case 'fix': + return 'patch'; + case 'feat': + return 'minor'; + case 'fix!': + return 'major'; + case 'feat!': + return 'major'; + default: + return 'patch'; + } + - name: Create changeset file + run: "echo -e '---\n'@asyncapi/cli': ${{ steps.determine_release_type.outputs.result }}\n---\n\n ${{ github.event.pull_request.title }}\n\n' > .changeset/${{ github.event.pull_request.number }}.md" + - name: Commit changeset file + run: | + git config --global user.email "info@asyncapi.com" + git config --global user.name "asyncapi-bot" + git add .changeset/${{ github.event.pull_request.number }}.md + git commit -m "chore: add changeset for PR #${{ github.event.pull_request.number }}" + # - name: Debug event + # run: echo ${{ toJson(github.event) }} + - name: Push changeset file + run: git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }} HEAD:${{ github.event.pull_request.head.ref }} \ No newline at end of file From 5131c8a676f45a0e930eff273f1ade72e4c6618b Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:38:42 +0530 Subject: [PATCH 2/2] chore: clean up and slack clean up message Signed-off-by: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> --- .github/workflows/auto-changeset.yml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/auto-changeset.yml b/.github/workflows/auto-changeset.yml index 67806fc33d9..9a164c3eaa7 100644 --- a/.github/workflows/auto-changeset.yml +++ b/.github/workflows/auto-changeset.yml @@ -6,10 +6,10 @@ on: - opened - edited -# startsWith(github.repository, 'asyncapi/') && jobs: auto-changeset: if: | + startsWith(github.repository, 'asyncapi/') && ( startsWith(github.event.pull_request.title, 'fix:') || startsWith(github.event.pull_request.title, 'feat:') || startsWith(github.event.pull_request.title, 'fix!:') || @@ -21,10 +21,12 @@ jobs: uses: actions/checkout@v4 with: token: ${{ secrets.GH_TOKEN }} + - name: Checkout PR env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} run: gh pr checkout ${{ github.event.pull_request.number }} + - name: Determine release type id: determine_release_type uses: actions/github-script@v7 @@ -44,15 +46,27 @@ jobs: default: return 'patch'; } + - name: Create changeset file - run: "echo -e '---\n'@asyncapi/cli': ${{ steps.determine_release_type.outputs.result }}\n---\n\n ${{ github.event.pull_request.title }}\n\n' > .changeset/${{ github.event.pull_request.number }}.md" + run: "echo -e '---\n'@asyncapi/cli': ${{ steps.determine_release_type.outputs.result }}\n---\n\n ${{ github.event.pull_request.title }}\n' > .changeset/${{ github.event.pull_request.number }}.md" + - name: Commit changeset file run: | - git config --global user.email "info@asyncapi.com" - git config --global user.name "asyncapi-bot" + git config --global user.name asyncapi-bot + git config --global user.email info@asyncapi.io git add .changeset/${{ github.event.pull_request.number }}.md git commit -m "chore: add changeset for PR #${{ github.event.pull_request.number }}" - # - name: Debug event - # run: echo ${{ toJson(github.event) }} + - name: Push changeset file - run: git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }} HEAD:${{ github.event.pull_request.head.ref }} \ No newline at end of file + run: git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }} HEAD:${{ github.event.pull_request.head.ref }} + + # Only, on failure, send a message on the 94_bot-failing-ci slack channel + - if: failure() + name: Report workflow run status to Slack + uses: 8398a7/action-slack@fbd6aa58ba854a740e11a35d0df80cb5d12101d8 #using https://github.com/8398a7/action-slack/releases/tag/v3.15.1 + with: + status: ${{ job.status }} + fields: repo,action,workflow + text: 'AsyncAPI CLI release to Chocolatey failed' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} \ No newline at end of file