phase6: Dockerfile, CI workflows, GHCR release pipeline
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
name: build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TAILWIND_VERSION: v3.4.17
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Install templ
|
||||
run: go install github.com/a-h/templ/cmd/templ@v0.3.1001
|
||||
|
||||
- name: Install tailwindcss standalone
|
||||
run: |
|
||||
curl -fsSL -o /usr/local/bin/tailwindcss \
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/download/${TAILWIND_VERSION}/tailwindcss-linux-x64"
|
||||
chmod +x /usr/local/bin/tailwindcss
|
||||
|
||||
- name: Build assets
|
||||
run: |
|
||||
mkdir -p web/static/dist
|
||||
templ generate ./...
|
||||
tailwindcss -c tailwind.config.js -i web/static/src/app.css -o web/static/dist/app.css --minify
|
||||
|
||||
- name: Vet
|
||||
run: go vet ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -race ./...
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p bin
|
||||
CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags="-s -w -X github.com/fserg/md-to-html/internal/version.Version=$(cat VERSION)" \
|
||||
-o bin/md-to-html ./cmd/md-to-html
|
||||
|
||||
cross-compile:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TAILWIND_VERSION: v3.4.17
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- goos: linux
|
||||
goarch: amd64
|
||||
- goos: linux
|
||||
goarch: arm64
|
||||
- goos: darwin
|
||||
goarch: arm64
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
|
||||
- name: Install templ
|
||||
run: go install github.com/a-h/templ/cmd/templ@v0.3.1001
|
||||
|
||||
- name: Install tailwindcss standalone
|
||||
run: |
|
||||
curl -fsSL -o /usr/local/bin/tailwindcss \
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/download/${TAILWIND_VERSION}/tailwindcss-linux-x64"
|
||||
chmod +x /usr/local/bin/tailwindcss
|
||||
|
||||
- name: Build assets
|
||||
run: |
|
||||
mkdir -p web/static/dist
|
||||
templ generate ./...
|
||||
tailwindcss -c tailwind.config.js -i web/static/src/app.css -o web/static/dist/app.css --minify
|
||||
|
||||
- name: Cross-compile
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
CGO_ENABLED: "0"
|
||||
run: |
|
||||
mkdir -p bin
|
||||
go build -trimpath \
|
||||
-ldflags="-s -w -X github.com/fserg/md-to-html/internal/version.Version=$(cat VERSION)" \
|
||||
-o "bin/md-to-html-${GOOS}-${GOARCH}" \
|
||||
./cmd/md-to-html
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: md-to-html-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: bin/md-to-html-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
retention-days: 7
|
||||
@@ -0,0 +1,79 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TAILWIND_VERSION: v3.4.17
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
|
||||
- name: Install templ
|
||||
run: go install github.com/a-h/templ/cmd/templ@v0.3.1001
|
||||
|
||||
- name: Install tailwindcss standalone
|
||||
run: |
|
||||
curl -fsSL -o /usr/local/bin/tailwindcss \
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/download/${TAILWIND_VERSION}/tailwindcss-linux-x64"
|
||||
chmod +x /usr/local/bin/tailwindcss
|
||||
|
||||
- name: Build assets
|
||||
run: |
|
||||
mkdir -p web/static/dist
|
||||
templ generate ./...
|
||||
tailwindcss -c tailwind.config.js -i web/static/src/app.css -o web/static/dist/app.css --minify
|
||||
|
||||
- name: Cross-compile binaries
|
||||
run: |
|
||||
mkdir -p dist
|
||||
for target in "linux amd64" "linux arm64" "darwin arm64"; do
|
||||
set -- $target
|
||||
GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -trimpath \
|
||||
-ldflags="-s -w -X github.com/fserg/md-to-html/internal/version.Version=$(cat VERSION)" \
|
||||
-o "dist/md-to-html-${1}-${2}" \
|
||||
./cmd/md-to-html
|
||||
done
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: docker/setup-qemu-action@v3
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: |
|
||||
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
|
||||
ghcr.io/${{ github.repository }}:latest
|
||||
|
||||
- name: Create GitHub Release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create "${{ github.ref_name }}" \
|
||||
--title "${{ github.ref_name }}" \
|
||||
--notes-file CHANGELOG.md \
|
||||
dist/*
|
||||
Reference in New Issue
Block a user