From 6244bb08953c05191ba10eed298fb9243908e2b9 Mon Sep 17 00:00:00 2001 From: Frank Bernhardt <275327+frank-bee@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:45:18 +0100 Subject: [PATCH] Refactor (#23) * Refactor * Refactor * fix perminssiongss * fix perminssiongss * cancel in pr * fix --- .../workflows/build-backend-docker-image.yml | 49 ++++++ .github/workflows/build-backend.yml | 45 +++++ .github/workflows/build-onyx.yml | 165 +----------------- .github/workflows/build-typescript-apps.yml | 46 +++++ .github/workflows/build.yml | 38 ++++ 5 files changed, 187 insertions(+), 156 deletions(-) create mode 100644 .github/workflows/build-backend-docker-image.yml create mode 100644 .github/workflows/build-backend.yml create mode 100644 .github/workflows/build-typescript-apps.yml create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build-backend-docker-image.yml b/.github/workflows/build-backend-docker-image.yml new file mode 100644 index 00000000..51efb5ab --- /dev/null +++ b/.github/workflows/build-backend-docker-image.yml @@ -0,0 +1,49 @@ +name: Build Backend Docker Image + +on: + workflow_call: + +jobs: + build-backend-docker-image: + runs-on: ubuntu-latest + env: + REGISTRY: ghcr.io + steps: + - uses: actions/checkout@v4 + + - name: Restore Onyx Cache + uses: actions/cache/restore@v4 + with: + path: onyx/bin + key: onyx-${{ hashFiles('onyx/**') }} + + - name: Restore TypeScript Apps Cache + uses: actions/cache/restore@v4 + with: + path: yaku-apps-typescript + key: typescript-apps-${{ hashFiles('yaku-apps-typescript/**') }} + + - name: Restore Backend Cache + uses: actions/cache@v4 + with: + path: qg-api-service + key: qg-api-service-${{ hashFiles('qg-api-service/**') }} + + - name: Log in to the Container Registry + uses: docker/login-action@v3.3.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Docker Image + uses: docker/build-push-action@v5 + with: + pull: true + push: true + build-args: | + BASE_IMAGE_WORKFLOW_NAME=node:22-alpine + tags: ghcr.io/b-s-f/yaku/api-image-test:test + context: ./qg-api-service + file: qg-api-service/qg-api-service/Dockerfile + platforms: linux/amd64 diff --git a/.github/workflows/build-backend.yml b/.github/workflows/build-backend.yml new file mode 100644 index 00000000..908453af --- /dev/null +++ b/.github/workflows/build-backend.yml @@ -0,0 +1,45 @@ +name: Build Backend + +on: + workflow_call: + +jobs: + build-backend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Cache Turbo Build Setup + uses: actions/cache@v4 + with: + path: qg-api-service/.turbo + key: backend-turbo-${{ github.sha }} + restore-keys: | + backend-turbo- + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18.18.2 + cache: "npm" + cache-dependency-path: qg-api-service/package-lock.json + + - name: Restore Cache if Exists + id: cache + uses: actions/cache/restore@v4 + with: + path: qg-api-service + key: qg-api-service-${{ hashFiles('qg-api-service/**') }} + + - name: Install and Build + if: steps.cache.outputs.cache-hit != 'true' + working-directory: qg-api-service + run: | + npm ci -ws --include-workspace-root + npm run build + + - name: Save Cache + uses: actions/cache/save@v4 + with: + path: qg-api-service + key: ${{ steps.cache.outputs.cache-primary-key }} diff --git a/.github/workflows/build-onyx.yml b/.github/workflows/build-onyx.yml index cdd8091d..22daf336 100644 --- a/.github/workflows/build-onyx.yml +++ b/.github/workflows/build-onyx.yml @@ -1,30 +1,22 @@ -name: Test Onyx Pipeline -# Remove me +name: Build Onyx + on: - workflow_dispatch: - push: - branches: - - "test-onyx-caching" + workflow_call: jobs: build-onyx: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - attestations: write - id-token: write steps: - uses: actions/checkout@v4 - - name: Setup go + - name: Setup Go uses: actions/setup-go@v5 with: go-version: ">=1.20.0" cache: true cache-dependency-path: onyx/go.sum - - name: restore cache if exists + - name: Restore Cache if Exists id: onyx-cache uses: actions/cache/restore@v4 with: @@ -32,154 +24,15 @@ jobs: key: onyx-${{ hashFiles('onyx/**') }} lookup-only: true - - if: steps.onyx-cache.outputs.cache-hit != 'true' - name: Build + - name: Build + if: steps.onyx-cache.outputs.cache-hit != 'true' working-directory: onyx run: | make setup make build - - name: Save cache + + - name: Save Cache uses: actions/cache/save@v4 with: path: onyx/bin key: ${{ steps.onyx-cache.outputs.cache-primary-key }} - build-typescript-apps: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - attestations: write - id-token: write - steps: - - uses: actions/checkout@v4 - - name: Cache turbo build setup - uses: actions/cache@v4 - with: - path: yaku-apps-typescript/.turbo - key: typescript-apps-turbo-${{ github.sha }} - restore-keys: | - typescript-apps-turbo- - - - uses: actions/setup-node@v4 - with: - node-version: 18 - check-latest: true - cache: 'npm' - cache-dependency-path: yaku-apps-typescript/package-lock.json - - - name: restore cache if exists - id: cache - uses: actions/cache/restore@v4 - with: - path: yaku-apps-typescript - key: typescript-apps-${{ hashFiles('yaku-apps-typescript/**') }} - - - if: steps.cache.outputs.cache-hit != 'true' - name: Install and Build - working-directory: yaku-apps-typescript - run: | - npm ci -ws --include-workspace-root - npm run build - - - name: Save cache - uses: actions/cache/save@v4 - with: - path: | - yaku-apps-typescript - key: ${{ steps.cache.outputs.cache-primary-key }} - build-backend: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - attestations: write - id-token: write - steps: - - uses: actions/checkout@v4 - - name: Cache turbo build setup - uses: actions/cache@v4 - with: - path: qg-api-service/.turbo - key: backend-turbo-${{ github.sha }} - restore-keys: | - backend-turbo- - - - uses: actions/setup-node@v4 - with: - node-version: 18.18.2 - cache: "npm" - cache-dependency-path: qg-api-service/package-lock.json - - - name: restore cache if exists - id: cache - uses: actions/cache/restore@v4 - with: - path: qg-api-service - key: qg-api-service-${{ hashFiles('qg-api-service/**') }} - - - if: steps.cache.outputs.cache-hit != 'true' - name: Install and build - working-directory: qg-api-service - run: | - npm ci -ws --include-workspace-root - npm run build - - name: Save cache - uses: actions/cache/save@v4 - with: - path: | - qg-api-service - key: ${{ steps.cache.outputs.cache-primary-key }} - Build-backend-docker-image: - runs-on: ubuntu-latest - env: - REGISTRY: ghcr.io - needs: - - build-onyx - - build-typescript-apps - - build-backend - permissions: - contents: read - packages: write - attestations: write - id-token: write - steps: - - name: restore onyx cache - uses: actions/cache/restore@v4 - with: - path: | - onyx/bin - key: onyx-${{ hashFiles('onyx/**') }} - - - name: restore typescript-apps cache - uses: actions/cache/restore@v4 - with: - path: | - yaku-apps-typescript - key: typescript-apps-${{ hashFiles('yaku-apps-typescript/**') }} - - - name: restore backend cache - uses: actions/cache/restore@v4 - with: - path: | - qg-api-service - key: qg-api-service-${{ hashFiles('qg-api-service/**') }} - - - name: Log in to the Container registry - uses: docker/login-action@v3.3.0 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build docker image - uses: docker/build-push-action@v5 - with: - pull: true - push: true - build-args: | - BASE_IMAGE_WORKFLOW_NAME=node:22-alpine - tags: ghcr.io/b-s-f/yaku/api-image-test:test - context: ./qg-api-service - file: qg-api-service/qg-api-service/Dockerfile - platforms: linux/amd64 - \ No newline at end of file diff --git a/.github/workflows/build-typescript-apps.yml b/.github/workflows/build-typescript-apps.yml new file mode 100644 index 00000000..3833d3fc --- /dev/null +++ b/.github/workflows/build-typescript-apps.yml @@ -0,0 +1,46 @@ +name: Build TypeScript Apps + +on: + workflow_call: + +jobs: + build-typescript-apps: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Cache Turbo Build Setup + uses: actions/cache@v4 + with: + path: yaku-apps-typescript/.turbo + key: typescript-apps-turbo-${{ github.sha }} + restore-keys: | + typescript-apps-turbo- + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + check-latest: true + cache: 'npm' + cache-dependency-path: yaku-apps-typescript/package-lock.json + + - name: Restore Cache if Exists + id: cache + uses: actions/cache/restore@v4 + with: + path: yaku-apps-typescript + key: typescript-apps-${{ hashFiles('yaku-apps-typescript/**') }} + + - name: Install and Build + if: steps.cache.outputs.cache-hit != 'true' + working-directory: yaku-apps-typescript + run: | + npm ci -ws --include-workspace-root + npm run build + + - name: Save Cache + uses: actions/cache/save@v4 + with: + path: yaku-apps-typescript + key: ${{ steps.cache.outputs.cache-primary-key }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..18c7fedd --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,38 @@ +name: Build and Test + +on: + workflow_dispatch: + push: + branches: + - "main" + pull_request: + branches: + - "main" + +permissions: + contents: read + packages: write + id-token: write + attestations: write + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + build-onyx: + uses: ./.github/workflows/build-onyx.yml + + build-typescript-apps: + uses: ./.github/workflows/build-typescript-apps.yml + + build-backend: + uses: ./.github/workflows/build-backend.yml + + build-backend-docker-image: + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + needs: + - build-onyx + - build-typescript-apps + - build-backend + uses: ./.github/workflows/build-backend-docker-image.yml