name: Build and Deploy on: push: branches: - main - master jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Gitea Container Registry uses: docker/login-action@v3 with: registry: git.rogi.casa username: ${{ gitea.actor }} password: ${{ secrets.RUNNER_GITEA_TOKEN }} - name: Extract version from commit id: version run: | # Use short commit SHA as version tag VERSION=$(git rev-parse --short HEAD) echo "version=${VERSION}" >> $GITHUB_OUTPUT echo "Building version: ${VERSION}" - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: | git.rogi.casa/${{ gitea.repository_owner }}/gym-tracker/gym-tracker:${{ steps.version.outputs.version }} git.rogi.casa/${{ gitea.repository_owner }}/gym-tracker/gym-tracker:latest cache-from: type=registry,ref=gitea.rogi.casa/${{ gitea.repository_owner }}/gym-tracker/gym-tracker:latest cache-to: type=inline - name: Checkout k3s-cluster repo uses: actions/checkout@v4 with: repository: roger/k3s-cluster token: ${{ secrets.GITEA_TOKEN }} path: k3s-cluster ref: main - name: Update deployment image tag run: | cd k3s-cluster echo "Updating deployment image to version: ${{ steps.version.outputs.version }}" # Update the image tag in the deployment file sed -i "s|image: git.rogi.casa/.*/gym-tracker:.*|image: gitea.rogi.casa/${{ gitea.repository_owner }}/gym-tracker/gym-tracker:${{ steps.version.outputs.version }}|g" gym-tracker/deployment.yaml # Print the updated image line for verification grep "image: git.rogi.casa/.*/gym-tracker:" gym-tracker/deployment.yaml - name: Commit and push changes run: | cd k3s-cluster git config user.name "Gitea Actions" git config user.email "actions@gitea.local" git add gym-tracker/deployment.yaml git diff --staged --quiet || git commit -m "Update gym-tracker image to ${{ steps.version.outputs.version }}" git push