Skip to content

Commit 7a02f8e

Browse files
earl-warrenearl-warren
authored andcommitted
chore: restore GitHub windows build workflow (#815)
Incorrectly removed in bc71649 Refs https://code.forgejo.org/forgejo/runner/pulls/767 <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - other - [PR](https://code.forgejo.org/forgejo/runner/pulls/815): <!--number 815 --><!--line 0 --><!--description Y2hvcmU6IHJlc3RvcmUgR2l0SHViIHdpbmRvd3MgYnVpbGQgd29ya2Zsb3c=-->chore: restore GitHub windows build workflow<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/815 Reviewed-by: Michael Kriese <[email protected]> Co-authored-by: Earl Warren <[email protected]> Co-committed-by: Earl Warren <[email protected]>
1 parent 79285e8 commit 7a02f8e

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

.github/workflows/build-release.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# This workflow:
2+
# - builds and uploads a binary artifact for each Windows architecture
3+
# - tests the runner on Windows with a Forgejo server container running on Windows Subsystem for Linux (WSL)
4+
# - releases the binary artifact (if triggered on a pushed tag)
5+
#
6+
# This build is currently supported on https://github.com/Crown0815/forgejo-runner-windows
7+
8+
name: Build Release
9+
10+
on:
11+
push:
12+
tags: ['v*']
13+
branches: [ main ]
14+
15+
jobs:
16+
build:
17+
name: Build ${{matrix.architecture}}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
architecture: ['386', amd64, arm, arm64]
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Build for ${{matrix.architecture}}
25+
run: |
26+
env GOOS=windows GOARCH=${{matrix.architecture}} \
27+
go build \
28+
-ldflags "-s -w -X code.forgejo.org/forgejo/runner/internal/pkg/ver.version=${{ github.ref_name }}" \
29+
-o forgejo-runner-windows-${{matrix.architecture}}.exe
30+
31+
- uses: actions/upload-artifact@v4
32+
with:
33+
name: forgejo-runner-windows-${{matrix.architecture}}
34+
path: forgejo-runner-windows-${{matrix.architecture}}.exe
35+
36+
37+
test:
38+
name: Run Tests on Windows with Linux Forgejo Server
39+
runs-on: windows-latest
40+
env:
41+
FORGEJO_ROOT_URL: 'http://localhost:3000/'
42+
FORGEJO_ADMIN_USER: 'admin_user'
43+
FORGEJO_ADMIN_PASSWORD: 'admin_password'
44+
FORGEJO_RUNNER_SECRET: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
45+
MAX_WAIT_ITERATIONS: 30
46+
47+
steps:
48+
- name: Windows - Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Windows - Setup Windows Subsystem for Linux (WSL)
52+
uses: Vampire/setup-wsl@v5
53+
with:
54+
distribution: Alpine
55+
wsl-shell-user: root
56+
additional-packages: bash
57+
58+
- name: WSL - Install Docker
59+
shell: wsl-bash {0}
60+
run: |
61+
apk --update add --no-cache docker curl
62+
63+
rc-update add docker default
64+
openrc default
65+
66+
# Wait for Docker to be ready
67+
i=0
68+
until docker info > /dev/null 2>&1 || (( i == ${{ env.MAX_WAIT_ITERATIONS }} )); do
69+
echo "Waiting for Docker to be ready... ($(( ++i ))/${{ env.MAX_WAIT_ITERATIONS }})"
70+
sleep 1
71+
done
72+
[ $i -lt ${{ env.MAX_WAIT_ITERATIONS }} ] && echo "Docker is ready!" || { echo "Timed out waiting for Docker" ; exit 1; }
73+
74+
- name: WSL - Start Forgejo Server
75+
shell: wsl-bash {0}
76+
run: |
77+
docker run -d --name forgejo \
78+
-p 3000:3000 \
79+
-e USER_UID=1000 \
80+
-e USER_GID=1000 \
81+
-e FORGEJO__security__INSTALL_LOCK=true \
82+
-e FORGEJO__server__DOMAIN=localhost \
83+
-e FORGEJO__server__ROOT_URL=${{ env.FORGEJO_ROOT_URL }} \
84+
codeberg.org/forgejo/forgejo:11.0-rootless
85+
86+
- name: Windows - Set up Go
87+
uses: actions/setup-go@v5
88+
with:
89+
go-version-file: go.mod
90+
91+
- name: Windows - Install dependencies
92+
run: go mod download
93+
94+
- name: WSL - Register Runner on Forgejo Server
95+
# Starting the Forgejo server takes some time.
96+
# That time used to install go.
97+
shell: wsl-bash {0}
98+
run: |
99+
i=0
100+
until curl -s ${{ env.FORGEJO_ROOT_URL }}/api/v1/version > /dev/null || (( i == ${{ env.MAX_WAIT_ITERATIONS }} )); do
101+
echo "Waiting for Forgejo to be ready... ($(( ++i ))/${{ env.MAX_WAIT_ITERATIONS }})"
102+
sleep 1
103+
done
104+
[ $i -lt ${{ env.MAX_WAIT_ITERATIONS }} ] && echo "Forgejo is ready!" || { echo "Timed out waiting for Forgejo" ; exit 1; }
105+
106+
# Create admin user and generate runner token
107+
docker exec forgejo forgejo admin user create --admin --username ${{ env.FORGEJO_ADMIN_USER }} --password ${{ env.FORGEJO_ADMIN_PASSWORD }} --email [email protected]
108+
docker exec forgejo forgejo forgejo-cli actions register --labels docker --name therunner --secret ${{ env.FORGEJO_RUNNER_SECRET }}
109+
110+
- name: Windows - Connect to Forgejo server
111+
run: |
112+
$configFileContent = @"
113+
log:
114+
level: debug
115+
runner:
116+
labels:
117+
- windows:host
118+
- docker:docker://node:20
119+
"@
120+
Set-Content -Path temporaryConfig.yml -Value $configFileContent
121+
122+
# Register the runner
123+
go run main.go create-runner-file --config temporaryConfig.yml --instance ${{ env.FORGEJO_ROOT_URL }} --secret ${{ env.FORGEJO_RUNNER_SECRET }} --name "windows-test-runner"
124+
125+
- name: Windows - Run tests
126+
run: go test -v ./...
127+
env:
128+
FORGEJO_URL: ${{ env.FORGEJO_ROOT_URL }}
129+
FORGEJO_RUNNER_SECRET: ${{ env.FORGEJO_RUNNER_SECRET }}
130+
FORGEJO_RUNNER_HEX_SECRET: ${{ env.FORGEJO_RUNNER_SECRET }}
131+
132+
133+
release:
134+
runs-on: ubuntu-latest
135+
needs: [build, test]
136+
if: github.event_name == 'push' && github.ref_type == 'tag'
137+
steps:
138+
- uses: actions/download-artifact@v4
139+
with:
140+
path: .
141+
142+
- name: Create Release
143+
uses: softprops/action-gh-release@v2
144+
with:
145+
tag_name: ${{ github.ref_name }}
146+
files: forgejo-runner-windows-*/forgejo-runner-windows-*.exe
147+
draft: false
148+
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}
149+
token: ${{ secrets.RELEASE_TOKEN }}
150+
fail_on_unmatched_files: true
151+
body: See [original release notes](https://code.forgejo.org/forgejo/runner/releases/tag/${{ github.ref_name }}).

0 commit comments

Comments
 (0)