diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index c79c8b3..b3f15be 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -31,24 +31,57 @@ jobs: # - name: Run linting # run: | # python -m flake8 web/ tests/ --max-line-length=120 + build-image: + runs-on: ubuntu-latest + needs: test + env: + DEFAULT_BRANCH: main + REGISTRY_URL: ${{ secrets.REGISTRY_URL }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + steps: + - name: Checkout + uses: actions/checkout@v4 - - name: Build Docker image + - name: Collect workflow metadata + id: meta + shell: bash run: | - docker build -t jobs-app . + ref_name="${GITHUB_REF_NAME:-${GITHUB_REF##*/}}" + event_name="${GITHUB_EVENT_NAME:-}" + sha="${GITHUB_SHA:-}" - - name: Run container tests - run: | - docker run --rm jobs-app python -m pytest tests/ -v + if [ "$ref_name" = "${DEFAULT_BRANCH:-main}" ]; then + echo "on_default=true" >> "$GITHUB_OUTPUT" + else + echo "on_default=false" >> "$GITHUB_OUTPUT" + fi - - name: Push Docker image to gitea registry - uses: docker/build-push-action@v4 - env: - REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} - REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + echo "ref_name=$ref_name" >> "$GITHUB_OUTPUT" + echo "event_name=$event_name" >> "$GITHUB_OUTPUT" + echo "sha=$sha" >> "$GITHUB_OUTPUT" + + - name: Set up QEMU and Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to registry (best-effort) + if: ${{ steps.meta.outputs.on_default == 'true' }} + uses: docker/login-action@v3 + continue-on-error: true + with: + registry: ${{ env.REGISTRY_URL }} + username: ${{ env.REGISTRY_USERNAME }} + password: ${{ env.REGISTRY_PASSWORD }} + + - name: Build (and optionally push) image + uses: docker/build-push-action@v5 with: context: . - push: true - tags: git.allucanget.biz/allucanget/jobs:latest + file: Dockerfile + push: ${{ steps.meta.outputs.on_default == 'true' && steps.meta.outputs.event_name != 'pull_request' && (env.REGISTRY_URL != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '') }} + tags: | + ${{ env.REGISTRY_URL }}/allucanget/jobs:latest + ${{ env.REGISTRY_URL }}/allucanget/jobs:${{ steps.meta.outputs.sha }} # deploy: # runs-on: ubuntu-latest