Build #190
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build | |
| on: | |
| push: | |
| tags: | |
| - '*' | |
| pull_request: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 0 * * *" | |
| env: | |
| REPO_OWNER_LOWER: ${{ github.repository_owner }} | |
| IMAGE_NAME: uptime-service-backend-test | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📥 Checkout | |
| uses: actions/checkout@v4 | |
| - name: 📥 Update Git Submodules | |
| run: | | |
| git submodule init | |
| git submodule update | |
| - name: 📦 Install Nix | |
| uses: cachix/install-nix-action@v31 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| - name: 🛠️ Build | |
| run: nix-shell --run "make build" | |
| - name: 🛠️ Build Docker | |
| env: | |
| TAG: latest | |
| run: nix-shell --run "make docker" | |
| - name: 🧪 Test | |
| run: nix-shell --run "make test" | |
| - name: 🔑 Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Repo owner lowercase | |
| run: echo "REPO_OWNER_LOWER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: 🪄 Determine Docker tag | |
| id: docker_tag | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| # Use branch name (sanitized) for PR builds | |
| TAG=$(echo "${{ github.head_ref }}" | sed 's/[^a-zA-Z0-9._-]/-/g') | |
| elif [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| # Use tag name for tag pushes | |
| TAG=${GITHUB_REF#refs/tags/} | |
| else | |
| # Fallback for scheduled runs | |
| TAG="nightly" | |
| fi | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| - name: 🏷️ Tag and Push Docker Image | |
| run: | | |
| docker tag ${{ env.IMAGE_NAME }}:latest ghcr.io/${{ env.REPO_OWNER_LOWER }}/uptime-service-backend:${{ steps.docker_tag.outputs.tag }} | |
| docker tag ${{ env.IMAGE_NAME }}:latest ghcr.io/${{ env.REPO_OWNER_LOWER }}/uptime-service-backend:${{ github.sha }} | |
| docker push ghcr.io/${{ env.REPO_OWNER_LOWER }}/uptime-service-backend:${{ steps.docker_tag.outputs.tag }} | |
| docker push ghcr.io/${{ env.REPO_OWNER_LOWER }}/uptime-service-backend:${{ github.sha }} | |
| - name: 🏷️ Push latest tag | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: | | |
| docker tag ${{ env.IMAGE_NAME }}:latest ghcr.io/${{ env.REPO_OWNER_LOWER }}/uptime-service-backend:latest | |
| docker push ghcr.io/${{ env.REPO_OWNER_LOWER }}/uptime-service-backend:latest |