Run tests in CI and build multi-arch Docker images
- Build (main, develop): vet and unit tests, then a linux/amd64 and linux/arm64 image build without pushing - Publish (version branches): same tests, then build and push both platforms - Integration tests (manual): run the testcontainers suite
This commit is contained in:
1 parent
59dfff38bc
commit
bd250ecaee
3 files changed
+54
-68
No files matched your search
@@ -1,9 +1,5 @@
|
|||||||
|
|
||||||
name: Build
|
name: Build
|
||||||
|
|
||||||
#on:
|
|
||||||
# release:
|
|
||||||
# types: [published]
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@@ -11,32 +7,42 @@ on:
|
|||||||
- develop
|
- develop
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# test:
|
test:
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - run: echo "The release ${{ gitea.ref }} ${{ gitea.ref_name }} was published"
|
|
||||||
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: https://github.com/actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
- name: Generate templ components
|
||||||
|
run: go tool templ generate
|
||||||
|
- name: Vet
|
||||||
|
run: go vet ./...
|
||||||
|
- name: Unit tests
|
||||||
|
run: go test -race ./...
|
||||||
|
|
||||||
|
docker:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: https://github.com/docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
config-inline: |
|
config-inline: |
|
||||||
[registry."gitea.sanplex.xyz/sansan"]
|
[registry."gitea.sanplex.xyz/sansan"]
|
||||||
http = true
|
http = true
|
||||||
insecure = true
|
insecure = true
|
||||||
- name: Login to Gitea
|
- name: Login to Gitea
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: gitea.sanplex.xyz
|
registry: gitea.sanplex.xyz
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.TOKEN }}
|
password: ${{ secrets.TOKEN }}
|
||||||
- name: Build
|
- name: Build
|
||||||
uses: https://github.com/docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
push: false
|
push: false
|
||||||
#tags: "gitea.sanplex.xyz/sansan/musicserver:${{gitea.ref_name}}, gitea.sanplex.xyz/sansan/musicserver:latest"
|
|
||||||
@@ -1,41 +1,50 @@
|
|||||||
|
|
||||||
name: Publish
|
name: Publish
|
||||||
|
|
||||||
#on:
|
|
||||||
# release:
|
|
||||||
# types: [published]
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '*.*'
|
- '*.*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# test:
|
test:
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - run: echo "The release ${{ gitea.ref }} ${{ gitea.ref_name }} was published"
|
|
||||||
|
|
||||||
publish:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: https://github.com/actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
- name: Generate templ components
|
||||||
|
run: go tool templ generate
|
||||||
|
- name: Vet
|
||||||
|
run: go vet ./...
|
||||||
|
- name: Unit tests
|
||||||
|
run: go test -race ./...
|
||||||
|
|
||||||
|
publish:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: https://github.com/docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
config-inline: |
|
config-inline: |
|
||||||
[registry."gitea.sanplex.xyz/sansan"]
|
[registry."gitea.sanplex.xyz/sansan"]
|
||||||
http = true
|
http = true
|
||||||
insecure = true
|
insecure = true
|
||||||
- name: Login to Gitea
|
- name: Login to Gitea
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: gitea.sanplex.xyz
|
registry: gitea.sanplex.xyz
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.TOKEN }}
|
password: ${{ secrets.TOKEN }}
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: https://github.com/docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: "gitea.sanplex.xyz/sansan/musicserver:${{gitea.ref_name}}, gitea.sanplex.xyz/sansan/musicserver:latest"
|
tags: |
|
||||||
|
gitea.sanplex.xyz/sansan/musicserver:${{ gitea.ref_name }}
|
||||||
|
gitea.sanplex.xyz/sansan/musicserver:latest
|
||||||
@@ -5,43 +5,14 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
integration-test:
|
integration-test:
|
||||||
|
# Needs access to a Docker daemon: the tests start PostgreSQL with testcontainers.
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
|
||||||
image: golang:1.25
|
|
||||||
options: --privileged
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:15-alpine
|
|
||||||
env:
|
|
||||||
POSTGRES_USER: testuser
|
|
||||||
POSTGRES_PASSWORD: testpass
|
|
||||||
POSTGRES_DB: music_server_test
|
|
||||||
ports:
|
|
||||||
- 5432:5432
|
|
||||||
options: >-
|
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 10s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 5
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
- name: Install dependencies
|
go-version-file: go.mod
|
||||||
run: go mod download
|
- name: Generate templ components
|
||||||
|
run: go tool templ generate
|
||||||
- name: Install testcontainers
|
- name: Integration tests
|
||||||
run: go install github.com/testcontainers/testcontainers-go@latest
|
run: go test -tags integration -race -timeout 15m ./...
|
||||||
|
|
||||||
- name: Run integration tests
|
|
||||||
env:
|
|
||||||
DB_HOST: postgres
|
|
||||||
DB_PORT: 5432
|
|
||||||
DB_USERNAME: testuser
|
|
||||||
DB_PASSWORD: testpass
|
|
||||||
DB_NAME: music_server_test
|
|
||||||
MUSIC_PATH: ./testMusic
|
|
||||||
CHARACTERS_PATH: ./testCharacters
|
|
||||||
run: go test -v -timeout 30m ./...
|
|
||||||
Reference in new issue
Block a user