From dbfd50ef4f68cec63416e499356fd08886802f05 Mon Sep 17 00:00:00 2001 From: le0m Date: Mon, 5 Aug 2024 14:56:59 +0200 Subject: [PATCH] chore: add workflows --- .github/workflows/codeql-analysis.yml | 43 ++++++++++++++++ .github/workflows/dependency-submission.yml | 33 +++++++++++++ .github/workflows/publish-package.yml | 26 ++++++++++ .github/workflows/release-binaries.yml | 51 +++++++++++++++++++ .github/workflows/release-containers.yml | 55 +++++++++++++++++++++ .github/workflows/test.yml | 31 ++++++++++++ Makefile | 12 +++-- README.md | 1 + 8 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/dependency-submission.yml create mode 100644 .github/workflows/publish-package.yml create mode 100644 .github/workflows/release-binaries.yml create mode 100644 .github/workflows/release-containers.yml create mode 100644 .github/workflows/test.yml create mode 100644 README.md diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..6724ffb --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -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' diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml new file mode 100644 index 0000000..fd1c47a --- /dev/null +++ b/.github/workflows/dependency-submission.yml @@ -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 diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml new file mode 100644 index 0000000..30d12f9 --- /dev/null +++ b/.github/workflows/publish-package.yml @@ -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/}" diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml new file mode 100644 index 0000000..5545295 --- /dev/null +++ b/.github/workflows/release-binaries.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/release-containers.yml b/.github/workflows/release-containers.yml new file mode 100644 index 0000000..8c73b32 --- /dev/null +++ b/.github/workflows/release-containers.yml @@ -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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..0be16e2 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/Makefile b/Makefile index 14ad861..46c37b6 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..9335732 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Go Reference