diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 21af985..769ae66 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,100 +7,73 @@ on: tags: - 'v*' -env: - IMAGE_NAME: m1k1o/neko-rooms - jobs: build-client: - runs-on: ubuntu-latest - # - # do not run on forks - # - if: github.repository_owner == 'm1k1o' - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: '20.x' - cache: 'npm' - cache-dependency-path: ./client/package-lock.json - - - name: Install dependencies - run: cd ./client && npm install - - - name: Build - run: cd ./client && npm run build - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: client - path: ./client/dist + name: Build Client Artifacts + uses: ./.github/workflows/client_build.yml - build-docker: - needs: build-client + build-and-push: + name: Build and Push Docker Image runs-on: ubuntu-latest - # - # do not run on forks - # - if: github.repository_owner == 'm1k1o' + needs: build-client steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v4 - - - name: Download client artifact + with: + fetch-depth: 0 + + - name: Download client dist uses: actions/download-artifact@v4 with: name: client - path: ./client/dist - - - name: Remove client stage from Dockerfile - # Change dockerfile: remove first stage - everything between # STAGE 1 and # STAGE 2 - # Replace "--from=frontend /src/dist/" with "./client/dist/" - run: | - sed -i '/# STAGE 1/,/# STAGE 2/d' ./Dockerfile - sed -i 's/--from=frontend \/src\/dist\//.\/client\/dist\//g' ./Dockerfile - - - name: Set up QEMU + path: client/dist + + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - id: buildx + + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} - - - name: Extract metadata (tags, labels) for Docker + + - name: Extract metadata (tags, labels) for Docker uses: docker/metadata-action@v5 id: meta with: - images: ${{ env.IMAGE_NAME }} + images: | + docker.io/${{ github.repository }} + ghcr.io/${{ github.repository }} tags: | type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} - - - name: Log in to the Container registry + + - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ github.actor }} password: ${{ secrets.DOCKER_TOKEN }} - - - name: Build and push + + - name: Log in to GCR + uses: docker/login-action@v3 + with: + registry: gcr.io + username: ${{ github.actor }} + password: ${{ secrets.GHCR_ACCESS_TOKEN }} + + - name: Remove client stage from Dockerfile + # Change dockerfile: remove first stage - everything between # STAGE 1 and # STAGE 2 + # Replace "--from=frontend /src/dist/" with "./client/dist/" + run: | + sed -i '/# STAGE 1/,/# STAGE 2/d' ./Dockerfile + sed -i 's/--from=frontend \/src\/dist\//.\/client\/dist\//g' ./Dockerfile + + - name: Build and push uses: docker/build-push-action@v6 with: - # Turns out the build-push-action runs in a "GitHub" context by default. - # At the very least, it means pulling down your repository as part of pre-Dockerfile command. - # You can change it to the "file" context by using: - context: . + context: ./ + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: true + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/client_build.yml b/.github/workflows/client_build.yml new file mode 100644 index 0000000..a2d605a --- /dev/null +++ b/.github/workflows/client_build.yml @@ -0,0 +1,45 @@ +name: Build Client + +on: + workflow_call: + inputs: + with-artifact: + required: false + type: boolean + default: true + description: | + If true, the build artifacts will be uploaded as a GitHub Actions artifact. + This is useful for debugging and testing purposes. If false, the artifacts + will not be uploaded. This is useful for test builds where you don't need + the artifacts. + +jobs: + build-client: + name: Build Client + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + cache-dependency-path: client/package-lock.json + + - name: Install dependencies + working-directory: ./client + run: npm ci + + - name: Build client + working-directory: ./client + run: npm run build + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + if: ${{ inputs.with-artifact }} + with: + name: client + path: client/dist diff --git a/.github/workflows/client_test.yml b/.github/workflows/client_test.yml new file mode 100644 index 0000000..efebf3a --- /dev/null +++ b/.github/workflows/client_test.yml @@ -0,0 +1,19 @@ +name: Test Client + +on: + pull_request: + branches: + - master + paths: + - client/** + - .github/workflows/client_build.yml + - .github/workflows/client_test.yml + +jobs: + test-client: + name: Test Client + uses: ./.github/workflows/client_build.yml + with: + # Do not upload artifacts for test builds + with-artifact: false + secrets: inherit