Skip to content
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

feat: add GitHub action for releasing via Changeset #1029

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"privatePackages": {
"version": true,
"tag": true
}
}
141 changes: 141 additions & 0 deletions .github/workflows/release-with-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# This action is centrally managed in https://github.com/asyncapi/.github/
Copy link
Member

@smoya smoya Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not centrally managed yet. Please remove the comment. We can add it once this is moved into .github repo

Suggested change
# This action is centrally managed in https://github.com/asyncapi/.github/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in the above-mentioned repo

# It does magic only if there is a package.json file in the root of the project
name: Release with changeset

on:
push:
branches:
- master
# The below lines are not enough to have release supported for these branches
# Make sure the configuration of the `semantic-release` package mentions these branches
Comment on lines +11 to +12
Copy link
Member

@smoya smoya Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use semantic-release anymore (and projects that will use this workflow won't use it either) so this comment should be removed.

Suggested change
# The below lines are not enough to have release supported for these branches
# Make sure the configuration of the `semantic-release` package mentions these branches

- next-spec
- next-major
- next-major-spec
- beta
- alpha
- next
Comment on lines +13 to +18
Copy link
Member

@smoya smoya Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need anything else to be configured (perhaps in changeset config file?) to allow those branches to be released as well? How does it work?

cc @derberg @KhudaDad414

Copy link
Member

@smoya smoya Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out this in their docs: https://github.com/changesets/changesets/blob/main/docs/prereleases.md

It should be done manually it seems. I guess in the workflow, detecting we are not in master branch and run npx changeset pre enter {tag} then. More investigation is needed.

We can work on it in a second iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure will do that.


jobs:
test-nodejs:
# We just check the message of the first commit as there is always just one commit because we squash into one before merging
# "commits" contains an array of objects where one of the properties is the commit "message"
# Release workflow will be skipped if release conventional commits are not used
if: |
startsWith(github.repository, 'asyncapi/') &&
(startsWith(github.event.commits[0].message, 'fix:') ||
startsWith(github.event.commits[0].message, 'fix!:') ||
startsWith(github.event.commits[0].message, 'feat:') ||
startsWith(github.event.commits[0].message, 'feat!:'))
name: Test NodeJS release on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Using macos-13 instead of latest (macos-14) due to an issue with Puppeteer and such runner.
# See: https://github.com/puppeteer/puppeteer/issues/12327 and https://github.com/asyncapi/parser-js/issues/1001
os: [ubuntu-latest, macos-13, windows-latest]
steps:
- name: Set git to use LF # To once and for all finish the never-ending fight between Unix and Windows
run: |
git config --global core.autocrlf false
git config --global core.eol lf
shell: bash
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if Node.js project and has package.json
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
shell: bash
- if: steps.packagejson.outputs.exists == 'true'
name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "${{ steps.lockversion.outputs.version }}"
- if: steps.lockversion.outputs.version == '18' && matrix.os == 'windows-latest'
name: Install npm cli 8
shell: bash
# npm cli 10 is buggy because of some cache issues
run: npm install -g [email protected]
- if: steps.packagejson.outputs.exists == 'true'
name: Install dependencies
shell: bash
run: npm ci
- if: steps.packagejson.outputs.exists == 'true'
name: Run test
run: npm test --if-present
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci Slack channel
name: Report workflow run status to Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,action,workflow
text: "Release workflow failed in testing job"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}

release:
needs: [test-nodejs]
name: Publish to any of NPM, GitHub, or Docker Hub
runs-on: ubuntu-latest
steps:
- name: Set git to use LF # To once and for all finish the never-ending fight between Unix and Windows
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if Node.js project and has package.json
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
shell: bash
- if: steps.packagejson.outputs.exists == 'true'
name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "${{ steps.lockversion.outputs.version }}"
- if: steps.packagejson.outputs.exists == 'true'
name: Install dependencies
shell: bash
run: npm ci
- if: steps.packagejson.outputs.exists == 'true'
name: Install Changesets
run: npm install --save-dev @changesets/[email protected]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it still needed if in the end you call below npx ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok removed we should add this like we do for semantic release.


- if: steps.packagejson.outputs.exists == 'true'
name: Create Release Pull Request or Release
uses: changesets/action@v1
- if: steps.packagejson.outputs.exists == 'true'
name: Publish to any of NPM, Github, and Docker Hub
id: release
with:
publish: npx turbo run build && npx changeset publish
version: npx changeset version
Comment on lines +120 to +121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do not specify the version, npx will always pick up latest - which in future will kick maintainers big time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok now added the version.

commit: "version packages"
title: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GIT_AUTHOR_NAME: asyncapi-bot
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: [email protected]
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci Slack channel
name: Report workflow run status to Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,action,workflow
text: "Release workflow failed in release job"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}
Loading
Loading