name: Tests und Docker-Image on: push: branches: ['**'] tags: ['v*'] pull_request: branches: [main] jobs: test: name: Tests und Frontend-Build runs-on: ubuntu-latest steps: - name: Quellcode auschecken uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: persist-credentials: false - name: Node.js 22 uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: '22' - run: npm ci - run: npm test - run: npm run build image: name: Leeres Produktionsimage bauen und veröffentlichen needs: test runs-on: ubuntu-latest env: REGISTRY_IMAGE: git.jfritzsche.de/jf/syncova-ticket COMMIT_SHA: ${{ gitea.sha }} steps: - name: Quellcode auschecken uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: persist-credentials: false - name: Node.js 22 für Image-Prüfung uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: '22' - name: Docker Buildx einrichten uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - name: Docker Compose einrichten uses: https://github.com/docker/setup-compose-action@2fe291b7677a45ee1269ec56a42604c143505e7e # v1 with: version: v2.39.4 cache-binary: false - name: Produktions- und Proxy-Konfiguration prüfen run: npm run test:compose - name: Produktionsimage bauen uses: https://github.com/docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 with: context: . load: true push: false tags: git.jfritzsche.de/jf/syncova-ticket:sha-${{ gitea.sha }} labels: | org.opencontainers.image.source=https://git.jfritzsche.de/jf/syncova-ticket org.opencontainers.image.revision=${{ gitea.sha }} - name: Leere Daten und Produktionsstart prüfen run: npm run test:image env: SYNCOVA_IMAGE: git.jfritzsche.de/jf/syncova-ticket:sha-${{ gitea.sha }} - name: An der Registry anmelden if: gitea.event_name == 'push' && (gitea.ref == 'refs/heads/main' || startsWith(gitea.ref, 'refs/tags/v')) uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 with: registry: git.jfritzsche.de username: jf password: ${{ secrets.REGISTRY_TOKEN }} - name: Geprüftes Image veröffentlichen if: gitea.event_name == 'push' && (gitea.ref == 'refs/heads/main' || startsWith(gitea.ref, 'refs/tags/v')) env: REF: ${{ gitea.ref }} REF_NAME: ${{ gitea.ref_name }} run: | set -eu image="$REGISTRY_IMAGE:sha-$COMMIT_SHA" docker push "$image" if [ "$REF" = 'refs/heads/main' ]; then current_main="$(git ls-remote origin refs/heads/main | cut -f1)" if [ "$current_main" = "$COMMIT_SHA" ]; then docker tag "$image" "$REGISTRY_IMAGE:latest" docker push "$REGISTRY_IMAGE:latest" else echo 'Neuerer main-Commit vorhanden; latest bleibt beim neueren Build.' fi else printf '%s' "$REF_NAME" | grep -Eq '^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$' docker tag "$image" "$REGISTRY_IMAGE:$REF_NAME" docker push "$REGISTRY_IMAGE:$REF_NAME" fi