diff --git a/.github/workflows/release-site.yml b/.github/workflows/release-site.yml new file mode 100644 index 0000000..bed171b --- /dev/null +++ b/.github/workflows/release-site.yml @@ -0,0 +1,48 @@ +name: Build and Deploy htmgo.dev + +on: + push: + branches: + - master # Trigger on pushes to master + paths: + - 'htmgo-site/**' # Trigger only if files in this directory change + +jobs: + build-and-push: + runs-on: self-hosted + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get short commit hash + id: vars + run: echo "::set-output name=short_sha::$(echo $GITHUB_SHA | cut -c1-7)" + + - name: Build Docker image + run: | + cd ./htmgo-site && docker build -t ghcr.io/${{ github.repository_owner }}/htmgo-site:${{ steps.vars.outputs.short_sha }} . + + - name: Log in to GitHub Container Registry + run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push Docker image + run: | + docker push ghcr.io/${{ github.repository_owner }}/htmgo-site:${{ steps.vars.outputs.short_sha }} + + - name: Create Git tag + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git tag ${{ steps.vars.outputs.short_sha }} + git push origin ${{ steps.vars.outputs.short_sha }} \ No newline at end of file diff --git a/framework/hx/trigger.go b/framework/hx/trigger.go index e275c7e..89fd46a 100644 --- a/framework/hx/trigger.go +++ b/framework/hx/trigger.go @@ -76,10 +76,7 @@ func (t Trigger) AddEvent(event TriggerEvent) Trigger { func (t Trigger) ToString() string { builder := strings.Builder{} for i, e := range t.events { - eventName := e.event - if strings.HasPrefix(eventName, "htmx:") { - eventName = eventName[5:] - } + eventName := ToHtmxTriggerName(e.event) builder.WriteString(eventName) for _, m := range e.modifiers { builder.WriteString(" ") diff --git a/htmgo-site/Dockerfile b/htmgo-site/Dockerfile new file mode 100644 index 0000000..41abac1 --- /dev/null +++ b/htmgo-site/Dockerfile @@ -0,0 +1,32 @@ +# Stage 1: Build the Go binary +FROM golang:1.22-alpine AS builder + +# Set the working directory inside the container +WORKDIR /app + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download and cache the Go modules +RUN go mod download + +# Copy the source code into the container +COPY . . + +# Build the Go binary for Linux +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server + +# Stage 2: Create the smallest possible image +FROM gcr.io/distroless/base-debian11 + +# Set the working directory inside the container +WORKDIR /app + +# Copy the Go binary from the builder stage +COPY --from=builder /app/server . + +# Expose the necessary port (replace with your server port) +EXPOSE 3000 + +# Command to run the binary +CMD ["./server"] \ No newline at end of file