Skip to content

Commit

Permalink
chore: add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
le0m committed Aug 5, 2024
1 parent 82b630d commit dbfd50e
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 3 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '46 13 * * 1'

jobs:
analyze:
name: Analyze ${{ matrix.module }}
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
matrix:
module: ['print2pdf', 'plain', 'lambda']

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
cache-dependency-path: ${{ matrix.module }}/go.sum
go-version-file: ${{ matrix.module }}/go.mod

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: go
build-mode: manual

- name: Build
run: go build ./${{ matrix.module }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: '/language:go'
33 changes: 33 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Go Dependency Submission"

on:
push:
branches: [ main ]

permissions:
contents: write

jobs:
go-action-detection:
name: Submit dependencies
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
module: ['plain', 'lambda']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
cache-dependency-path: ${{ matrix.module }}/go.sum
go-version-file: ${{ matrix.module }}/go.mod

- name: Run snapshot action
uses: actions/go-dependency-submission@v2
with:
go-mod-path: ${{ matrix.module }}/go.mod
go-build-target: ${{ matrix.module }}/main.go
26 changes: 26 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish GO package

on:
push:
tags: [ print2pdf/v* ]

jobs:
publish-package:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
cache-dependency-path: print2pdf/go.sum
go-version-file: print2pdf/go.mod

- name: Publish package
env:
GOPROXY: proxy.golang.org
TAG: ${{ github.ref_name }}
run: go list -m "github.com/chialab/print2pdf-go/print2pdf@${TAG#print2pdf/}"
51 changes: 51 additions & 0 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release binaries

on:
push:
tags: [ v* ]

permissions:
contents: write

jobs:
release-binaries:
name: Build and release binaries
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
module: ['plain', 'lambda']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
cache-dependency-path: ${{ matrix.module }}/go.sum
go-version-file: ${{ matrix.module }}/go.mod

- name: Build
env:
CGO_ENABLED: 0
run: |
GOOS=linux GOARCH=amd64 go build -ldflags '-s' -o build/print2pdf-${{ matrix.module }}-linux-amd64 ${{ matrix.module }}
GOOS=linux GOARCH=arm64 go build -ldflags '-s' -o build/print2pdf-${{ matrix.module }}-linux-arm64 ${{ matrix.module }}
GOOS=darwin GOARCH=amd64 go build -ldflags '-s' -o build/print2pdf-${{ matrix.module }}-darwin-amd64 ${{ matrix.module }}
GOOS=darwin GOARCH=arm64 go build -ldflags '-s' -o build/print2pdf-${{ matrix.module }}-darwin-arm64 ${{ matrix.module }}
GOOS=windows GOARCH=amd64 go build -ldflags '-s' -o build/print2pdf-${{ matrix.module }}-windows-amd64 ${{ matrix.module }}
GOOS=windows GOARCH=arm64 go build -ldflags '-s' -o build/print2pdf-${{ matrix.module }}-windows-arm64 ${{ matrix.module }}
- name: Release
uses: softprops/action-gh-release@v2
with:
draft: true
generate_release_notes: true
files: |
build/print2pdf-${{ matrix.module }}-linux-amd64
build/print2pdf-${{ matrix.module }}-linux-arm64
build/print2pdf-${{ matrix.module }}-darwin-amd64
build/print2pdf-${{ matrix.module }}-darwin-arm64
build/print2pdf-${{ matrix.module }}-windows-amd64
build/print2pdf-${{ matrix.module }}-windows-arm64
55 changes: 55 additions & 0 deletions .github/workflows/release-containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release containers

on:
push:
tags: [ v* ]

jobs:
release-containers:
name: Build and release containers
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
module: ['plain', 'lambda']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/chialab/print2pdf
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
suffix=-${{ matrix.module }}
- name: Login to GitHub Packages
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: ${{ matrix.module }}
file: ${{ matrix.module }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
name: Run linter
runs-on: ubuntu-latest
strategy:
matrix:
module: ['plain', 'lambda']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
cache-dependency-path: ${{ matrix.module }}/go.sum
go-version-file: ${{ matrix.module }}/go.mod

- name: Linter
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: ${{ matrix.module }}
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
.PHONY: lambda plain
.PHONY: bin-plain bin-lambda docker-plain docker-lambda

IMAGE_NAME ?= print2pdf
IMAGE_TAG ?= dev

plain:
bin-plain:
CGO_ENABLED=0 go build -ldflags '-s' -o build/print2pdf-plain plain

bin-lambda:
CGO_ENABLED=0 go build -ldflags '-s' -o build/print2pdf-lambda lambda

docker-plain:
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) --file plain/Dockerfile plain/

lambda:
docker-lambda:
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) --file lambda/Dockerfile lambda/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="https://pkg.go.dev/github.com/chialab/print2pdf-go/print2pdf"><img src="https://pkg.go.dev/badge/github.com/chialab/print2pdf-go/print2pdf.svg" alt="Go Reference"></a>

0 comments on commit dbfd50e

Please sign in to comment.