Skip to content
Merged
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
70 changes: 70 additions & 0 deletions .github/workflows/pr-build-and-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,73 @@ jobs:

- name: Run Tests
run: yarn test

version-check:
name: Version Bump Check
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for source changes requiring version bump
id: changes
run: |
CHANGED_FILES=$(git diff --name-only origin/main...HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"

NEEDS_BUMP=false
while IFS= read -r file; do
case "$file" in
src/*|tsconfig.build.json|tsconfig.base.json)
NEEDS_BUMP=true
break
;;
package.json)
# Check if anything other than "version" changed
OTHER_CHANGES=$(git diff origin/main...HEAD -- package.json | grep -E '^[+-]\s' | grep -v -E '^\+\+\+|^---' | grep -v '"version"' || true)
if [ -n "$OTHER_CHANGES" ]; then
NEEDS_BUMP=true
break
fi
;;
esac
done <<< "$CHANGED_FILES"

echo "needs_bump=$NEEDS_BUMP" >> "$GITHUB_OUTPUT"

- name: Verify version bump and changelog
if: steps.changes.outputs.needs_bump == 'true'
run: |
PR_VERSION=$(node -p "require('./package.json').version")
MAIN_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version")

echo "Main version: $MAIN_VERSION"
echo "PR version: $PR_VERSION"

if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
echo "::error::Source files or dependencies changed but package version was not bumped. Please update the version in package.json."
exit 1
fi

HIGHER=$(node -e "
const [a, b] = ['$PR_VERSION', '$MAIN_VERSION'].map(v => v.split('.').map(Number));
const isHigher = a[0] > b[0] || (a[0] === b[0] && a[1] > b[1]) || (a[0] === b[0] && a[1] === b[1] && a[2] > b[2]);
process.exit(isHigher ? 0 : 1);
" && echo "true" || echo "false")

if [ "$HIGHER" != "true" ]; then
echo "::error::PR version ($PR_VERSION) must be higher than main version ($MAIN_VERSION)."
exit 1
fi

echo "Version bumped from $MAIN_VERSION to $PR_VERSION"

CHANGELOG_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/changelog.md)
if [ -z "$CHANGELOG_CHANGED" ]; then
echo "::error::Version was bumped but docs/changelog.md was not updated. Please add a changelog entry for version $PR_VERSION."
exit 1
fi
echo "Changelog updated for version bump"
33 changes: 33 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
name: Publish package to NPM

on:
push:
branches:
- main
paths:
- "package.json"
workflow_dispatch:

jobs:
check-version:
name: Check Version
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.version-check.outputs.should_publish }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Check if version changed
id: version-check
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
PUBLISHED_VERSION=$(npm view @red-hat-developer-hub/e2e-test-utils version 2>/dev/null || echo "0.0.0")

echo "Current version: $CURRENT_VERSION"
echo "Published version: $PUBLISHED_VERSION"

if [ "$CURRENT_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "Version $CURRENT_VERSION is already published. Skipping."
else
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "New version $CURRENT_VERSION will be published."
fi

publish:
name: Publish to NPM
needs: check-version
if: needs.check-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
Loading