mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-01 17:38:36 +00:00
145 lines
4.8 KiB
YAML
145 lines
4.8 KiB
YAML
name: Windows Tests
|
|
|
|
# This workflow runs tests on Windows with a Forgejo server running on Linux.
|
|
# It uses Windows Subsystem for Linux (WSL) to run the Forgejo server in a Docker container
|
|
# within the Windows runner, allowing network connectivity between the two.
|
|
#
|
|
# The workflow:
|
|
# 1. Sets up WSL with Alpine Linux
|
|
# 2. Installs Docker in WSL
|
|
# 3. Starts a Forgejo server in a Docker container within WSL
|
|
# 4. Creates an admin user and generates a runner token
|
|
# 5. Passes the runner token to the Windows environment
|
|
# 6. Waits for the Forgejo server to be accessible from Windows
|
|
# 7. Sets up the Forgejo connection and registers the runner
|
|
# 8. Runs the tests on Windows
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
env:
|
|
FORGEJO_ROOT_URL: 'http://localhost:3000/'
|
|
FORGEJO_RUNNER_SECRET: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
|
|
|
|
jobs:
|
|
test:
|
|
name: Run Tests on Windows with Linux Forgejo Server
|
|
runs-on: windows-latest
|
|
|
|
steps:
|
|
- name: Windows - Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Windows - Setup Windows Subsystem for Linux (WSL)
|
|
uses: Vampire/setup-wsl@v5
|
|
with:
|
|
distribution: Alpine
|
|
wsl-shell-user: root
|
|
additional-packages: bash
|
|
|
|
- name: WSL - Install Docker
|
|
shell: wsl-bash {0}
|
|
run: |
|
|
apk --update add --no-cache docker curl
|
|
rc-update add docker default
|
|
|
|
# Check if Docker is already running, if not start it and wait for it to be ready
|
|
if ! pgrep -x dockerd > /dev/null; then
|
|
service docker start
|
|
# Wait for Docker to be ready
|
|
echo "Waiting for Docker to be ready..."
|
|
timeout=30
|
|
for i in $(seq 1 $timeout); do
|
|
if docker info > /dev/null 2>&1; then
|
|
echo "Docker is ready!"
|
|
break
|
|
fi
|
|
echo "Waiting for Docker to be ready... ($i/$timeout)"
|
|
sleep 1
|
|
done
|
|
else
|
|
echo "Docker is ready!"
|
|
fi
|
|
|
|
- name: WSL - Start Forgejo Server
|
|
shell: wsl-bash {0}
|
|
run: |
|
|
docker run -d --name forgejo \
|
|
-p 3000:3000 \
|
|
-e USER_UID=1000 \
|
|
-e USER_GID=1000 \
|
|
-e FORGEJO__security__INSTALL_LOCK=true \
|
|
-e FORGEJO__server__DOMAIN=localhost \
|
|
-e FORGEJO__server__ROOT_URL=${{ env.FORGEJO_ROOT_URL }} \
|
|
codeberg.org/forgejo/forgejo:11.0-rootless
|
|
|
|
# Wait for Forgejo to be ready
|
|
for i in {1..30}; do
|
|
if curl -s ${{ env.FORGEJO_ROOT_URL }}/api/v1/version > /dev/null; then
|
|
echo "Forgejo is ready!"
|
|
break
|
|
fi
|
|
echo "Waiting for Forgejo to be ready... ($i/30)"
|
|
sleep 5
|
|
done
|
|
|
|
# Create admin user and generate runner token
|
|
docker exec forgejo forgejo admin create-user --username test-admin --password test-password --email test@example.com --admin
|
|
docker exec forgejo forgejo forgejo-cli actions register --secret ${{ env.FORGEJO_RUNNER_SECRET }}
|
|
|
|
- name: Windows - Wait for Forgejo to be accessible
|
|
run: |
|
|
$retries = 0
|
|
$maxRetries = 30
|
|
do {
|
|
try {
|
|
$response = Invoke-WebRequest -Uri "${{ env.FORGEJO_ROOT_URL }}api/v1/version" -UseBasicParsing
|
|
if ($response.StatusCode -eq 200) {
|
|
Write-Host "Forgejo is accessible from Windows!"
|
|
break
|
|
}
|
|
} catch {
|
|
Write-Host "Waiting for Forgejo to be accessible from Windows... ($retries/$maxRetries)"
|
|
}
|
|
$retries++
|
|
Start-Sleep -Seconds 5
|
|
} while ($retries -lt $maxRetries)
|
|
|
|
if ($retries -ge $maxRetries) {
|
|
Write-Error "Forgejo did not become accessible in time"
|
|
exit 1
|
|
}
|
|
|
|
- name: Windows - Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Windows - Install dependencies
|
|
run: go mod download
|
|
|
|
- name: Windows - Setup Forgejo connection
|
|
run: |
|
|
# Create a temporary config file
|
|
$configContent = @"
|
|
log:
|
|
level: debug
|
|
runner:
|
|
labels:
|
|
- windows:host
|
|
- docker:docker://node:20
|
|
"@
|
|
Set-Content -Path config.yml -Value $configContent
|
|
|
|
# Register the runner
|
|
go run main.go create-runner-file --config config.yml --instance ${{ env.FORGEJO_ROOT_URL }} --secret ${{ env.FORGEJO_RUNNER_SECRET }} --name "windows-test-runner"
|
|
|
|
- name: Windows - Run tests
|
|
run: go test -v ./...
|
|
env:
|
|
FORGEJO_URL: http://localhost:3000
|
|
FORGEJO_RUNNER_SECRET: ${{ env.RUNNER_TOKEN }}
|
|
FORGEJO_RUNNER_HEX_SECRET: ${{ env.RUNNER_HEX_TOKEN }}
|