[Closes #8] Updated CI test and build workflow #58
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - "dev" | |
| - "main" | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| jobs: | |
| meta: | |
| name: Generate and check metadata | |
| runs-on: ubuntu-latest | |
| outputs: | |
| environment: ${{ steps.environment.outputs.environment }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tag: ${{ steps.meta.outputs.tags }} | |
| tag_names: ${{ steps.meta.outputs.tag_names }} | |
| tag_exists: ${{ steps.check-image.outputs.tag_exists }} | |
| json: ${{ steps.meta.outputs.json }} | |
| version: ${{ steps.meta.outputs.version }} | |
| steps: | |
| - name: Set environment variable based on branch | |
| id: environment | |
| run: | | |
| if [[ "${{ github.ref_name }}" == "main" ]]; then | |
| echo "environment=main" >> "$GITHUB_OUTPUT" | |
| elif [[ "${{ github.ref_name }}" == "dev" ]]; then | |
| echo "environment=dev" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ vars.REGISTRY_IMAGE }} | |
| tags: | | |
| type=sha,format=long | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Check if image exists already | |
| id: check-image | |
| run: | | |
| if docker manifest inspect ${{ steps.meta.outputs.tags }} > /dev/null 2>&1; then | |
| echo "tag_exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "tag_exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| test: | |
| name: Test | |
| needs: meta | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.meta.outputs.tag_exists == 'false' }} | |
| container: node:22.19.0-bookworm | |
| services: | |
| db: | |
| image: postgres:17.6 | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| minio: | |
| image: minio/minio:RELEASE.2025-09-07T16-13-09Z | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Set up npm cache | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Generate Prisma client | |
| run: npm run prisma:generate -w server | |
| - name: Run ESLint | |
| run: npm run lint:check | |
| - name: Run Tests | |
| run: cp server/example.env server/.env && npm test | |
| - name: Build client | |
| run: npm run build -w client | |
| build: | |
| name: Build Image | |
| needs: [ meta, test ] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| runner: | |
| - ubuntu-24.04 | |
| - ubuntu-24.04-arm | |
| runs-on: ${{ matrix.runner }} | |
| if: ${{ github.ref_name == 'dev' || github.ref_name == 'main' }} | |
| steps: | |
| - name: Prepare | |
| run: | | |
| if [[ ${{ matrix.runner }} == "ubuntu-24.04-arm" ]]; then | |
| platform=linux/arm64 | |
| else | |
| platform=linux/amd64 | |
| fi | |
| echo "PLATFORM=${platform}" >> $GITHUB_ENV | |
| echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
| - name: Set up docker buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to docker hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: ${{ env.PLATFORM }} | |
| labels: ${{ needs.meta.outputs.labels }} | |
| tags: ${{ vars.REGISTRY_IMAGE }} | |
| outputs: type=image,push-by-digest=true,name-canonical=true,push=true | |
| - name: Export digest | |
| run: | | |
| mkdir -p ${{ runner.temp }}/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "${{ runner.temp }}/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ env.PLATFORM_PAIR }} | |
| path: ${{ runner.temp }}/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: [ meta, build ] | |
| env: | |
| DOCKER_METADATA_OUTPUT_VERSION: ${{ needs.meta.outputs.version }} | |
| DOCKER_METADATA_OUTPUT_TAGS: ${{ needs.meta.outputs.tag }} | |
| DOCKER_METADATA_OUTPUT_TAG_NAMES: ${{ needs.meta.outputs.tag_names }} | |
| DOCKER_METADATA_OUTPUT_LABELS: ${{ needs.meta.outputs.labels }} | |
| DOCKER_METADATA_OUTPUT_JSON: ${{ needs.meta.outputs.json }} | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ${{ runner.temp }}/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Create manifest list and push | |
| working-directory: ${{ runner.temp }}/digests | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf '${{ vars.REGISTRY_IMAGE }}@sha256:%s ' *) | |
| - name: Inspect image | |
| run: | | |
| docker buildx imagetools inspect ${{ needs.meta.outputs.tag }} | |
| deploy: | |
| name: Deploy | |
| needs: [ meta, merge ] | |
| if: | | |
| always() | |
| && (needs.meta.outputs.tag_exists == 'true' || needs.merge.result == 'success') | |
| runs-on: ubuntu-latest | |
| environment: ${{ needs.meta.outputs.environment }} | |
| steps: | |
| - name: Push to dokku | |
| uses: dokku/github-action@master | |
| with: | |
| git_remote_url: ${{ vars.DOKKU_GIT_REMOTE_URL }} | |
| ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| deploy_docker_image: ${{ needs.meta.outputs.tag }} |