diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f39512b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +name: CI + +on: + push: + branches: + - development + pull_request: + branches: + - development + - main + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: Typecheck, Test & Build + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build engine package + run: pnpm --filter school-timetabling-engine build + + - name: Run typecheck + run: pnpm typecheck + + - name: Run tests + run: pnpm test + + - name: Verify production build + run: pnpm build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2744101..b70b3d9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,6 @@ name: Deploy to GitHub Pages on: push: branches: - - development - main workflow_dispatch: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 17cabb2..9bd01cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,7 @@ permissions: contents: write issues: write pull-requests: write + packages: write concurrency: group: release-${{ github.ref }} @@ -55,10 +56,14 @@ jobs: name: Release Jadwali Platform needs: [release-engine] runs-on: ubuntu-latest + outputs: + released: ${{ steps.check_release.outputs.released }} + version: ${{ steps.check_release.outputs.version }} steps: - name: Checkout repository uses: actions/checkout@v4 with: + ref: main fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} @@ -85,3 +90,108 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: pnpm release:platform + + - name: Check if new platform version was released + id: check_release + run: | + if [ -f .platform-version ]; then + VERSION=$(cat .platform-version) + echo "released=true" >> "$GITHUB_OUTPUT" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "Platform released version: $VERSION" + else + echo "released=false" >> "$GITHUB_OUTPUT" + echo "No new platform release created." + fi + + publish-docker: + name: Build & Publish Docker Images + needs: [release-platform] + if: needs.release-platform.outputs.released == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Lowercase repository owner + id: repo_owner + run: echo "owner=${GITHUB_REPOSITORY_OWNER,,}" >> "$GITHUB_OUTPUT" + + - name: Extract metadata for Server + uses: docker/metadata-action@v5 + id: meta_server + with: + images: ghcr.io/${{ steps.repo_owner.outputs.owner }}/jadwali-server + tags: | + type=raw,value=${{ needs.release-platform.outputs.version }} + type=raw,value=latest + + - name: Build and push Server Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: server/Dockerfile + push: true + tags: ${{ steps.meta_server.outputs.tags }} + labels: ${{ steps.meta_server.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Extract metadata for Client + uses: docker/metadata-action@v5 + id: meta_client + with: + images: ghcr.io/${{ steps.repo_owner.outputs.owner }}/jadwali-client + tags: | + type=raw,value=${{ needs.release-platform.outputs.version }} + type=raw,value=latest + + - name: Build and push Client Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: client/Dockerfile + push: true + tags: ${{ steps.meta_client.outputs.tags }} + labels: ${{ steps.meta_client.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + sync-development: + name: Sync Release to Development Branch + needs: [release-platform] + if: always() && needs.release-platform.result == 'success' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Merge main back into development + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git checkout development + git pull origin development + git merge origin/main --no-edit -m "chore: sync release from main back to development [skip ci]" || echo "No changes or already up to date" + git push origin development || echo "Nothing to push" diff --git a/.gitignore b/.gitignore index b9a3a75..fcec290 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ local/ docs/ .superpowers/ **/superpowers/ +.platform-version diff --git a/package.json b/package.json index 160b00b..3d54a0e 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "build": "pnpm --filter school-timetabling-engine build && pnpm --filter client build", "test": "pnpm -r run test", "typecheck": "pnpm --filter school-timetabling-engine build && pnpm -r run typecheck", - "release:engine": "semantic-release --config release-engine.config.cjs", - "release:platform": "semantic-release --config release-platform.config.cjs" + "release:engine": "semantic-release --extends ./release-engine.config.cjs", + "release:platform": "semantic-release --extends ./release-platform.config.cjs" }, "devDependencies": { "@semantic-release/changelog": "^6.0.3", diff --git a/release-platform.config.cjs b/release-platform.config.cjs index b30d7d8..eef0ac4 100644 --- a/release-platform.config.cjs +++ b/release-platform.config.cjs @@ -49,7 +49,8 @@ module.exports = { [ '@semantic-release/exec', { - prepareCmd: 'node scripts/sync-platform-versions.js ${nextRelease.version}' + prepareCmd: 'node scripts/sync-platform-versions.js ${nextRelease.version}', + successCmd: 'node -e "require(\'fs\').writeFileSync(\'.platform-version\', \'${nextRelease.version}\')"' } ], [ diff --git a/scripts/sync-platform-versions.js b/scripts/sync-platform-versions.js index 94e12f4..eeb8e47 100644 --- a/scripts/sync-platform-versions.js +++ b/scripts/sync-platform-versions.js @@ -1,8 +1,6 @@ -import fs from 'node:fs'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; +const fs = require('node:fs'); +const path = require('node:path'); -const __dirname = path.dirname(fileURLToPath(import.meta.url)); const rootDir = path.resolve(__dirname, '..'); const version = process.argv[2];