fix: ubuntu runner
Some checks failed
Build, Test and Deploy / test-backend (push) Successful in 13s
Build, Test and Deploy / build-and-push (push) Failing after 11s
Build, Test and Deploy / deploy (push) Has been skipped

This commit is contained in:
2026-01-29 19:33:57 +01:00
parent 465678f3e4
commit 7fafabad42

View File

@@ -2,89 +2,94 @@ name: Build, Test and Deploy
on: on:
push: push:
branches: branches: [main, int, dev]
- main
- int concurrency:
- dev group: print-calculator-${{ gitea.ref }}
cancel-in-progress: true
jobs: jobs:
test-backend: test-backend:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up Python # Evito actions/setup-python (spesso fragile su act_runner)
uses: actions/setup-python@v4 - name: Install Python deps + run tests
with: shell: bash
python-version: '3.10'
- name: Install dependencies
run: | run: |
pip install -r backend/requirements.txt apt-get update
pip install pytest httpx apt-get install -y --no-install-recommends python3 python3-pip
python3 -m pip install --upgrade pip
- name: Run Backend Tests python3 -m pip install -r backend/requirements.txt
run: | python3 -m pip install pytest httpx
export PYTHONPATH=$PYTHONPATH:$(pwd)/backend export PYTHONPATH="${PYTHONPATH}:$(pwd)/backend"
pytest backend/tests pytest backend/tests
build-and-push: build-and-push:
needs: test-backend needs: test-backend
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set Environment Variables - name: Set TAG
shell: bash
run: | run: |
if [[ "${{ gitea.ref }}" == "refs/heads/main" ]]; then if [[ "${{ gitea.ref }}" == "refs/heads/main" ]]; then
echo "TAG=prod" >> $GITHUB_ENV echo "TAG=prod" >> "$GITHUB_ENV"
elif [[ "${{ gitea.ref }}" == "refs/heads/int" ]]; then elif [[ "${{ gitea.ref }}" == "refs/heads/int" ]]; then
echo "TAG=int" >> $GITHUB_ENV echo "TAG=int" >> "$GITHUB_ENV"
else else
echo "TAG=dev" >> $GITHUB_ENV echo "TAG=dev" >> "$GITHUB_ENV"
fi fi
- name: Ensure docker CLI exists
shell: bash
run: |
if ! command -v docker >/dev/null 2>&1; then
apt-get update
apt-get install -y --no-install-recommends docker.io
fi
docker version
- name: Login to Gitea Registry - name: Login to Gitea Registry
uses: docker/login-action@v2 shell: bash
with: run: |
registry: ${{ secrets.REGISTRY_URL }} echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ secrets.REGISTRY_URL }}" \
username: ${{ secrets.GITEA_USER }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin
password: ${{ secrets.GITEA_TOKEN }}
- name: Build and Push Backend - name: Build & Push Backend
uses: docker/build-push-action@v4 shell: bash
with: run: |
context: ./backend BACKEND_IMAGE="${{ secrets.REGISTRY_URL }}/${{ gitea.repository_owner }}/print-calculator-backend:${{ env.TAG }}"
push: true docker build -t "$BACKEND_IMAGE" ./backend
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.repository_owner }}/print-calculator-backend:${{ env.TAG }} docker push "$BACKEND_IMAGE"
- name: Build and Push Frontend - name: Build & Push Frontend
uses: docker/build-push-action@v4 shell: bash
with: run: |
context: ./frontend FRONTEND_IMAGE="${{ secrets.REGISTRY_URL }}/${{ gitea.repository_owner }}/print-calculator-frontend:${{ env.TAG }}"
push: true docker build -t "$FRONTEND_IMAGE" ./frontend
tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.repository_owner }}/print-calculator-frontend:${{ env.TAG }} docker push "$FRONTEND_IMAGE"
deploy: deploy:
needs: build-and-push needs: build-and-push
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout (serve per avere compose + env nel workspace)
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set Deployment Vars - name: Set ENV
shell: bash
run: | run: |
if [[ "${{ gitea.ref }}" == "refs/heads/main" ]]; then if [[ "${{ gitea.ref }}" == "refs/heads/main" ]]; then
echo "ENV=prod" >> $GITHUB_ENV echo "ENV=prod" >> "$GITHUB_ENV"
echo "TAG=prod" >> $GITHUB_ENV
elif [[ "${{ gitea.ref }}" == "refs/heads/int" ]]; then elif [[ "${{ gitea.ref }}" == "refs/heads/int" ]]; then
echo "ENV=int" >> $GITHUB_ENV echo "ENV=int" >> "$GITHUB_ENV"
echo "TAG=int" >> $GITHUB_ENV
else else
echo "ENV=dev" >> $GITHUB_ENV echo "ENV=dev" >> "$GITHUB_ENV"
echo "TAG=dev" >> $GITHUB_ENV
fi fi
- name: Create Remote Directory - name: Create Remote Directory
@@ -111,7 +116,7 @@ jobs:
username: ${{ secrets.SERVER_USER }} username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }} key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "deploy/envs/${{ env.ENV }}.env" source: "deploy/envs/${{ env.ENV }}.env"
target: "/mnt/user/appdata/print-calculator/${{ env.ENV }}/.env" target: "/mnt/user/appdata/print-calculator/${{ env.ENV }}/"
- name: Execute Remote Deployment - name: Execute Remote Deployment
uses: appleboy/ssh-action@v0.1.10 uses: appleboy/ssh-action@v0.1.10
@@ -120,18 +125,14 @@ jobs:
username: ${{ secrets.SERVER_USER }} username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }} key: ${{ secrets.SSH_PRIVATE_KEY }}
script: | script: |
set -e
cd /mnt/user/appdata/print-calculator/${{ env.ENV }}/ cd /mnt/user/appdata/print-calculator/${{ env.ENV }}/
# Rename the copied env file to strictly '.env' so docker compose picks it up automatically # il file copiato si chiama "dev.env"/"int.env"/"prod.env"
mv ${{ env.ENV }}.env .env mv "${{ env.ENV }}.env" .env
# Login to registry echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ secrets.REGISTRY_URL }}" \
echo ${{ secrets.GITEA_TOKEN }} | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.GITEA_USER }} --password-stdin -u "${{ secrets.REGISTRY_USER }}" --password-stdin
# Pull new images
# We force reading from .env just to be safe, though default behavior does it too.
docker compose --env-file .env -f docker-compose.deploy.yml pull docker compose --env-file .env -f docker-compose.deploy.yml pull
# Start/Update services
# TAG is inside .env now, so we don't even need to pass it explicitly!
docker compose --env-file .env -f docker-compose.deploy.yml up -d --remove-orphans docker compose --env-file .env -f docker-compose.deploy.yml up -d --remove-orphans