name: flatgit CI on: workflow_dispatch: push: branches: ["main"] tags: ["v*"] pull_request: branches: ["main"] permissions: contents: read jobs: build: name: Go build and test runs-on: ubuntu-latest steps: - &checkout uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version: "1.26.x" cache: true - name: Test run: go test ./... - name: Vet run: go vet ./... - name: Build run: go build -trimpath -o ./bin/flatgit ./cmd/flatgit - name: Smoke test run: ./bin/flatgit version docker: name: Docker image runs-on: ubuntu-latest needs: - build if: startsWith(github.ref, 'refs/tags/v') permissions: contents: read packages: write steps: - *checkout - &set_build_version name: Set build version id: set_build_version shell: bash run: | set -eu if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then BUILD_VER="${GITHUB_REF_NAME}" else BUILD_VER="dev-${GITHUB_SHA::12}" fi echo "BUILD_VER=${BUILD_VER}" >> "$GITHUB_ENV" echo "build_ver=${BUILD_VER}" >> "$GITHUB_OUTPUT" echo "Build version: ${BUILD_VER}" - &set_image_name name: Set image name shell: bash run: | set -eu image="ghcr.io/${GITHUB_REPOSITORY}" image="${image,,}" echo "IMAGE_NAME=${image}" >> "$GITHUB_ENV" echo "Image name: ${image}" - &setup_buildx name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - &login_ghcr name: Login to GHCR uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ github.token }} - name: Docker metadata id: meta uses: docker/metadata-action@v6 with: images: ${{ env.IMAGE_NAME }} tags: | type=raw,value=${{ env.BUILD_VER }}-debian-slim type=raw,value=latest-debian-slim,enable=${{ startsWith(github.ref, 'refs/tags/v') }} - name: Build and push image uses: docker/build-push-action@v7 with: context: . file: ./dockerfiles/github.Dockerfile platforms: linux/amd64,linux/arm64 push: true build-args: | BUILD_VER=${{ env.BUILD_VER }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}