From dee7744e457d646694c19b3de3d2a2d004c02384 Mon Sep 17 00:00:00 2001 From: rock Date: Tue, 8 Sep 2026 18:31:42 -0700 Subject: [PATCH] ci: split PR check and deploy workflows build.yaml (PR only): - cargo build + test + clippy - Docker build + push with SHA tag (no :latest) - Image exists in registry after PR CI passes deploy.yaml (main push only): - docker pull SHA image (already in registry from PR) - docker tag as :latest - docker push :latest - No rebuild, no cargo steps --- .gitea/workflows/build.yaml | 33 +++++++++------------------ .gitea/workflows/deploy.yaml | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 .gitea/workflows/deploy.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index d4cf924..c39612b 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,11 +1,8 @@ -name: CI +name: PR Check on: - push: - branches: [main] pull_request: branches: [main] - workflow_dispatch: env: REGISTRY: forgejo.riotpiao.com @@ -14,28 +11,26 @@ env: SQLX_OFFLINE: "true" jobs: - ci: - name: CI + check: + name: Build, Test & Image runs-on: rust steps: - - name: Install Node.js and Docker - run: | - apt-get update - apt-get install -y nodejs docker.io + - name: Install Docker + run: apt-get update && apt-get install -y docker.io - name: Checkout code uses: actions/checkout@v4 - - name: Cargo build all + - name: Cargo build run: cargo build --all --verbose - - name: Cargo test all + - name: Cargo test run: cargo test --all --lib --verbose 2>&1 | tail -150 || true - name: Cargo clippy run: cargo clippy --all --all-targets -- -D warnings 2>&1 | tail -50 || true - - name: Clean build artifacts before Docker + - name: Clean build artifacts run: cargo clean - name: Get short SHA @@ -50,19 +45,13 @@ jobs: REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} - - name: Build Docker image + - name: Build and push image (SHA tag only) run: | docker build --no-cache --progress=plain \ -t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \ - -t "${IMAGE}:latest" \ -f Dockerfile . - - - name: Push Docker image - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' - run: | docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}" - docker push "${IMAGE}:latest" - echo "✓ Pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" + echo "Pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" - - name: Prune unused images + - name: Prune images run: docker image prune -a --force 2>&1 | tail -3 || true diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..52db832 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,44 @@ +name: Deploy + +on: + push: + branches: [main] + workflow_dispatch: + +env: + REGISTRY: forgejo.riotpiao.com + IMAGE: forgejo.riotpiao.com/riotpiao-poimen/poimen-memory + DOCKER_HOST: tcp://localhost:2375 + +jobs: + deploy: + name: Tag & Push Latest + runs-on: rust + steps: + - name: Install Docker + run: apt-get update && apt-get install -y docker.io + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get short SHA + id: sha + run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Registry login + run: | + echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \ + --username "${REGISTRY_USER}" --password-stdin + env: + REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} + REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} + + - name: Pull SHA image and tag as latest + run: | + docker pull "${IMAGE}:${{ steps.sha.outputs.short_sha }}" && \ + docker tag "${IMAGE}:${{ steps.sha.outputs.short_sha }}" "${IMAGE}:latest" && \ + docker push "${IMAGE}:latest" && \ + echo "Tagged and pushed: ${IMAGE}:latest (from ${{ steps.sha.outputs.short_sha }})" + + - name: Prune images + run: docker image prune -a --force 2>&1 | tail -3 || true