# This workflow: # - 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 name: Build Release on: push: tags: ['v*'] branches: [ main ] jobs: build: name: Build ${{matrix.architecture}} runs-on: ubuntu-latest strategy: matrix: architecture: ['386', amd64, arm, arm64] steps: - uses: actions/checkout@v4 - name: Build for ${{matrix.architecture}} run: | env GOOS=windows GOARCH=${{matrix.architecture}} \ go build \ -ldflags "-s -w -X code.forgejo.org/forgejo/runner/internal/pkg/ver.version=${{ github.ref_name }}" \ -o forgejo-runner-windows-${{matrix.architecture}}.exe - uses: actions/upload-artifact@v4 with: name: forgejo-runner-windows-${{matrix.architecture}} 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: runs-on: ubuntu-latest needs: [build, test] if: github.event_name == 'push' && github.ref_type == 'tag' steps: - uses: actions/download-artifact@v4 with: path: . - name: Create Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.ref_name }} files: forgejo-runner-windows-*/forgejo-runner-windows-*.exe draft: false prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }} token: ${{ secrets.RELEASE_TOKEN }} fail_on_unmatched_files: true body: See [original release notes](https://code.forgejo.org/forgejo/runner/releases/tag/${{ github.ref_name }}).