name: publish on: push: branches: - "**" workflow_dispatch: env: REGISTRY: gcr.forust.xyz IMAGE_NAME: forust/telegram-scraper jobs: docker: runs-on: [self-hosted, linux, arch, homelab] steps: - name: Checkout repository uses: actions/checkout@v4 - name: Read project version id: version shell: bash run: | version="$(python3 - <<'PY' from pathlib import Path import tomllib print(tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"]) PY )" echo "version=$version" >> "$GITHUB_OUTPUT" - name: Log in to registry shell: bash run: | echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${REGISTRY}" \ -u "${{ secrets.REGISTRY_USERNAME }}" \ --password-stdin - name: Build and push image shell: bash run: | image="${REGISTRY}/${IMAGE_NAME}" tags=("latest" "${{ steps.version.outputs.version }}") case "${GITHUB_REF_NAME}" in main) tags+=("main" "prod") ;; dev) tags+=("dev") ;; esac build_args=() for tag in "${tags[@]}"; do build_args+=(-t "${image}:${tag}") done docker build "${build_args[@]}" . for tag in "${tags[@]}"; do docker push "${image}:${tag}" done