Skip to content

Commit

Permalink
chore: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Dec 26, 2023
1 parent 969cdc6 commit ee7e4af
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
- 'assets/**'
- '**/*.gitignore'
- '**/*.md'
pull_request:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
- 'assets/**'
- '**/*.gitignore'
- '**/*.md'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Set up Go
uses: actions/setup-go@v3
with:
cache: false
go-version-file: go.mod

- name: Verify gofmt
run: |
go fmt ./... && git add cmd internal models pkg &&
git diff --cached --exit-code || (echo 'Please run "make fmt" to verify gofmt' && exit 1);
- name: Verify govet
run: |
go vet ./... && git add cmd internal models pkg &&
git diff --cached --exit-code || (echo 'Please run "make vet" to verify govet' && exit 1);
- name: Build
run: CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o aoa .
83 changes: 83 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Release

on:
workflow_dispatch:
inputs:
tag:
default: 'latest'
required: true
description: 'Docker image tag'
push:
tags:
- 'v*'

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to the GPR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Parse Tag Name
run: |
if [ x${{ github.event.inputs.tag }} == x"" ]; then
echo "TAG_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
fi
- name: Build and push
uses: docker/build-push-action@v4
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1 # https://github.com/orgs/community/discussions/45969
with:
platforms: linux/amd64,linux/arm64
push: true
pull: true
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.licenses=Apache-2.0
tags: |
${{ github.repository }}:${{ env.TAG_NAME }}
ghcr.io/${{ github.repository }}:${{ env.TAG_NAME }}
cache-from: type=gha # https://docs.docker.com/build/cache/backends/gha/
cache-to: type=gha,mode=max

goreleaser:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.tag == '' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Set up Go
uses: actions/setup-go@v4
with:
cache: false
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88 changes: 88 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Make sure to check the documentation at https://goreleaser.com
env:
- GIT_URL=https://github.com/soulteary/amazing-openai-api
before:
hooks:
- go mod tidy
builds:
- id: amazing-openai-api
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
main: ./cmd
binary: aoa
flags:
- -trimpath
ldflags:
- -s -w
- -X main.version={{ .Version }}
- -X main.buildDate={{ .Date }}
- -X main.gitCommit={{ .Commit }}

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"

# https://goreleaser.com/customization/changelog/
changelog:
sort: asc
use: github
filters:
exclude:
- '^build:'
- '^ci:'
# - '^docs:'
- '^test:'
- '^chore:'
- '^feat(deps):'
- 'merge conflict'
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
- '^Update'
groups:
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 300
- title: 'New Features'
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: 'Security updates'
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
order: 150
- title: 'Bug fixes'
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: 'Documentation updates'
regexp: '^.*?doc(\([[:word:]]+\))??!?:.+$'
order: 400
# - title: 'Build process updates'
# regexp: '^.*?build(\([[:word:]]+\))??!?:.+$'
# order: 400
- title: Other work
order: 9999
release:
footer: |
**Full Changelog**: https://github.com/soulteary/amazing-openai-api/compare/{{ .PreviousTag }}...{{ .Tag }}

0 comments on commit ee7e4af

Please sign in to comment.