Skip to content

Commit

Permalink
separate workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
x0ddf committed Nov 24, 2024
1 parent 356b60c commit 2df53c1
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 82 deletions.
80 changes: 1 addition & 79 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Build and Release
name: Build

on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

Expand Down Expand Up @@ -33,80 +32,3 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest

docker:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release:
needs: docker
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Build release binaries
run: |
GOOS=linux GOARCH=amd64 go build -o tiny-status-page-linux-amd64
GOOS=linux GOARCH=arm64 go build -o tiny-status-page-linux-arm64
GOOS=darwin GOARCH=amd64 go build -o tiny-status-page-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -o tiny-status-page-darwin-arm64
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
tiny-status-page-linux-amd64
tiny-status-page-linux-arm64
tiny-status-page-darwin-amd64
tiny-status-page-darwin-arm64
generate_release_notes: true
110 changes: 110 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Release

on:
push:
tags: [ 'v*' ]


jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
cache: true

- name: Verify dependencies
run: go mod verify

- name: Build
run: go build -v ./...

- name: Run tests
run: go test -v ./...

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

docker:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release:
needs: docker
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Build release binaries
run: |
GOOS=linux GOARCH=amd64 go build -o tiny-status-page-linux-amd64
GOOS=linux GOARCH=arm64 go build -o tiny-status-page-linux-arm64
GOOS=darwin GOARCH=amd64 go build -o tiny-status-page-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -o tiny-status-page-darwin-arm64
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
tiny-status-page-linux-amd64
tiny-status-page-linux-arm64
tiny-status-page-darwin-amd64
tiny-status-page-darwin-arm64
generate_release_notes: true
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ RUN apk --no-cache add ca-certificates

# Copy the binary from builder
COPY --from=builder /app/tiny-status-page .
# Copy templates and static files
COPY --from=builder /app/pkg/server/templates ./pkg/server/templates
COPY --from=builder /app/pkg/server/static ./pkg/server/static

# Create non-root user
RUN adduser -D -u 1000 appuser
Expand Down

0 comments on commit 2df53c1

Please sign in to comment.