66 push :
77 tags :
88 - " v**"
9+ schedule :
10+ # Run nightly at 1 AM UTC
11+ - cron : ' 0 1 * * *'
912
1013permissions :
1114 contents : read
@@ -154,8 +157,78 @@ jobs:
154157 yarn install
155158 env :
156159 CI : true
157- - name : Bump version
158- if : ${{ github.event_name == 'workflow_dispatch' }}
160+ - name : Build
161+ run : |
162+ cd packages
163+ yarn build
164+ env :
165+ CI : true
166+ - name : Check for changes and bump versions (scheduled builds only)
167+ if : ${{ github.event_name == 'schedule' }}
168+ run : |
169+ cd packages
170+
171+ # Check each package for changes
172+ PACKAGES="blueprints-integration server-core-integration shared-lib live-status-gateway-api openapi"
173+ HAS_ANY_CHANGES=0
174+
175+ echo "## Package Change Detection" >> $GITHUB_STEP_SUMMARY
176+ echo "" >> $GITHUB_STEP_SUMMARY
177+
178+ for PKG in $PACKAGES; do
179+ # Get current package name
180+ if [ "${{ env.IS_UPSTREAM }}" = "true" ]; then
181+ PACKAGE_NAME="@sofie-automation/$PKG"
182+ else
183+ PACKAGE_NAME="@${{ env.NPM_PACKAGE_SCOPE }}/${{ env.NPM_PACKAGE_PREFIX }}$PKG"
184+ fi
185+
186+ # Get latest nightly version from npm
187+ LATEST_NIGHTLY=$(npm view $PACKAGE_NAME dist-tags.nightly 2>/dev/null || echo "")
188+
189+ if [ -z "$LATEST_NIGHTLY" ]; then
190+ echo "📦 **$PKG**: No nightly found, will publish" >> $GITHUB_STEP_SUMMARY
191+ HAS_ANY_CHANGES=1
192+ continue
193+ fi
194+
195+ # Extract dist hash from version (format: X.Y.Z-nightly-branch-YYYYMMDD-HHMMSS-githash-disthash)
196+ LAST_DIST_HASH=$(echo "$LATEST_NIGHTLY" | grep -oP '[0-9a-f]{8}$' || echo "")
197+
198+ if [ -z "$LAST_DIST_HASH" ]; then
199+ echo "📦 **$PKG**: Old version format ($LATEST_NIGHTLY), will publish" >> $GITHUB_STEP_SUMMARY
200+ HAS_ANY_CHANGES=1
201+ continue
202+ fi
203+
204+ # Compute current dist hash for this package
205+ if [ -d "$PKG/dist" ]; then
206+ CURRENT_DIST_HASH=$(find "$PKG/dist" -type f | sort | xargs cat | sha256sum | cut -c1-8)
207+ else
208+ echo "📦 **$PKG**: No dist folder, will publish" >> $GITHUB_STEP_SUMMARY
209+ HAS_ANY_CHANGES=1
210+ continue
211+ fi
212+
213+ if [ "$LAST_DIST_HASH" = "$CURRENT_DIST_HASH" ]; then
214+ echo "✅ **$PKG**: No changes ($CURRENT_DIST_HASH)" >> $GITHUB_STEP_SUMMARY
215+ else
216+ echo "📦 **$PKG**: Changed ($LAST_DIST_HASH → $CURRENT_DIST_HASH)" >> $GITHUB_STEP_SUMMARY
217+ HAS_ANY_CHANGES=1
218+ fi
219+ done
220+
221+ echo "" >> $GITHUB_STEP_SUMMARY
222+ if [ $HAS_ANY_CHANGES -eq 0 ]; then
223+ echo "**Result**: No packages changed, skipping publish" >> $GITHUB_STEP_SUMMARY
224+ exit 1 # Fail the step to stop the workflow
225+ fi
226+
227+ echo "**Result**: Will publish changed packages" >> $GITHUB_STEP_SUMMARY
228+ env :
229+ CI : true
230+ - name : Bump version with per-package dist hashes
231+ if : ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
159232 run : |
160233 cd packages
161234 COMMIT_TIMESTAMP=$(git log -1 --pretty=format:%ct HEAD)
@@ -166,13 +239,50 @@ jobs:
166239 git config --global user.email "[email protected] " 167240 git config --global user.name "superflytvab"
168241
169- yarn set-version-and-commit prerelease --preid $PRERELEASE_TAG-$COMMIT_DATE-$GIT_HASH
170- env :
171- CI : true
172- - name : Build
173- run : |
174- cd packages
175- yarn build
242+ # Update each package version with its own dist hash
243+ for PKG_DIR in blueprints-integration server-core-integration shared-lib live-status-gateway-api openapi; do
244+ if [ -d "$PKG_DIR/dist" ]; then
245+ # Compute dist hash for this specific package
246+ DIST_HASH=$(find "$PKG_DIR/dist" -type f | sort | xargs cat | sha256sum | cut -c1-8)
247+
248+ # Get current version from package.json
249+ CURRENT_VERSION=$(node -p "require('./$PKG_DIR/package.json').version")
250+
251+ # Compute new prerelease version
252+ NEW_VERSION=$(node -e "
253+ const semver = require('semver');
254+ const current = '$CURRENT_VERSION';
255+ const parsed = semver.parse(current);
256+ const newVersion = \`\${parsed.major}.\${parsed.minor}.\${parsed.patch}-$PRERELEASE_TAG-$COMMIT_DATE-$GIT_HASH-$DIST_HASH\`;
257+ console.log(newVersion);
258+ ")
259+
260+ # Update package.json
261+ node -e "
262+ const fs = require('fs');
263+ const path = './$PKG_DIR/package.json';
264+ const pkg = JSON.parse(fs.readFileSync(path, 'utf8'));
265+ pkg.version = '$NEW_VERSION';
266+ fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n');
267+ "
268+
269+ echo "Updated $PKG_DIR to $NEW_VERSION"
270+ fi
271+ done
272+
273+ # Also update lerna.json with a representative version (use blueprints-integration)
274+ if [ -f "blueprints-integration/package.json" ]; then
275+ LERNA_VERSION=$(node -p "require('./blueprints-integration/package.json').version")
276+ node -e "
277+ const fs = require('fs');
278+ const lerna = JSON.parse(fs.readFileSync('./lerna.json', 'utf8'));
279+ lerna.version = '$LERNA_VERSION';
280+ fs.writeFileSync('./lerna.json', JSON.stringify(lerna, null, 2) + '\n');
281+ "
282+ fi
283+
284+ git add .
285+ git commit -m "chore: bump versions for nightly" --no-verify --allow-empty
176286 env :
177287 CI : true
178288
@@ -256,7 +366,7 @@ jobs:
256366 yarn install
257367
258368 NPM_TAG=nightly
259- if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
369+ if [ "${{ github.event_name }}" != "workflow_dispatch" ] && [ "${{ github.event_name }}" != "schedule" ] ; then
260370 PACKAGE_NAME=$(node -p "require('./shared-lib/package.json').name")
261371 PUBLISHED_VERSION=$(yarn npm info --json $PACKAGE_NAME | jq -c '.version' -r)
262372 THIS_VERSION=$(node -p "require('./lerna.json').version")
0 commit comments