Skip to content

Commit a3d3106

Browse files
committed
feat: add workflow for ci
1 parent bd57c48 commit a3d3106

5 files changed

Lines changed: 115 additions & 7 deletions

File tree

.github/workflows/integration.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Proxy Integration Tests
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
build:
7+
type: boolean
8+
description: Build from current tag before running tests
9+
10+
jobs:
11+
determine-tag:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
version: ${{ steps.metadata.outputs.VERSION }}
15+
commit_hash: ${{ steps.metadata.outputs.COMMIT_HASH }}
16+
build_timestamp: ${{ steps.metadata.outputs.BUILD_TIMESTAMP }}
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Determine metadata
22+
id: metadata
23+
run: |
24+
# Generate static metadata
25+
echo "COMMIT_HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
26+
echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%dT%H:%M:%S')" >> "$GITHUB_OUTPUT"
27+
28+
# Determine version
29+
if [ "${{ inputs.build }}" == "true" ]; then
30+
echo "VERSION=development" >> "$GITHUB_OUTPUT"
31+
else
32+
echo "VERSION=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
33+
fi
34+
35+
integration:
36+
runs-on: ubuntu-latest
37+
needs: determine-tag
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Setup Go
43+
uses: actions/setup-go@v6
44+
with:
45+
go-version: "1.25.0"
46+
47+
- name: Initialize submodules
48+
run: |
49+
git submodule init
50+
git submodule update
51+
52+
- name: Apply patches
53+
run: |
54+
git apply --directory paerser/ patches/nested_maps.diff
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
if: ${{ inputs.build == 'true' }}
59+
60+
- name: Build
61+
uses: docker/build-push-action@v6
62+
if: ${{ inputs.build == 'true' }}
63+
with:
64+
platforms: linux/amd64
65+
tags: ghcr.io/${{ github.repository_owner }}/tinyauth:${{ needs.determine-tag.outputs.version }}
66+
outputs: type=image,push=false
67+
cache-from: type=gha
68+
cache-to: type=gha,mode=max
69+
build-args: |
70+
VERSION=${{ needs.determine-tag.outputs.version }}
71+
COMMIT_HASH=${{ needs.determine-tag.outputs.commit_hash }}
72+
BUILD_TIMESTAMP=${{ needs.determine-tag.outputs.build_timestamp }}
73+
74+
- name: Set tinyauth version
75+
run: |
76+
sed -i "s/TINYAUTH_VERSION=.*/TINYAUTH_VERSION=${{ needs.determine-tag.outputs.version }}/" integration/.env
77+
78+
- name: Test
79+
run: make integration

.github/workflows/release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ jobs:
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v4
18-
with:
19-
ref: nightly
2018

2119
- name: Generate metadata
2220
id: metadata

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,11 @@ sql:
8181
sqlc generate
8282

8383
# Go gen
84+
.PHONY: generate
8485
generate:
8586
go run ./gen
87+
88+
# Proxy integration tests
89+
.PHONY: integration
90+
integration:
91+
go run ./integration -- --log=false

integration/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ WHOAMI_HOST=whoami.127.0.0.1.sslip.io
1313
ENVOY_VERSION=v1.33-latest
1414

1515
# Tinyauth configuration
16-
TINYAUTH_VERSION=dev
16+
TINYAUTH_VERSION=latest

integration/integration.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"os/exec"
13+
"path"
1314
"time"
1415
)
1516

@@ -34,14 +35,36 @@ func main() {
3435
logFlag := flag.Bool("log", false, "enable stack logging")
3536
flag.Parse()
3637

38+
rootFolder, err := os.Getwd()
39+
40+
if err != nil {
41+
slog.Error("fail", "error", err)
42+
os.Exit(1)
43+
}
44+
45+
slog.Info("root folder", "folder", rootFolder)
46+
47+
integrationRoot := rootFolder
48+
49+
if _, err := os.Stat(path.Join(rootFolder, ".git")); err != nil {
50+
if !errors.Is(err, os.ErrNotExist) {
51+
slog.Error("fail", "error", err)
52+
os.Exit(1)
53+
}
54+
} else {
55+
integrationRoot = path.Join(rootFolder, "integration")
56+
}
57+
58+
slog.Info("integration root", "folder", integrationRoot)
59+
3760
for _, proxy := range ProxiesToTest {
3861
slog.Info("begin", "proxy", proxy)
3962
compose := fmt.Sprintf("docker-compose.%s.yml", proxy)
40-
if _, err := os.Stat(compose); err != nil {
63+
if _, err := os.Stat(path.Join(integrationRoot, compose)); err != nil {
4164
slog.Error("fail", "proxy", proxy, "error", err)
4265
os.Exit(1)
4366
}
44-
if err := createInstanceAndRunTests(compose, *logFlag, proxy); err != nil {
67+
if err := createInstanceAndRunTests(compose, *logFlag, proxy, integrationRoot); err != nil {
4568
slog.Error("fail", "proxy", proxy, "error", err)
4669
os.Exit(1)
4770
}
@@ -74,11 +97,13 @@ func runTests(client *http.Client, name string) error {
7497
return nil
7598
}
7699

77-
func createInstanceAndRunTests(compose string, log bool, name string) error {
100+
func createInstanceAndRunTests(compose string, log bool, name string, integrationDir string) error {
78101
ctx, cancel := context.WithCancel(context.Background())
79102
defer cancel()
80103

81-
cmdArgs := []string{"compose", "-f", compose, "--env-file", EnvFile, "up", "--build", "--force-recreate", "--remove-orphans"}
104+
composeFile := path.Join(integrationDir, compose)
105+
envFile := path.Join(integrationDir, EnvFile)
106+
cmdArgs := []string{"compose", "-f", composeFile, "--env-file", envFile, "up", "--build", "--force-recreate", "--remove-orphans"}
82107
cmd := exec.CommandContext(ctx, "docker", cmdArgs...)
83108

84109
if log {

0 commit comments

Comments
 (0)