diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..71881e8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,63 @@ +name: Build image + +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + +permissions: + contents: read + packages: write + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 + with: + go-version-file: go.mod + - run: go vet ./... + - run: go test ./... + + image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + if: github.event_name != 'pull_request' + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=sha,prefix=sha- + type=semver,pattern=v{{version}} + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + - name: Version string + id: ver + run: | + if [[ "$GITHUB_REF" == refs/tags/v* ]]; then + echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" + else + echo "version=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT" + fi + - uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ steps.ver.outputs.version }} + COMMIT=${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max