Merge pull request #16 from NandhakumarE/develop #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Release Workflow | |
| # | |
| # Pipeline: test → build → version → publish (sequential) | |
| # ↓ | |
| # update-changelog | create-tag-release | deploy-storybook (parallel) | |
| # ↓ | |
| # notify (failure summary) | |
| # | |
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # ───────────────────────────────────────────────────────── | |
| # Job 1: Sequential core — test → build → version → publish | |
| # ───────────────────────────────────────────────────────── | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| outputs: | |
| version: ${{ steps.pkg.outputs.version }} | |
| has_changesets: ${{ steps.changesets.outputs.has_changesets }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test -- --run | |
| - name: Build package | |
| run: npm run build | |
| - name: Check changesets | |
| id: changesets | |
| run: | | |
| CHANGESET_FILE=$(find .changeset -name "*.md" ! -name "README.md" 2>/dev/null | head -1) | |
| if [ -z "$CHANGESET_FILE" ]; then | |
| echo "has_changesets=false" >> $GITHUB_OUTPUT | |
| echo "⚠️ No changesets found — skipping release" | |
| else | |
| echo "has_changesets=true" >> $GITHUB_OUTPUT | |
| echo "✅ Changeset found: $CHANGESET_FILE" | |
| fi | |
| - name: Version packages | |
| if: steps.changesets.outputs.has_changesets == 'true' | |
| run: npx changeset version | |
| - name: Get package version | |
| if: steps.changesets.outputs.has_changesets == 'true' | |
| id: pkg | |
| run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Publish to npm | |
| if: steps.changesets.outputs.has_changesets == 'true' | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Skip publish (no changesets) | |
| if: steps.changesets.outputs.has_changesets == 'false' | |
| run: | | |
| echo "────────────────────────────────────────────────" | |
| echo " No changesets found - skipping release" | |
| echo "" | |
| echo "To publish a new version:" | |
| echo " 1. Run: npx changeset" | |
| echo " 2. Commit the .md file" | |
| echo " 3. Merge to main" | |
| echo "────────────────────────────────────────────────" | |
| # ───────────────────────────────────────────────────────── | |
| # Job 2: Commit version bump + CHANGELOG + consumed changesets | |
| # ───────────────────────────────────────────────────────── | |
| update-changelog: | |
| needs: release | |
| if: needs.release.outputs.has_changesets == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Version packages (reproduce changes) | |
| run: npx changeset version | |
| - name: Commit and push | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "chore: release v${{ needs.release.outputs.version }}" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ───────────────────────────────────────────────────────── | |
| # Job 3: Create git tag + GitHub Release | |
| # ───────────────────────────────────────────────────────── | |
| create-tag-release: | |
| needs: release | |
| if: needs.release.outputs.has_changesets == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Create git tag | |
| run: | | |
| git tag v${{ needs.release.outputs.version }} | |
| git push origin v${{ needs.release.outputs.version }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ needs.release.outputs.version }} | |
| name: v${{ needs.release.outputs.version }} | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ───────────────────────────────────────────────────────── | |
| # Job 4: Build and deploy Storybook to GitHub Pages | |
| # ───────────────────────────────────────────────────────── | |
| deploy-storybook: | |
| needs: release | |
| if: needs.release.outputs.has_changesets == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build Storybook | |
| run: npm run build-storybook | |
| env: | |
| STORYBOOK_BASE: /react-querybuilder-lite/ | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: "./storybook-static" | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| # ───────────────────────────────────────────────────────── | |
| # Job 5: Failure notification | |
| # ───────────────────────────────────────────────────────── | |
| notify: | |
| needs: [update-changelog, create-tag-release, deploy-storybook] | |
| if: >- | |
| always() && | |
| !(needs.update-changelog.result == 'skipped' && | |
| needs.create-tag-release.result == 'skipped' && | |
| needs.deploy-storybook.result == 'skipped') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check for failures | |
| run: | | |
| echo "## Post-publish job results" | |
| echo "- update-changelog: ${{ needs.update-changelog.result }}" | |
| echo "- create-tag-release: ${{ needs.create-tag-release.result }}" | |
| echo "- deploy-storybook: ${{ needs.deploy-storybook.result }}" | |
| FAILED=false | |
| if [ "${{ needs.update-changelog.result }}" = "failure" ]; then FAILED=true; fi | |
| if [ "${{ needs.create-tag-release.result }}" = "failure" ]; then FAILED=true; fi | |
| if [ "${{ needs.deploy-storybook.result }}" = "failure" ]; then FAILED=true; fi | |
| if [ "$FAILED" = "true" ]; then | |
| echo "" | |
| echo "❌ One or more post-publish jobs failed. Check the logs above." | |
| exit 1 | |
| else | |
| echo "" | |
| echo "✅ All post-publish jobs succeeded." | |
| fi |