Skip to content

Commit 870eb6b

Browse files
fix: release pipeline (#1947)
Signed-off-by: Shurtu-gal <ashishpadhy1729@gmail.com> Co-authored-by: Chan <bot+chan@asyncapi.io>
1 parent 74109c6 commit 870eb6b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.github/workflows/release-with-changesets.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
# "commits" contains an array of objects where one of the properties is the commit "message"
2020
# Release workflow will be skipped if release conventional commits are not used
2121
if: |
22-
startsWith( github.repository, 'asyncapi/' ) &&
2322
(startsWith( github.event.commits[0].message , 'fix:' ) ||
2423
startsWith( github.event.commits[0].message, 'fix!:' ) ||
2524
startsWith( github.event.commits[0].message, 'feat:' ) ||
@@ -117,21 +116,37 @@ jobs:
117116
- if: steps.packagejson.outputs.exists == 'true'
118117
name: Publish to any of NPM, Github, and Docker Hub
119118
#this step has 2 goals, it is either identifying that there is changeset file created and then this action creates a PR with version bump that will trigger release - or if it sees there is no changeset, and there are versions changes in package.json files, it publish new versions to NPM is they are not there yet
119+
# However, as currently changeset's publish isn't working well with OIDC next step will directly publish to NPM if there are version changes but no changesets
120120
uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3
121121
id: release
122122
with:
123123
version: npm run bump:version
124124
commit: "chore(release): release and bump versions of packages"
125125
title: "chore(release): release and bump versions of packages"
126-
publish: npx -p @changesets/cli@2.27.7 changeset publish
126+
# Working around changesets action not supporting OIDC yet. Need to pass successful release output for triggering github release
127+
publish: npm run publish:trusted
127128
setupGitUser: false
128129
env:
129-
NPM_TOKEN: ''
130130
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
131131
GIT_AUTHOR_NAME: asyncapi-bot
132132
GIT_AUTHOR_EMAIL: info@asyncapi.io
133133
GIT_COMMITTER_NAME: asyncapi-bot
134134
GIT_COMMITTER_EMAIL: info@asyncapi.io
135+
136+
- name: Publish to NPM directly (skip if version already published)
137+
if: steps.packagejson.outputs.exists == 'true' && steps.release.outputs.hasChangesets == 'false'
138+
shell: bash
139+
run: |
140+
# Check if the version in package.json is already published
141+
VERSION=$(node -p "require('./package.json').version")
142+
PACKAGE_NAME=$(node -p "require('./package.json').name")
143+
if npm view "$PACKAGE_NAME@$VERSION" > /dev/null 2>&1; then
144+
echo "Version $VERSION of package $PACKAGE_NAME is already published. Skipping publish."
145+
else
146+
echo "Publishing version $VERSION of package $PACKAGE_NAME to NPM."
147+
npm publish --provenance
148+
fi
149+
135150
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci Slack channel
136151
name: Report workflow run status to Slack
137152
uses: 8398a7/action-slack@fbd6aa58ba854a740e11a35d0df80cb5d12101d8 # v3.15.1

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
"pack:tarballs:alpine": "oclif pack tarballs -t linux-x64 && npm run pack:rename alpine",
179179
"pack:windows": "oclif pack win && npm run pack:rename",
180180
"pack:rename": "node scripts/releasePackagesRename.js",
181+
"publish:trusted": "echo \"Working around changesets action not supporting OIDC yet. Need to pass successful release output for triggering github release\";VERSION=$(node -p \"require('./package.json').version\"); PACKAGE_NAME=$(node -p \"require('./package.json').name\"); if npm view $PACKAGE_NAME@$VERSION > /dev/null 2>&1; then echo \"Version $VERSION of package $PACKAGE_NAME already published to NPM. Skipping GitHub release.\"; else git tag v$VERSION -m v$VERSION; echo \"New tag: $PACKAGE_NAME@$VERSION.\"; fi",
181182
"prepublishOnly": "npm run build",
182183
"pretest": "npm run build",
183184
"pretest:coverage": "npm run build",

0 commit comments

Comments
 (0)