Skip to content

Commit 230e92c

Browse files
Attempt to add nightly release
1 parent 4ec6970 commit 230e92c

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

.github/workflows/nightly-tag.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Nightly Tag
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- NightlyTest
8+
9+
jobs:
10+
update-nightly-tag:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Create or update nightly tag
18+
run: |
19+
git config --global user.name "GitHub Action"
20+
git config --global user.email "action@github.com"
21+
22+
# Delete the nightly tag if it exists (both locally and remotely)
23+
git tag -d nightly || true
24+
git push origin :refs/tags/nightly || true
25+
26+
# Create new nightly tag
27+
git tag nightly
28+
git push origin nightly
29+
30+
- name: Set status check
31+
uses: bobheadxi/status@v1
32+
with:
33+
context: nightly-tag
34+
status: success
35+
description: "Nightly tag updated successfully"
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Jenkinsfile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2785
def REPO_OWNER = "Neko-Box-Coder"
2886
def REPO_NAME = "runcpp2"
2987
def 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

Comments
 (0)