-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
87 lines (74 loc) · 2.69 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pipeline {
environment {
VERSION = pwsh(
returnStdout: true,
script: $/(Select-String -Pattern '^version = "(?<v>\d+.\d+.\d+)"' -AllMatches -Path Cargo.toml).Matches[0].Groups[1].value/$
).trim()
RELEASE_ASSET_PATH = "target/x86_64-pc-windows-msvc/release/mapirs.dll"
}
agent {
label 'win-native'
}
parameters {
booleanParam(
name: 'PUBLISH', defaultValue: false,
description: "publish the built dll to github"
)
}
stages {
stage('run tests') {
steps {
pwsh 'cargo fmt -- --check'
pwsh 'cargo clippy --target "x86_64-pc-windows-msvc" -- -D clippy::all'
pwsh 'cargo clean'
pwsh 'cargo test --target "x86_64-pc-windows-msvc"'
}
}
stage('build the dll') {
steps {
echo "building mapirs v${VERSION}"
pwsh 'cargo clean'
pwsh 'cargo build --release --target "x86_64-pc-windows-msvc"'
stash includes: "${RELEASE_ASSET_PATH}", name: 'dll'
}
}
stage('publish a github release') {
when {
expression { params.PUBLISH }
}
environment {
GITHUB_TOKEN = credentials('github-access-token')
RELEASE_TAG = "mapirs-release-${VERSION}"
}
steps {
unstash 'dll'
pwsh 'git tag $Env:RELEASE_TAG'
withCredentials([string(credentialsId: 'github-access-token', variable: 'GITHUB_TOKEN')]) {
pwsh 'git remote add origin-access https://$Env:GITHUB_TOKEN@github.com/tutao/mapirs.git'
pwsh 'git push origin-access --tags'
pwsh 'git remote remove origin-access'
}
sleep(10)
pwsh '''
echo $Env:RELEASE_TAG
$checksum = (Get-FileHash -Algorithm SHA256 -Path $Env:RELEASE_ASSET_PATH).Hash.ToLower()
$url = "https://api.github.com/repos/tutao/mapirs/releases"
$body_data = @{
'tag_name' = $Env:RELEASE_TAG
'name' = "mapirs v" + $Env:VERSION
'body' = "sha 256 checksum: " + $checksum
}
$body = $body_data | ConvertTo-Json
$headers = @{
'Accept' = 'application/vnd.github.v3+json'
'Authorization' = "token $Env:GITHUB_TOKEN"
}
$resp = Invoke-RestMethod -Method 'POST' -Uri $url -Body $body -Headers $headers
$asset_url = "https://uploads.github.com/repos/tutao/mapirs/releases/" + $resp.id + "/assets?name=mapirs.dll"
$headers["Content-Type"] = "application/octet-stream"
$asset_resp = Invoke-RestMethod -Method 'POST' -Uri $asset_url -InFile $Env:RELEASE_ASSET_PATH -Headers $headers
'''
}
}
}
}