name: Build Frontend And Update GitOps on: push: branches: - main - high-performance jobs: build-and-push: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Log in to registry run: | echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login registry.nxtgauge.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin - name: Build and push frontend image run: | set -euo pipefail IMAGE="registry.nxtgauge.com/nxtgauge-frontend-solid:${{ github.sha }}" docker build -t "${IMAGE}" -t registry.nxtgauge.com/nxtgauge-frontend-solid:latest . docker push "${IMAGE}" docker push registry.nxtgauge.com/nxtgauge-frontend-solid:latest update-gitops: needs: build-and-push runs-on: ubuntu-latest steps: - name: Update GitOps frontend tag env: GITOPS_USERNAME: ${{ secrets.GITOPS_GITHUB_USERNAME || 'Traceworks2023' }} GITOPS_PASSWORD: ${{ secrets.GITOPS_GITHUB_TOKEN || secrets.GITOPS_PAT }} GITOPS_REPO: https://github.com/Traceworks2023/nxtgauge-gitops.git IMAGE_TAG: ${{ github.sha }} run: | set -euo pipefail test -n "${GITOPS_PASSWORD:-}" || { echo "GITOPS_PASSWORD is empty"; exit 1; } AUTH="$(printf '%s' "${GITOPS_USERNAME}:${GITOPS_PASSWORD}" | base64 -w0)" TMP_DIR="$(mktemp -d)" git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" clone --branch main "${GITOPS_REPO}" "${TMP_DIR}" cd "${TMP_DIR}" python3 - <<'PY' from pathlib import Path path = Path('apps/nxtgauge-frontend-solid/overlays/prod/kustomization.yaml') text = path.read_text() old = 'newTag: latest' if old not in text: raise SystemExit('expected frontend newTag line not found') path.write_text(text.replace(old, f'newTag: ' + __import__('os').environ['IMAGE_TAG'], 1)) PY git config user.name "forgejo-actions" git config user.email "forgejo-actions@nxtgauge.com" git add apps/nxtgauge-frontend-solid/overlays/prod/kustomization.yaml git diff --cached --quiet && exit 0 git commit -m "chore(gitops): update frontend image to ${IMAGE_TAG}" git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push origin main