🍴 Publish kubernetes-models crd-generate #11
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
| name: 🍴 Publish kubernetes-models crd-generate | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: publish-kubernetes-models-crd-generate | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-publish: | |
| name: Build and publish from 'featured' branch | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout SocialGouv/kubernetes-models-ts (featured) | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: SocialGouv/kubernetes-models-ts | |
| ref: featured | |
| path: kubernetes-models-ts | |
| fetch-depth: 1 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| always-auth: true | |
| cache: pnpm | |
| cache-dependency-path: kubernetes-models-ts/pnpm-lock.yaml | |
| - name: Install dependencies | |
| working-directory: kubernetes-models-ts | |
| run: pnpm install --frozen-lockfile=false | |
| - name: Build (crd-generate only via turbo filter) | |
| working-directory: kubernetes-models-ts | |
| run: pnpm turbo run build --filter=@kubernetes-models/crd-generate | |
| - name: Rewrite package.json for publish (rename + resolve workspace deps via pnpm) | |
| working-directory: kubernetes-models-ts | |
| shell: bash | |
| run: | | |
| node - <<'NODE' | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const cp = require('child_process'); | |
| const root = process.cwd(); | |
| const pkgPath = path.join('utils', 'crd-generate', 'package.json'); | |
| const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); | |
| // Rename and ensure publishable | |
| pkg.name = '@crossplane-js/kubernetes-models-crd-generate'; | |
| pkg.publishConfig = { ...(pkg.publishConfig || {}), access: 'public' }; | |
| if (pkg.private) delete pkg.private; | |
| // Use pnpm to list all workspaces once | |
| const out = cp.execSync('pnpm ls -r --depth -1 --json', { encoding: 'utf8' }); | |
| const list = JSON.parse(out); | |
| const versions = new Map(); | |
| for (const p of list) { | |
| if (p && p.name && p.version) versions.set(p.name, p.version); | |
| } | |
| const depSets = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']; | |
| function mapWorkspaceSpecifier(spec, version) { | |
| const s = spec.replace(/^workspace:/, '').trim(); | |
| if (s === '^') return '^' + version; | |
| if (s === '~') return '~' + version; | |
| if (s === '' || s === '*') return version; | |
| if (s.startsWith('^')) return '^' + version; | |
| if (s.startsWith('~')) return '~' + version; | |
| return version; | |
| } | |
| const unresolved = []; | |
| for (const set of depSets) { | |
| const deps = pkg[set]; | |
| if (!deps) continue; | |
| for (const [name, spec] of Object.entries(deps)) { | |
| if (typeof spec === 'string' && spec.startsWith('workspace:')) { | |
| const v = versions.get(name); | |
| if (!v) { | |
| unresolved.push(name); | |
| } else { | |
| deps[name] = mapWorkspaceSpecifier(spec, v); | |
| } | |
| } | |
| } | |
| } | |
| if (unresolved.length) { | |
| console.error('ERROR: Could not resolve workspace versions for:', unresolved.join(', ')); | |
| process.exit(1); | |
| } | |
| // Suffix version with commit and run identifiers (semver prerelease) | |
| const base = (pkg.version || '0.0.0').split('-')[0]; | |
| const shortSha = cp.execSync('git rev-parse --short=12 HEAD', { encoding: 'utf8' }).trim(); | |
| const runNum = process.env.GITHUB_RUN_NUMBER || '0'; | |
| const runAttempt = process.env.GITHUB_RUN_ATTEMPT || '1'; | |
| const suffix = `sha.${shortSha}.r${runNum}.a${runAttempt}`; | |
| pkg.version = `${base}-${suffix}`; | |
| fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); | |
| console.log('Rewrote workspace dependencies to monorepo versions for', pkgPath); | |
| console.log('Final version:', pkg.version); | |
| NODE | |
| echo "Updated package.json:" | |
| cat utils/crd-generate/package.json | |
| - name: Publish to npm | |
| working-directory: kubernetes-models-ts/utils/crd-generate | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.SOCIALGROOVYBOT_NPM_TOKEN }} | |
| run: npm publish --access public --tag featured |