@@ -24,6 +24,64 @@ def SetGithubStatus(githubToken, context, targetUrl, desc, status, repoOwner, re
2424 """
2525}
2626
27+ def WaitForGithubAction (githubToken , repoOwner , repoName , gitHash , actionName )
28+ {
29+ def maxAttempts = 30 // 5 minutes with 10-second intervals
30+ def attempt = 0
31+
32+ while (attempt < maxAttempts) {
33+ def status = bash("""
34+ curl -s \\
35+ -H "Authorization: Bearer ${ githubToken} " \\
36+ "https://api.github.com/repos/${ repoOwner} /${ repoName} /commits/${ gitHash} /status" |
37+ jq -r '.statuses[] | select(.context == "${ actionName} ") | .state'
38+ """ , true ). trim()
39+ // """
40+ if (status == " success" ) {
41+ return true
42+ } else if (status == " failure" || status == " error" ) {
43+ error " GitHub Action ${ actionName} failed"
44+ }
45+
46+ sleep 10
47+ attempt++
48+ }
49+
50+ error " Timeout waiting for GitHub Action ${ actionName} to complete"
51+ }
52+
53+ def UploadArtifactToGithub (githubToken , repoOwner , repoName , tagName , artifactPath , artifactName )
54+ {
55+ bash """
56+ # Create a release if it doesn't exist
57+ RELEASE_ID=\$ (curl -s \\
58+ -H "Authorization: Bearer ${ githubToken} " \\
59+ "https://api.github.com/repos/${ repoOwner} /${ repoName} /releases/tags/${ tagName} " | jq -r '.id')
60+
61+ if [ "\$ RELEASE_ID" = "null" ]; then
62+ RELEASE_ID=\$ (curl -s -X POST \\
63+ -H "Accept: application/vnd.github+json" \\
64+ -H "Authorization: Bearer ${ githubToken} " \\
65+ -H "X-GitHub-Api-Version: 2022-11-28" \\
66+ -d '{
67+ "tag_name": "${ tagName} ",
68+ "name": "Nightly Build ${ BUILD_NUMBER} ",
69+ "body": "Automated nightly build from Jenkins pipeline"
70+ }' \\
71+ "https://api.github.com/repos/${ repoOwner} /${ repoName} /releases" | jq -r '.id')
72+ fi
73+
74+ # Upload the artifact
75+ curl -L --fail-with-body \\
76+ -X POST \\
77+ -H "Accept: application/vnd.github+json" \\
78+ -H "Authorization: Bearer ${ githubToken} " \\
79+ -H "Content-Type: application/octet-stream" \\
80+ --data-binary "@${ artifactPath} " \\
81+ "https://uploads.github.com/repos/${ repoOwner} /${ repoName} /releases/\$ {RELEASE_ID}/assets?name=${ artifactName} "
82+ """
83+ }
84+
2785def REPO_OWNER = " Neko-Box-Coder"
2886def REPO_NAME = " runcpp2"
2987def TARGET_URL = ' https://github.com/Neko-Box-Coder/runcpp2.git'
@@ -339,6 +397,48 @@ pipeline
339397 }
340398 }
341399
400+ stage(' GitHub Operations' )
401+ {
402+ agent { label ' linux' }
403+ // when {
404+ // expression { return env.X_GitHub_Event == 'push' && env.GITHUB_PUSH_REF == 'refs/heads/master' }
405+ // }
406+ steps
407+ {
408+ script
409+ {
410+ withCredentials([string(credentialsId : ' github-token' , variable : ' GITHUB_TOKEN' )])
411+ {
412+ // Wait for GitHub Action to create/update the nightly tag
413+ WaitForGithubAction (' $GITHUB_TOKEN' , REPO_OWNER , REPO_NAME , GIT_HASH , " nightly-tag" )
414+
415+ // Upload Linux executable
416+ unstash ' linux_build'
417+ if (fileExists(' Build/Src/runcpp2/runcpp2' )) {
418+ bash """
419+ cd Build/Src/runcpp2
420+ zip -9 ../../../../runcpp2-linux.zip runcpp2
421+ cd ../../../..
422+ """
423+ UploadArtifactToGithub (' $GITHUB_TOKEN' , REPO_OWNER , REPO_NAME , " nightly" , " runcpp2-linux.zip" , " runcpp2-linux.zip" )
424+ }
425+
426+ // Upload Windows executable
427+ unstash ' windows_build'
428+ if (fileExists(' Build/Src/runcpp2/runcpp2.exe' )) {
429+ bash """
430+ cd Build/Src/runcpp2
431+ zip -9 ../../../../runcpp2-windows.zip runcpp2.exe
432+ cd ../../../..
433+ """
434+ UploadArtifactToGithub (' $GITHUB_TOKEN' , REPO_OWNER , REPO_NAME , " nightly" , " runcpp2-windows.zip" , " runcpp2-windows.zip" )
435+ }
436+ }
437+ }
438+ }
439+ post { failure { script { FAILED_STAGE = env. STAGE_NAME } } }
440+ }
441+
342442 stage(' Notify' )
343443 {
344444 agent { label ' linux' }
0 commit comments