Skip to content

Commit

Permalink
Try new workflow to publish @mockline/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Sep 2, 2024
1 parent 32c9810 commit d335024
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci-ui.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: UI CI/CD

on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: write
id-token: write

jobs:
ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: 📦 Install dependencies
run: bun install

- name: 🚀 Prepare UI
run: bun run dev:prepare

- name: 🎨 Run Tailwind
run: bun run tailwind

- name: 💅 Lint code
run: bun run lint

- name: 🛠️ Build
run: bun run build

- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
src:
- 'packages/mockline/src/**'
- 'packages/mockline/package.json'
- 'packages/mockline/bun.lockb'
- 'packages/utils/src/**'
- 'packages/utils/package.json'
- 'packages/utils/bun.lockb'
- 'package.json'
- 'bun.lockb'
- name: 🚀 Release UI
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && steps.changes.outputs.src == 'true')
run: ./scripts/release-ui.sh
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
34 changes: 34 additions & 0 deletions scripts/bump-ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { promises as fsp } from 'fs'
import { resolve } from 'path'
import { execSync } from 'child_process'
import { join } from 'pathe'

async function loadPackage(dir: string) {
const pkgPath = resolve(dir, 'package.json')

const data = JSON.parse(await fsp.readFile(pkgPath, 'utf-8').catch(() => '{}'))

const save = () => fsp.writeFile(pkgPath, JSON.stringify(data, null, 2) + '\n')

return {
dir,
data,
save
}
}

async function main() {
const rootDir = resolve(__dirname, '..')
const pkg = await loadPackage(join(rootDir, 'packages', 'mockline'))

pkg.data.name = `@mockline/ui`

pkg.data.version = `${pkg.data.version}`

await pkg.save()
}

main().catch((err) => {
console.error(err)
process.exit(1)
})
20 changes: 20 additions & 0 deletions scripts/release-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Restore all git changes
git restore -s@ -SW -- .

# Bump versions to edge
bunx jiti ./scripts/bump-ui

# Update token
if [[ ! -z ${NPM_TOKEN} ]] ; then
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
echo "always-auth=true" >> ~/.npmrc
npm whoami
fi

# Release package
echo "Publishing @mockline/ui"
cd packages/mockline
npm publish -q --access public

0 comments on commit d335024

Please sign in to comment.