mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-06-27 16:35:58 +00:00
Add tests to Windows build (#585)
The PR adds testing of the runner code on Windows, including communication with a Forgejo server running on WSL. Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/585 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Crown0815 <felix.kroener@gmx.de> Co-committed-by: Crown0815 <felix.kroener@gmx.de>
This commit is contained in:
parent
059ed2d9ea
commit
5a3d0bba9e
1 changed files with 107 additions and 5 deletions
112
.github/workflows/build-release.yml
vendored
112
.github/workflows/build-release.yml
vendored
|
@ -1,12 +1,17 @@
|
||||||
# This workflow will build a Windows binary for each architecture and upload it as an artifact.
|
# This workflow:
|
||||||
# If the push is a tag, it will create a release with the binaries attached.
|
# - builds and uploads a binary artifact for each Windows architecture
|
||||||
|
# - tests the runner on Windows with a Forgejo server container running on Windows Subsystem for Linux (WSL)
|
||||||
|
# - releases the binary artifact (if triggered on a pushed tag)
|
||||||
|
#
|
||||||
# This build is currently supported on https://github.com/Crown0815/forgejo-runner-windows
|
# This build is currently supported on https://github.com/Crown0815/forgejo-runner-windows
|
||||||
|
|
||||||
name: Build release
|
name: Build Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags: 'v*'
|
tags: ['v*']
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build ${{matrix.architecture}}
|
name: Build ${{matrix.architecture}}
|
||||||
|
@ -28,9 +33,106 @@ jobs:
|
||||||
name: forgejo-runner-windows-${{matrix.architecture}}
|
name: forgejo-runner-windows-${{matrix.architecture}}
|
||||||
path: forgejo-runner-windows-${{matrix.architecture}}.exe
|
path: forgejo-runner-windows-${{matrix.architecture}}.exe
|
||||||
|
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Run Tests on Windows with Linux Forgejo Server
|
||||||
|
runs-on: windows-latest
|
||||||
|
env:
|
||||||
|
FORGEJO_ROOT_URL: 'http://localhost:3000/'
|
||||||
|
FORGEJO_ADMIN_USER: 'admin_user'
|
||||||
|
FORGEJO_ADMIN_PASSWORD: 'admin_password'
|
||||||
|
FORGEJO_RUNNER_SECRET: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
|
||||||
|
MAX_WAIT_ITERATIONS: 30
|
||||||
|
|
||||||
|
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
|
||||||
|
openrc default
|
||||||
|
|
||||||
|
# Wait for Docker to be ready
|
||||||
|
i=0
|
||||||
|
until docker info > /dev/null 2>&1 || (( i == ${{ env.MAX_WAIT_ITERATIONS }} )); do
|
||||||
|
echo "Waiting for Docker to be ready... ($(( ++i ))/${{ env.MAX_WAIT_ITERATIONS }})"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
[ $i -lt ${{ env.MAX_WAIT_ITERATIONS }} ] && echo "Docker is ready!" || { echo "Timed out waiting for Docker" ; exit 1; }
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- 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: WSL - Register Runner on Forgejo Server
|
||||||
|
# Starting the Forgejo server takes some time.
|
||||||
|
# That time used to install go.
|
||||||
|
shell: wsl-bash {0}
|
||||||
|
run: |
|
||||||
|
i=0
|
||||||
|
until curl -s ${{ env.FORGEJO_ROOT_URL }}/api/v1/version > /dev/null || (( i == ${{ env.MAX_WAIT_ITERATIONS }} )); do
|
||||||
|
echo "Waiting for Forgejo to be ready... ($(( ++i ))/${{ env.MAX_WAIT_ITERATIONS }})"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
[ $i -lt ${{ env.MAX_WAIT_ITERATIONS }} ] && echo "Forgejo is ready!" || { echo "Timed out waiting for Forgejo" ; exit 1; }
|
||||||
|
|
||||||
|
# Create admin user and generate runner token
|
||||||
|
docker exec forgejo forgejo admin user create --admin --username ${{ env.FORGEJO_ADMIN_USER }} --password ${{ env.FORGEJO_ADMIN_PASSWORD }} --email root@example.com
|
||||||
|
docker exec forgejo forgejo forgejo-cli actions register --labels docker --name therunner --secret ${{ env.FORGEJO_RUNNER_SECRET }}
|
||||||
|
|
||||||
|
- name: Windows - Connect to Forgejo server
|
||||||
|
run: |
|
||||||
|
$configFileContent = @"
|
||||||
|
log:
|
||||||
|
level: debug
|
||||||
|
runner:
|
||||||
|
labels:
|
||||||
|
- windows:host
|
||||||
|
- docker:docker://node:20
|
||||||
|
"@
|
||||||
|
Set-Content -Path temporaryConfig.yml -Value $configFileContent
|
||||||
|
|
||||||
|
# Register the runner
|
||||||
|
go run main.go create-runner-file --config temporaryConfig.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: ${{ env.FORGEJO_ROOT_URL }}
|
||||||
|
FORGEJO_RUNNER_SECRET: ${{ env.FORGEJO_RUNNER_SECRET }}
|
||||||
|
FORGEJO_RUNNER_HEX_SECRET: ${{ env.FORGEJO_RUNNER_SECRET }}
|
||||||
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: [build, test]
|
||||||
if: github.event_name == 'push' && github.ref_type == 'tag'
|
if: github.event_name == 'push' && github.ref_type == 'tag'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/download-artifact@v4
|
- uses: actions/download-artifact@v4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue