Compare commits
4 Commits
ci-lesavka
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43b6639516 | ||
|
|
32274747f5 | ||
|
|
7e8139965c | ||
|
|
5a71c3fea2 |
@ -268,9 +268,11 @@ data:
|
|||||||
url('https://scm.bstein.dev/bstein/lesavka.git')
|
url('https://scm.bstein.dev/bstein/lesavka.git')
|
||||||
credentials('gitea-pat')
|
credentials('gitea-pat')
|
||||||
}
|
}
|
||||||
branches('*/dev-phone-companion-updates')
|
// Pin both the pipeline definition and worker checkout to the request.
|
||||||
|
branches('$EXPECTED_SOURCE_REVISION')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lightweight(false)
|
||||||
scriptPath('docker/Jenkinsfile.compile')
|
scriptPath('docker/Jenkinsfile.compile')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,6 +335,7 @@ data:
|
|||||||
stringParam('APK21_SHA256', '', 'Reviewed unsigned version-21 fixture hash.')
|
stringParam('APK21_SHA256', '', 'Reviewed unsigned version-21 fixture hash.')
|
||||||
stringParam('APK22_SHA256', '', 'Reviewed unsigned version-22 fixture hash.')
|
stringParam('APK22_SHA256', '', 'Reviewed unsigned version-22 fixture hash.')
|
||||||
choiceParam('ANDROID_API', ['34', '36'], 'Empty VM API; separate result per platform.')
|
choiceParam('ANDROID_API', ['34', '36'], 'Empty VM API; separate result per platform.')
|
||||||
|
choiceParam('ANDROID_IMAGE_TAG', ['platform-default', 'default', 'google_apis'], 'Explicit image comparison; platform-default retains API34 AOSP and API36 Google APIs. AOSP does not qualify Google delivery.')
|
||||||
stringParam('ANDROID_WORKER_IMAGE', '', 'Reviewed lesavka-android-runtime image digest.')
|
stringParam('ANDROID_WORKER_IMAGE', '', 'Reviewed lesavka-android-runtime image digest.')
|
||||||
}
|
}
|
||||||
definition {
|
definition {
|
||||||
@ -377,9 +380,12 @@ data:
|
|||||||
url('https://scm.bstein.dev/bstein/lesavka.git')
|
url('https://scm.bstein.dev/bstein/lesavka.git')
|
||||||
credentials('gitea-pat')
|
credentials('gitea-pat')
|
||||||
}
|
}
|
||||||
branches('*/dev-phone-companion-updates')
|
// Select both Jenkinsfile and worker source from the queued revision.
|
||||||
|
branches('$EXPECTED_SOURCE_REVISION')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// A commit is not a branch-head name for lightweight retrieval.
|
||||||
|
lightweight(false)
|
||||||
scriptPath('docker/Jenkinsfile.software-tests')
|
scriptPath('docker/Jenkinsfile.software-tests')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,9 +495,11 @@ data:
|
|||||||
url('https://scm.bstein.dev/bstein/lesavka.git')
|
url('https://scm.bstein.dev/bstein/lesavka.git')
|
||||||
credentials('gitea-pat')
|
credentials('gitea-pat')
|
||||||
}
|
}
|
||||||
branches('*/dev-phone-companion-updates')
|
// Pin both the pipeline definition and worker checkout to the request.
|
||||||
|
branches('$EXPECTED_SOURCE_REVISION')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lightweight(false)
|
||||||
scriptPath('docker/Jenkinsfile.runtime')
|
scriptPath('docker/Jenkinsfile.runtime')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
143
services/jenkins/validation/lesavka-source-selection.groovy
Normal file
143
services/jenkins/validation/lesavka-source-selection.groovy
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
// Controller-side acceptance probe with a private Git fixture. Supply one reviewed
|
||||||
|
// job's DSL as candidateSeed and its allowlisted name as candidateJob. Installed
|
||||||
|
// jobs are never saved, queued or changed.
|
||||||
|
import groovy.json.JsonOutput
|
||||||
|
import groovy.xml.XmlUtil
|
||||||
|
import hudson.EnvVars
|
||||||
|
import hudson.FilePath
|
||||||
|
import hudson.model.TaskListener
|
||||||
|
import hudson.plugins.git.GitSCM
|
||||||
|
import hudson.plugins.git.util.BuildChooserContext
|
||||||
|
import hudson.plugins.git.util.BuildData
|
||||||
|
import javaposse.jobdsl.dsl.DslScriptLoader
|
||||||
|
import javaposse.jobdsl.dsl.Item
|
||||||
|
import javaposse.jobdsl.plugin.JenkinsJobManagement
|
||||||
|
import jenkins.model.Jenkins
|
||||||
|
import org.jenkinsci.plugins.gitclient.Git
|
||||||
|
import org.jenkinsci.plugins.gitclient.GitClient
|
||||||
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.attribute.PosixFilePermissions
|
||||||
|
|
||||||
|
class ReviewOnly extends JenkinsJobManagement {
|
||||||
|
Map<String, String> rendered = [:]
|
||||||
|
final String expectedJob
|
||||||
|
|
||||||
|
ReviewOnly(String expectedJob) {
|
||||||
|
super(TaskListener.NULL.logger, [:], new File('/tmp'))
|
||||||
|
this.expectedJob = expectedJob
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override boolean createOrUpdateConfig(Item item, boolean ignoreExisting) {
|
||||||
|
assert item.name == expectedJob
|
||||||
|
rendered[item.name] = item.xml
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override void queueJob(String name) {
|
||||||
|
throw new IllegalStateException('acceptance probe cannot queue jobs')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def selectedJob = binding.getVariable('candidateJob')
|
||||||
|
def expected = [
|
||||||
|
'lesavka-software-tests': [path: 'docker/Jenkinsfile.software-tests', builds: '8'],
|
||||||
|
'lesavka-compile': [path: 'docker/Jenkinsfile.compile', builds: '12'],
|
||||||
|
'lesavka-runtime-tests': [path: 'docker/Jenkinsfile.runtime', builds: '8'],
|
||||||
|
]
|
||||||
|
assert expected.containsKey(selectedJob)
|
||||||
|
def review = new ReviewOnly(selectedJob)
|
||||||
|
def installedState = {
|
||||||
|
def current = Jenkins.get().getItemByFullName(selectedJob).definition
|
||||||
|
[path: current.scriptPath, lightweight: current.lightweight, branches: current.scm.branches*.name]
|
||||||
|
}
|
||||||
|
def before = installedState()
|
||||||
|
new DslScriptLoader(review).runScript(binding.getVariable('candidateSeed'))
|
||||||
|
assert review.rendered.keySet() == [selectedJob] as Set
|
||||||
|
def xml = new XmlParser().parseText(review.rendered[selectedJob])
|
||||||
|
def definition = Jenkins.XSTREAM2.fromXML(XmlUtil.serialize(xml.definition[0]))
|
||||||
|
assert !definition.lightweight
|
||||||
|
assert definition.scriptPath == expected[selectedJob].path
|
||||||
|
def scm = definition.scm
|
||||||
|
assert scm.branches*.name == ['$EXPECTED_SOURCE_REVISION']
|
||||||
|
assert scm.userRemoteConfigs.size() == 1
|
||||||
|
assert scm.userRemoteConfigs[0].url == 'https://scm.bstein.dev/bstein/lesavka.git'
|
||||||
|
assert scm.userRemoteConfigs[0].credentialsId == 'gitea-pat'
|
||||||
|
assert xml.properties.'org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty'.size() == 1
|
||||||
|
assert xml.properties.'jenkins.model.BuildDiscarderProperty'.strategy.numToKeep.text() == expected[selectedJob].builds
|
||||||
|
assert xml.properties.'jenkins.model.BuildDiscarderProperty'.strategy.artifactNumToKeep.text() == '4'
|
||||||
|
|
||||||
|
def resolver = GitSCM.getDeclaredMethod('getSingleBranch', EnvVars)
|
||||||
|
resolver.accessible = true
|
||||||
|
def directory = Files.createTempDirectory('lesavka-source-selection-',
|
||||||
|
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString('rwx------'))).toFile()
|
||||||
|
def checks = []
|
||||||
|
try {
|
||||||
|
// Tiny public fixture only. No network, credentials, real repository or build.
|
||||||
|
def git = Git.with(TaskListener.NULL, new EnvVars()).in(directory).using('git').getClient()
|
||||||
|
git.init()
|
||||||
|
git.setAuthor('Lesavka CI fixture', 'fixture@example.invalid')
|
||||||
|
git.setCommitter('Lesavka CI fixture', 'fixture@example.invalid')
|
||||||
|
def pipeline = new File(directory, definition.scriptPath)
|
||||||
|
assert pipeline.parentFile.mkdirs()
|
||||||
|
def payload = new File(directory, 'source.txt')
|
||||||
|
pipeline.text = 'reviewed pipeline\n'
|
||||||
|
payload.text = 'reviewed source\n'
|
||||||
|
git.add('.')
|
||||||
|
git.commit('Reviewed fixture')
|
||||||
|
def requested = git.revParse('HEAD').name()
|
||||||
|
pipeline.text = 'later pipeline\n'
|
||||||
|
payload.text = 'later source\n'
|
||||||
|
git.add('.')
|
||||||
|
git.commit('Branch advanced while request waited')
|
||||||
|
def later = git.revParse('HEAD').name()
|
||||||
|
assert later != requested
|
||||||
|
def repository = new FileRepositoryBuilder().setGitDir(new File(directory, '.git')).build()
|
||||||
|
try {
|
||||||
|
def branch = repository.updateRef('refs/remotes/origin/dev-phone-companion-updates')
|
||||||
|
branch.setNewObjectId(git.revParse('HEAD'))
|
||||||
|
branch.forceUpdate()
|
||||||
|
} finally {
|
||||||
|
repository.close()
|
||||||
|
}
|
||||||
|
checks << 'branch_advanced_after_requested_revision'
|
||||||
|
|
||||||
|
// Reproduce the old selector choosing the later branch tip in this fixture.
|
||||||
|
def oldScm = new GitSCM('https://example.invalid/review.git')
|
||||||
|
oldScm.branches = [new hudson.plugins.git.BranchSpec('*/dev-phone-companion-updates')]
|
||||||
|
def oldExpanded = resolver.invoke(oldScm, new EnvVars([EXPECTED_SOURCE_REVISION: requested]))
|
||||||
|
def oldCandidates = oldScm.buildChooser.getCandidateRevisions(false, oldExpanded,
|
||||||
|
(GitClient) git, TaskListener.NULL, new BuildData(), (BuildChooserContext) null)
|
||||||
|
assert oldCandidates.size() == 1 && oldCandidates.first().sha1String == later
|
||||||
|
checks << 'old_selector_reproduces_moving_branch_defect'
|
||||||
|
|
||||||
|
// Exercise the installed plugin's expansion and actual revision chooser.
|
||||||
|
def expanded = resolver.invoke(scm, new EnvVars([EXPECTED_SOURCE_REVISION: requested]))
|
||||||
|
assert expanded == requested
|
||||||
|
def candidates = scm.buildChooser.getCandidateRevisions(false, expanded, (GitClient) git,
|
||||||
|
TaskListener.NULL, new BuildData(), (BuildChooserContext) null)
|
||||||
|
assert candidates.size() == 1 && candidates.first().sha1String == requested
|
||||||
|
git.checkout().ref(candidates.first().sha1String).execute()
|
||||||
|
assert git.revParse('HEAD').name() == requested
|
||||||
|
assert pipeline.text == 'reviewed pipeline\n' && payload.text == 'reviewed source\n'
|
||||||
|
checks << 'requested_pipeline_and_payload_selected_after_branch_advance'
|
||||||
|
|
||||||
|
// A nonexistent full revision must not fall back to branch HEAD.
|
||||||
|
def missing = resolver.invoke(scm, new EnvVars([EXPECTED_SOURCE_REVISION: '0' * 40]))
|
||||||
|
assert scm.buildChooser.getCandidateRevisions(false, missing, (GitClient) git,
|
||||||
|
TaskListener.NULL, new BuildData(), (BuildChooserContext) null).isEmpty()
|
||||||
|
checks << 'missing_revision_does_not_select_head'
|
||||||
|
|
||||||
|
// No real-job mutation: loading/parsing this configuration is not rollout.
|
||||||
|
assert installedState() == before
|
||||||
|
checks << 'installed_job_unchanged'
|
||||||
|
} finally {
|
||||||
|
new FilePath(directory).deleteRecursive()
|
||||||
|
}
|
||||||
|
assert !directory.exists()
|
||||||
|
checks << 'private_fixture_removed'
|
||||||
|
println(JsonOutput.toJson([status: 'passed', job: selectedJob, checks: checks,
|
||||||
|
plugins: ['git', 'git-client', 'workflow-cps', 'job-dsl'].collectEntries {
|
||||||
|
[(it): Jenkins.get().pluginManager.getPlugin(it).version]
|
||||||
|
}]))
|
||||||
|
return null
|
||||||
56
services/jenkins/validation/lesavka-worker-source.groovy
Normal file
56
services/jenkins/validation/lesavka-worker-source.groovy
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Read public worker definitions through the installed Pipeline step. Supply two
|
||||||
|
// reviewed commits with different payload hashes and an existing software run.
|
||||||
|
// No job is created, saved, queued or changed; credentials stay inside GitSCMSource.
|
||||||
|
import groovy.json.JsonOutput
|
||||||
|
import hudson.model.Run
|
||||||
|
import hudson.model.TaskListener
|
||||||
|
import jenkins.model.Jenkins
|
||||||
|
import jenkins.plugins.git.GitSCMSource
|
||||||
|
import org.jenkinsci.plugins.workflow.steps.StepContext
|
||||||
|
import org.jenkinsci.plugins.workflow.steps.scm.ReadScmFileStep
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
def job = Jenkins.get().getItemByFullName('lesavka-software-tests')
|
||||||
|
def build = job.getBuildByNumber(binding.getVariable('existingBuild') as int)
|
||||||
|
assert build != null && !build.building
|
||||||
|
def before = job.configFile.asString()
|
||||||
|
def context = [get: { Class type ->
|
||||||
|
if (type == Run) { return build }
|
||||||
|
if (type == TaskListener) { return TaskListener.NULL }
|
||||||
|
throw new IllegalStateException('Unexpected step context: ' + type.name)
|
||||||
|
}] as StepContext
|
||||||
|
def source = new GitSCMSource('https://scm.bstein.dev/bstein/lesavka.git')
|
||||||
|
source.credentialsId = 'gitea-pat'
|
||||||
|
def read = { String revision, String path ->
|
||||||
|
def execution = new ReadScmFileStep(source, revision, path).start(context)
|
||||||
|
def method = execution.class.getDeclaredMethod('run')
|
||||||
|
method.accessible = true
|
||||||
|
method.invoke(execution)
|
||||||
|
}
|
||||||
|
def digest = { String value ->
|
||||||
|
MessageDigest.getInstance('SHA-256').digest(value.getBytes('UTF-8')).encodeHex().toString()
|
||||||
|
}
|
||||||
|
def expected = binding.getVariable('expectedPayloads')
|
||||||
|
assert expected.size() == 2 && expected.values().toSet().size() == 2
|
||||||
|
def checks = []
|
||||||
|
expected.each { revision, sha256 ->
|
||||||
|
assert revision ==~ /[0-9a-f]{40}/
|
||||||
|
assert sha256 ==~ /[0-9a-f]{64}/
|
||||||
|
assert digest(read(revision, 'docker/software-test-pod.yaml')) == sha256
|
||||||
|
checks << 'exact_worker_payload_' + revision
|
||||||
|
}
|
||||||
|
boolean missingRefused = false
|
||||||
|
try {
|
||||||
|
read('0' * 40, 'docker/software-test-pod.yaml')
|
||||||
|
} catch (java.lang.reflect.InvocationTargetException failure) {
|
||||||
|
assert failure.cause instanceof hudson.AbortException
|
||||||
|
assert failure.cause.message == 'No such revision'
|
||||||
|
missingRefused = true
|
||||||
|
}
|
||||||
|
assert missingRefused
|
||||||
|
checks << 'missing_revision_refused_without_fallback'
|
||||||
|
assert job.configFile.asString() == before
|
||||||
|
checks << 'installed_job_unchanged'
|
||||||
|
println(JsonOutput.toJson([status: 'passed', checks: checks,
|
||||||
|
plugin: Jenkins.get().pluginManager.getPlugin('workflow-scm-step').version]))
|
||||||
|
return null
|
||||||
Loading…
x
Reference in New Issue
Block a user