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
27 changes: 17 additions & 10 deletions .github/workflows/pr-build-and-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- release-*

jobs:
build:
Expand Down Expand Up @@ -48,8 +49,10 @@ jobs:
- name: Check for docs changes
id: docs-changes
working-directory: .
env:
BASE_REF: origin/${{ github.base_ref }}
run: |
DOCS_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/ | grep '\.md$' || true)
DOCS_CHANGED=$(git diff --name-only "$BASE_REF"...HEAD -- docs/ | grep '\.md$' || true)
if [ -z "$DOCS_CHANGED" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "No markdown changes in docs/"
Expand Down Expand Up @@ -99,8 +102,10 @@ jobs:

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

Expand All @@ -113,7 +118,7 @@ jobs:
;;
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)
OTHER_CHANGES=$(git diff "$BASE_REF"...HEAD -- package.json | grep -E '^[+-]\s' | grep -v -E '^\+\+\+|^---' | grep -v '"version"' || true)
if [ -n "$OTHER_CHANGES" ]; then
NEEDS_BUMP=true
break
Expand All @@ -126,32 +131,34 @@ jobs:

- name: Verify version bump and changelog
if: steps.changes.outputs.needs_bump == 'true'
env:
BASE_REF: origin/${{ github.base_ref }}
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")
BASE_VERSION=$(git show "$BASE_REF":package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version")

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

if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
if [ "$PR_VERSION" = "$BASE_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 [a, b] = ['$PR_VERSION', '$BASE_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)."
echo "::error::PR version ($PR_VERSION) must be higher than base version ($BASE_VERSION)."
exit 1
fi

echo "Version bumped from $MAIN_VERSION to $PR_VERSION"
echo "Version bumped from $BASE_VERSION to $PR_VERSION"

CHANGELOG_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/changelog.md)
CHANGELOG_CHANGED=$(git diff --name-only "$BASE_REF"...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
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- release-*
paths:
- "package.json"
workflow_dispatch:
Expand All @@ -14,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.version-check.outputs.should_publish }}
npm_tag: ${{ steps.version-check.outputs.npm_tag }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand All @@ -22,17 +24,31 @@ jobs:
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")
BRANCH="${GITHUB_REF#refs/heads/}"

if [[ "$BRANCH" != "main" && "$BRANCH" != release-* ]]; then
echo "::error::Publishing is only allowed from main or release-* branches (got: $BRANCH)"
exit 1
fi

if [[ "$BRANCH" == release-* ]]; then
NPM_TAG="${BRANCH#release-}"
PUBLISHED_VERSION=$(npm view @red-hat-developer-hub/e2e-test-utils version --tag "$NPM_TAG" 2>/dev/null || echo "0.0.0")
else
NPM_TAG="latest"
PUBLISHED_VERSION=$(npm view @red-hat-developer-hub/e2e-test-utils version 2>/dev/null || echo "0.0.0")
fi

echo "Current version: $CURRENT_VERSION"
echo "Published version: $PUBLISHED_VERSION"
echo "Published version ($NPM_TAG): $PUBLISHED_VERSION"
echo "npm_tag=$NPM_TAG" >> "$GITHUB_OUTPUT"

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."
echo "New version $CURRENT_VERSION will be published (tag: $NPM_TAG)."
fi

publish:
Expand Down Expand Up @@ -65,7 +81,8 @@ jobs:
run: yarn config set npmPublishRegistry "https://registry.npmjs.org"

- name: Publish
run: yarn npm publish
run: yarn npm publish --tag "$NPM_TAG"
env:
NPM_TAG: ${{ needs.check-version.outputs.npm_tag }}
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
Loading