Skip to content

fix(ws-bridge): broadcast permissionMode changes from CLI to browsers… #159

fix(ws-bridge): broadcast permissionMode changes from CLI to browsers…

fix(ws-bridge): broadcast permissionMode changes from CLI to browsers… #159

Workflow file for this run

name: Preview
on:
push:
branches: [main]
concurrency:
group: preview-main
cancel-in-progress: true
permissions:
contents: read
env:
REGISTRY: docker.io
IMAGE_NAME: stangirard/the-companion
jobs:
test-gate:
name: test-gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
working-directory: web
run: bun install
- name: Typecheck
working-directory: web
run: bun run typecheck
- name: Run tests
working-directory: web
run: bun run test
preview-docker:
name: deploy/preview
needs: test-gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & push preview image
uses: docker/build-push-action@v6
with:
context: web/docker
file: web/docker/Dockerfile.the-companion
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:preview-main
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:preview-${{ github.sha }}
cache-from: |
type=gha
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:preview-main
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
preview-npm:
name: deploy/preview-npm
needs: test-gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
working-directory: web
run: bun install
- name: Build frontend
working-directory: web
run: bun run build
env:
VITE_POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }}
VITE_POSTHOG_HOST: ${{ vars.VITE_POSTHOG_HOST || 'https://us.i.posthog.com' }}
- name: Verify dist exists
working-directory: web
run: |
test -f dist/index.html || (echo "ERROR: dist/index.html missing" && exit 1)
- name: Compute prerelease version
id: version
working-directory: web
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
TIMESTAMP=$(date +%Y%m%d%H%M%S)
# Bump patch by 1 so the prerelease is semver-ahead of the current
# stable release. Without this, 0.68.0-preview.* < 0.68.0 and the
# in-app update checker correctly rejects it (THE-216).
NEXT_PATCH=$(node -p "
const v = '${BASE_VERSION}'.split('.');
v[2] = Number(v[2]) + 1;
v.join('.')
")
PRE_VERSION="${NEXT_PATCH}-preview.${TIMESTAMP}.${SHORT_SHA}"
echo "version=${PRE_VERSION}" >> "$GITHUB_OUTPUT"
echo "Preview version: ${PRE_VERSION}"
- name: Validate prerelease is semver-ahead of stable
working-directory: web
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
PRE_VERSION="${{ steps.version.outputs.version }}"
node -e "
const semverGt = (a, b) => {
const pa = a.split('-')[0].split('.').map(Number);
const pb = b.split('-')[0].split('.').map(Number);
for (let i = 0; i < 3; i++) {
if (pa[i] > pb[i]) return true;
if (pa[i] < pb[i]) return false;
}
// Equal core: stable > prerelease of same core
return a.split('-').length === 1 && b.split('-').length > 1;
};
if (!semverGt('${PRE_VERSION}', '${BASE_VERSION}')) {
console.error('FATAL: preview version ${PRE_VERSION} is not semver-greater than stable ${BASE_VERSION}');
process.exit(1);
}
console.log('OK: ${PRE_VERSION} > ${BASE_VERSION}');
"
- name: Set prerelease version
working-directory: web
run: npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
- name: Publish prerelease to npm
working-directory: web
run: npm publish --access public --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}