Skip to content

Commit b6a70b6

Browse files
committed
Implement skipping when there are no changes without failing CI
1 parent c10ddc6 commit b6a70b6

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

.github/workflows/publish-libs.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ jobs:
141141

142142
if: ${{ needs.check-publish.outputs.can-publish == '1' }}
143143

144+
outputs:
145+
should_publish: ${{ steps.detect.outputs.should_publish }}
146+
144147
steps:
145148
- uses: actions/checkout@v6
146149
with:
@@ -163,10 +166,16 @@ jobs:
163166
yarn build
164167
env:
165168
CI: true
166-
- name: Check for changes and bump versions (scheduled builds only)
167-
if: ${{ github.event_name == 'schedule' }}
169+
- name: Decide whether to publish (scheduled builds may skip)
170+
id: detect
168171
run: |
169172
cd packages
173+
174+
# Default: publish for non-scheduled events
175+
if [ "${{ github.event_name }}" != "schedule" ]; then
176+
echo "should_publish=1" >> $GITHUB_OUTPUT
177+
exit 0
178+
fi
170179
171180
# Check each package for changes
172181
PACKAGES="blueprints-integration server-core-integration shared-lib live-status-gateway-api openapi"
@@ -203,7 +212,7 @@ jobs:
203212
204213
# Compute current dist hash for this package
205214
if [ -d "$PKG/dist" ]; then
206-
CURRENT_DIST_HASH=$(find "$PKG/dist" -type f | sort | xargs cat | sha256sum | cut -c1-8)
215+
CURRENT_DIST_HASH=$(find "$PKG/dist" -type f -print0 | sort -z | xargs -0 cat | sha256sum | cut -c1-8)
207216
else
208217
echo "📦 **$PKG**: No dist folder, will publish" >> $GITHUB_STEP_SUMMARY
209218
HAS_ANY_CHANGES=1
@@ -221,14 +230,16 @@ jobs:
221230
echo "" >> $GITHUB_STEP_SUMMARY
222231
if [ $HAS_ANY_CHANGES -eq 0 ]; then
223232
echo "**Result**: No packages changed, skipping publish" >> $GITHUB_STEP_SUMMARY
224-
exit 1 # Fail the step to stop the workflow
233+
echo "should_publish=0" >> $GITHUB_OUTPUT
234+
exit 0
225235
fi
226236
227237
echo "**Result**: Will publish changed packages" >> $GITHUB_STEP_SUMMARY
238+
echo "should_publish=1" >> $GITHUB_OUTPUT
228239
env:
229240
CI: true
230241
- name: Bump version with per-package dist hashes
231-
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
242+
if: ${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && steps.detect.outputs.should_publish == '1' }}
232243
run: |
233244
cd packages
234245
COMMIT_TIMESTAMP=$(git log -1 --pretty=format:%ct HEAD)
@@ -243,7 +254,7 @@ jobs:
243254
for PKG_DIR in blueprints-integration server-core-integration shared-lib live-status-gateway-api openapi; do
244255
if [ -d "$PKG_DIR/dist" ]; then
245256
# Compute dist hash for this specific package
246-
DIST_HASH=$(find "$PKG_DIR/dist" -type f | sort | xargs cat | sha256sum | cut -c1-8)
257+
DIST_HASH=$(find "$PKG_DIR/dist" -type f -print0 | sort -z | xargs -0 cat | sha256sum | cut -c1-8)
247258
248259
# Get current version from package.json
249260
CURRENT_VERSION=$(node -p "require('./$PKG_DIR/package.json').version")
@@ -284,19 +295,22 @@ jobs:
284295
CI: true
285296

286297
- name: Build OpenAPI client library
298+
if: ${{ github.event_name != 'schedule' || steps.detect.outputs.should_publish == '1' }}
287299
run: |
288300
cd packages/openapi
289301
yarn build
290302
env:
291303
CI: true
292304
- name: Modify dependencies to use npm packages
305+
if: ${{ github.event_name != 'schedule' || steps.detect.outputs.should_publish == '1' }}
293306
run: |
294307
node scripts/prepublish.js "${{ github.repository }}" "${{ env.NPM_PACKAGE_SCOPE }}" ${{ env.NPM_PACKAGE_PREFIX }}
295308
296309
cd packages
297310
yarn install --no-immutable
298311
299312
- name: Upload release artifact
313+
if: ${{ github.event_name != 'schedule' || steps.detect.outputs.should_publish == '1' }}
300314
uses: actions/upload-artifact@v5
301315
with:
302316
name: publish-dist
@@ -317,6 +331,8 @@ jobs:
317331
- prepare-publish
318332
- test-packages
319333

334+
if: ${{ github.event_name != 'schedule' || needs.prepare-publish.outputs.should_publish == '1' }}
335+
320336
permissions:
321337
contents: write
322338
id-token: write # scoped for as short as possible, as this gives write access to npm

0 commit comments

Comments
 (0)