feat: add workflow for ci

This commit is contained in:
Stavros
2026-03-14 20:24:37 +02:00
parent bd57c480f3
commit a3d310667b
5 changed files with 115 additions and 7 deletions

79
.github/workflows/integration.yml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: Proxy Integration Tests
on:
workflow_dispatch:
inputs:
build:
type: boolean
description: Build from current tag before running tests
jobs:
determine-tag:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.metadata.outputs.VERSION }}
commit_hash: ${{ steps.metadata.outputs.COMMIT_HASH }}
build_timestamp: ${{ steps.metadata.outputs.BUILD_TIMESTAMP }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Determine metadata
id: metadata
run: |
# Generate static metadata
echo "COMMIT_HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%dT%H:%M:%S')" >> "$GITHUB_OUTPUT"
# Determine version
if [ "${{ inputs.build }}" == "true" ]; then
echo "VERSION=development" >> "$GITHUB_OUTPUT"
else
echo "VERSION=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
integration:
runs-on: ubuntu-latest
needs: determine-tag
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: "1.25.0"
- name: Initialize submodules
run: |
git submodule init
git submodule update
- name: Apply patches
run: |
git apply --directory paerser/ patches/nested_maps.diff
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: ${{ inputs.build == 'true' }}
- name: Build
uses: docker/build-push-action@v6
if: ${{ inputs.build == 'true' }}
with:
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/tinyauth:${{ needs.determine-tag.outputs.version }}
outputs: type=image,push=false
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.determine-tag.outputs.version }}
COMMIT_HASH=${{ needs.determine-tag.outputs.commit_hash }}
BUILD_TIMESTAMP=${{ needs.determine-tag.outputs.build_timestamp }}
- name: Set tinyauth version
run: |
sed -i "s/TINYAUTH_VERSION=.*/TINYAUTH_VERSION=${{ needs.determine-tag.outputs.version }}/" integration/.env
- name: Test
run: make integration

View File

@@ -15,8 +15,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: nightly
- name: Generate metadata
id: metadata

View File

@@ -81,5 +81,11 @@ sql:
sqlc generate
# Go gen
.PHONY: generate
generate:
go run ./gen
# Proxy integration tests
.PHONY: integration
integration:
go run ./integration -- --log=false

View File

@@ -13,4 +13,4 @@ WHOAMI_HOST=whoami.127.0.0.1.sslip.io
ENVOY_VERSION=v1.33-latest
# Tinyauth configuration
TINYAUTH_VERSION=dev
TINYAUTH_VERSION=latest

View File

@@ -10,6 +10,7 @@ import (
"net/http"
"os"
"os/exec"
"path"
"time"
)
@@ -34,14 +35,36 @@ func main() {
logFlag := flag.Bool("log", false, "enable stack logging")
flag.Parse()
rootFolder, err := os.Getwd()
if err != nil {
slog.Error("fail", "error", err)
os.Exit(1)
}
slog.Info("root folder", "folder", rootFolder)
integrationRoot := rootFolder
if _, err := os.Stat(path.Join(rootFolder, ".git")); err != nil {
if !errors.Is(err, os.ErrNotExist) {
slog.Error("fail", "error", err)
os.Exit(1)
}
} else {
integrationRoot = path.Join(rootFolder, "integration")
}
slog.Info("integration root", "folder", integrationRoot)
for _, proxy := range ProxiesToTest {
slog.Info("begin", "proxy", proxy)
compose := fmt.Sprintf("docker-compose.%s.yml", proxy)
if _, err := os.Stat(compose); err != nil {
if _, err := os.Stat(path.Join(integrationRoot, compose)); err != nil {
slog.Error("fail", "proxy", proxy, "error", err)
os.Exit(1)
}
if err := createInstanceAndRunTests(compose, *logFlag, proxy); err != nil {
if err := createInstanceAndRunTests(compose, *logFlag, proxy, integrationRoot); err != nil {
slog.Error("fail", "proxy", proxy, "error", err)
os.Exit(1)
}
@@ -74,11 +97,13 @@ func runTests(client *http.Client, name string) error {
return nil
}
func createInstanceAndRunTests(compose string, log bool, name string) error {
func createInstanceAndRunTests(compose string, log bool, name string, integrationDir string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cmdArgs := []string{"compose", "-f", compose, "--env-file", EnvFile, "up", "--build", "--force-recreate", "--remove-orphans"}
composeFile := path.Join(integrationDir, compose)
envFile := path.Join(integrationDir, EnvFile)
cmdArgs := []string{"compose", "-f", composeFile, "--env-file", envFile, "up", "--build", "--force-recreate", "--remove-orphans"}
cmd := exec.CommandContext(ctx, "docker", cmdArgs...)
if log {