|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + pull_request: |
| 8 | + types: [labeled, synchronize] |
| 9 | + branches: [main] |
7 | 10 |
|
8 | 11 | concurrency: |
9 | 12 | group: ${{ github.workflow }}-${{ github.ref }} |
10 | 13 | cancel-in-progress: true |
11 | 14 |
|
12 | 15 | jobs: |
13 | | - publish-datum-ui: |
| 16 | + # Stable publish on push to main (reusable workflow) |
| 17 | + publish: |
| 18 | + if: github.event_name == 'push' |
14 | 19 | uses: datum-cloud/actions/.github/workflows/publish-npm-package.yaml@main |
15 | 20 | permissions: |
16 | 21 | contents: write |
17 | 22 | id-token: write |
18 | | - |
19 | 23 | with: |
20 | 24 | package-name: "@datum-cloud/datum-ui" |
21 | 25 | package-path: packages/datum-ui |
| 26 | + |
| 27 | + # Alpha publish on PR with 'alpha' label |
| 28 | + alpha: |
| 29 | + name: Publish alpha |
| 30 | + if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'alpha') |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + id-token: write |
| 35 | + pull-requests: write |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout PR branch |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + ref: ${{ github.event.pull_request.head.sha }} |
| 42 | + |
| 43 | + - uses: pnpm/action-setup@v4 |
| 44 | + |
| 45 | + - uses: actions/setup-node@v4 |
| 46 | + with: |
| 47 | + node-version: 24 |
| 48 | + cache: pnpm |
| 49 | + registry-url: https://registry.npmjs.org |
| 50 | + |
| 51 | + - run: pnpm install --frozen-lockfile |
| 52 | + |
| 53 | + - name: Determine next version |
| 54 | + id: version |
| 55 | + working-directory: packages/datum-ui |
| 56 | + env: |
| 57 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + run: | |
| 59 | + CURRENT=$(node -p "require('./package.json').version") |
| 60 | +
|
| 61 | + # Detect bump type from PR labels |
| 62 | + LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}' |
| 63 | + if echo "$LABELS" | grep -q "release:major"; then |
| 64 | + BUMP="major" |
| 65 | + elif echo "$LABELS" | grep -q "release:minor"; then |
| 66 | + BUMP="minor" |
| 67 | + else |
| 68 | + BUMP="patch" |
| 69 | + fi |
| 70 | +
|
| 71 | + # Calculate next version |
| 72 | + NEXT=$(node -e " |
| 73 | + const [major, minor, patch] = '${CURRENT}'.split('.').map(Number); |
| 74 | + const bump = '${BUMP}'; |
| 75 | + if (bump === 'major') console.log(\`\${major+1}.0.0\`); |
| 76 | + else if (bump === 'minor') console.log(\`\${major}.\${minor+1}.0\`); |
| 77 | + else console.log(\`\${major}.\${minor}.\${patch+1}\`); |
| 78 | + ") |
| 79 | + SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7) |
| 80 | + ALPHA_VERSION="${NEXT}-alpha.${SHORT_SHA}" |
| 81 | +
|
| 82 | + echo "version=${ALPHA_VERSION}" >> "$GITHUB_OUTPUT" |
| 83 | + echo "Publishing ${ALPHA_VERSION} (${BUMP} bump from ${CURRENT})" |
| 84 | +
|
| 85 | + - name: Set alpha version |
| 86 | + working-directory: packages/datum-ui |
| 87 | + run: npm version ${{ steps.version.outputs.version }} --no-git-tag-version |
| 88 | + |
| 89 | + - name: Build |
| 90 | + run: pnpm --filter @datum-cloud/datum-ui build |
| 91 | + |
| 92 | + - name: Publish to npm |
| 93 | + working-directory: packages/datum-ui |
| 94 | + run: pnpm publish --no-git-checks --access public --tag alpha --provenance |
| 95 | + |
| 96 | + - name: Comment on PR |
| 97 | + uses: actions/github-script@v7 |
| 98 | + with: |
| 99 | + script: | |
| 100 | + const version = '${{ steps.version.outputs.version }}'; |
| 101 | + const body = [ |
| 102 | + `### 📦 Alpha published`, |
| 103 | + '', |
| 104 | + `\`@datum-cloud/datum-ui@${version}\``, |
| 105 | + '', |
| 106 | + '```bash', |
| 107 | + `pnpm add @datum-cloud/datum-ui@${version}`, |
| 108 | + '# or use the alpha tag for the latest alpha:', |
| 109 | + 'pnpm add @datum-cloud/datum-ui@alpha', |
| 110 | + '```', |
| 111 | + ].join('\n'); |
| 112 | +
|
| 113 | + // Find and update existing comment, or create new one |
| 114 | + const { data: comments } = await github.rest.issues.listComments({ |
| 115 | + owner: context.repo.owner, |
| 116 | + repo: context.repo.repo, |
| 117 | + issue_number: context.issue.number, |
| 118 | + }); |
| 119 | +
|
| 120 | + const marker = '### 📦 Alpha published'; |
| 121 | + const existing = comments.find(c => c.body.startsWith(marker)); |
| 122 | +
|
| 123 | + if (existing) { |
| 124 | + await github.rest.issues.updateComment({ |
| 125 | + owner: context.repo.owner, |
| 126 | + repo: context.repo.repo, |
| 127 | + comment_id: existing.id, |
| 128 | + body, |
| 129 | + }); |
| 130 | + } else { |
| 131 | + await github.rest.issues.createComment({ |
| 132 | + owner: context.repo.owner, |
| 133 | + repo: context.repo.repo, |
| 134 | + issue_number: context.issue.number, |
| 135 | + body, |
| 136 | + }); |
| 137 | + } |
0 commit comments