Skip to content

fix: fetch default.packages.yaml from rhdh-plugin-export-overlays for… #60

fix: fetch default.packages.yaml from rhdh-plugin-export-overlays for…

fix: fetch default.packages.yaml from rhdh-plugin-export-overlays for… #60

Workflow file for this run

name: Publish package to NPM
on:
push:
branches:
- main
- release-*
paths:
- "package.json"
workflow_dispatch:
jobs:
check-version:
name: Check Version
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
- name: Check if version changed
id: version-check
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
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 ($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 (tag: $NPM_TAG)."
fi
publish:
name: Publish to NPM
needs: check-version
if: needs.check-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
registry-url: "https://registry.npmjs.org"
node-version: "22"
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: yarn install --immutable
- name: Build
run: yarn build
- name: Configure npm registry
run: yarn config set npmPublishRegistry "https://registry.npmjs.org"
- name: 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 }}