-
-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: add changeset automation #1653
base: master
Are you sure you want to change the base?
Changes from all commits
14d6da8
5131c8a
5c1e4f4
4d5ed19
11f4905
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Add changeset automatically | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- edited | ||
|
||
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!:') || | ||
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' > .changeset/${{ github.event.pull_request.number }}.md" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you sure you wanna hardcode this way? to cli, knowing there will be more projects in repo in future? maybe try changeset cli with I strongly suggest, such a generated changeset has a large multiline comment with info that it is generated and should be manually reviewed. Cause is the end, I don't know if without human we are able to make a decision what package should be released 🤔 also we probably should drop some comment in the PR, that both created Changeset and that it must be reviewed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly |
||
|
||
- name: Commit changeset file | ||
run: | | ||
git config --global user.name asyncapi-bot | ||
git config --global user.email [email protected] | ||
git add .changeset/${{ github.event.pull_request.number }}.md | ||
git commit -m "chore: add changeset for PR #${{ github.event.pull_request.number }}" | ||
|
||
- 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 }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check with chatgpt but I think for security reasons better not pash secrets this way - maybe they annonymize secrets in logs, but yeah if better to be secure and add one more line to configure token with |
||
|
||
# Only, on failure, send a message on the 94_bot-failing-ci slack channel | ||
- if: failure() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case to workflows running on PR I don't think we need to drop errors to slack - this is going to be visible in the CI status at the bottom of PR |
||
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 }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should probably trigger it on all events
types: [opened, reopened, synchronize, edited, ready_for_review]