Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/override-…
Browse files Browse the repository at this point in the history
…notify-message-template

* upstream/master:
  Fix build status and adjust Vault (#1074)
  Remove super-linter since it takes 20 minutes (#1083)
  Bump elastic stack version automation (#1081)
  feat: step to check if a docker image exists (#1077)
  docs: update CHANGELOG.md
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release v1.1.210
  Enable stage filter argument for the beatsStages (#1076)
  • Loading branch information
v1v committed Apr 21, 2021
2 parents 76f04fa + 48709f3 commit cda303f
Show file tree
Hide file tree
Showing 21 changed files with 731 additions and 19 deletions.
11 changes: 0 additions & 11 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,6 @@ pipeline {
}
}
}
stage('Super-linter') {
steps {
withGithubNotify(context: 'Check super-linter', tab: 'tests') {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
superLinter(failNever: true, junit: false)
}
}
}
}
stage('Release') {
environment {
// gren and other tools are in the .ci/scripts folder.
Expand Down
169 changes: 169 additions & 0 deletions .ci/bumpStackVersion.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import groovy.transform.Field

@Library('apm@current') _

// To store all the latest snapshot versions
@Field def latestVersions

pipeline {
agent { label 'linux && immutable' }
environment {
REPO = 'observability-dev'
HOME = "${env.WORKSPACE}"
NOTIFY_TO = credentials('notify-to')
PIPELINE_LOG_LEVEL='INFO'
}
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
parameters {
booleanParam(name: 'DRY_RUN_MODE', defaultValue: false, description: 'If true, allows to execute this pipeline in dry run mode, without sending a PR.')
}
stages {
stage('Checkout') {
steps {
git(credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken', url: "https://github.com/elastic/${REPO}.git")
}
}
stage('Fetch latest versions') {
steps {
script {
latestVersions = artifactsApi(action: 'latest-versions')
}
archiveArtifacts 'latest-versions.json'
}
}
stage('Send Pull Request'){
options {
warnError('Pull Requests failed')
}
steps {
generateSteps()
}
}
}
post {
cleanup {
notifyBuildResult()
}
}
}

def generateSteps(Map args = [:]) {
def projects = readYaml(file: '.ci/.bump-stack-version.yml')
def parallelTasks = [:]
projects['projects'].each { project ->
matrix( agent: 'linux && immutable',
axes:[
axis('REPO', [project.repo]),
axis('BRANCH', project.branches),
axis('ENABLED', [project.get('enabled', true)])
],
excludes: [ axis('ENABLED', [ false ]) ]
) {
bumpStackVersion(repo: env.REPO,
scriptFile: "${project.script}",
branch: env.BRANCH,
reusePullRequest: project.get('reusePullRequest', false),
labels: project.get('labels', ''))
}
}
}

def bumpStackVersion(Map args = [:]){
def repo = args.containsKey('repo') ? args.get('repo') : error('bumpStackVersion: repo argument is required')
def scriptFile = args.containsKey('scriptFile') ? args.get('scriptFile') : error('bumpStackVersion: scriptFile argument is required')
def branch = args.containsKey('branch') ? args.get('branch') : error('bumpStackVersion: branch argument is required')
def reusePullRequest = args.get('reusePullRequest', false)
def labels = args.get('labels', '')
log(level: 'INFO', text: "bumpStackVersion(repo: ${repo}, branch: ${branch}, scriptFile: ${scriptFile}, reusePullRequest: ${reusePullRequest}, labels: '${labels}')")

def branchName = findBranch(branch: branch, versions: latestVersions)
def versionEntry = latestVersions.get(branchName)
def message = createPRDescription(versionEntry)

catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
deleteDir()
setupAPMGitEmail(global: true)
git(url: "https://github.com/elastic/${repo}.git", branch: branchName, credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken')
sh(script: "${scriptFile} '${versionEntry.build_id}'", label: "Prepare changes for ${repo}")

pullRequest(reusePullRequest: reusePullRequest,
stackVersion: versionEntry.build_id,
message: message,
labels: labels)
}
}

def pullRequest(Map args = [:]){
def stackVersion = args.stackVersion
def message = args.message
def labels = args.labels.replaceAll('\\s','')
def reusePullRequest = args.get('reusePullRequest', false)
if (labels.trim()) {
labels = "automation,${labels}"
}

if (params.DRY_RUN_MODE) {
log(level: 'INFO', text: "DRY-RUN: pullRequest(stackVersion: ${stackVersion}, reusePullRequest: ${reusePullRequest}, labels: ${labels}, message: '${message}')")
return
}

if (reusePullRequest && ammendPullRequestIfPossible()) {
log(level: 'INFO', text: 'Reuse existing Pull Request')
return
}
githubCreatePullRequest(title: "bump: stack version '${stackVersion}'",
labels: "${labels}", description: "${message}")
}

def ammendPullRequestIfPossible() {
log(level: 'INFO', text: 'TBD')
return false
}

def findBranch(Map args = [:]){
def branch = args.branch
// special macro to look for the latest minor version
if (branch.contains('<minor>')) {
def parts = branch.split('\\.')
def major = parts[0]
branch = args.versions.collect{ k,v -> k }.findAll { it ==~ /${major}\.\d+/}.sort().last()
}
return branch
}

def createPRDescription(versionEntry) {
return """
### What
Bump stack version with the latest one.
### Further details
```
${versionEntry}
```
"""
}
25 changes: 25 additions & 0 deletions .ci/jobs/bump-stack-version-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- job:
name: apm-shared/bump-stack-version-pipeline
display-name: Bump Stack Version
description: Send PRs to the subscribed observability repositories if a new stack snapshot version has been released.
view: APM-CI
project-type: pipeline
parameters:
- string:
name: branch_specifier
default: master
description: the Git branch specifier to build
pipeline-scm:
script-path: .ci/bumpStackVersion.groovy
scm:
- git:
url: git@github.com:elastic/apm-pipeline-library.git
refspec: +refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*
wipe-workspace: 'True'
name: origin
shallow-clone: true
credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba
reference-repo: /var/lib/jenkins/.git-references/apm-pipeline-library.git
branches:
- $branch_specifier
8 changes: 8 additions & 0 deletions .ci/schedule-daily.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ pipeline {
wait: false
)

build(job: 'apm-shared/bump-stack-version-pipeline',
parameters: [
booleanParam(name: 'DRY_RUN_MODE', value: false)
],
propagate: false,
wait: false
)

build(job: 'apm-ui/apm-ui-e2e-tests-mbp/master',
parameters: [
booleanParam(name: 'FORCE', value: true),
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.1.210 (20/04/2021)

#### 🚀 Enhancements

- Enable stage filter argument for the beatsStages [#1076](https://github.com/elastic/apm-pipeline-library/pull/1076)

## v1.1.209 (15/04/2021)

#### 🚀 Enhancements
Expand Down
4 changes: 4 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ execute the following from the directory at the root of this project:

`./mvnw test -Dtest=DummyStepTests`

To run one single test, execute the following from the directory at the root of
this project, separating test name from test file with an `#`:

`./mvnw test -Dtest=DummyStepTests#testName`

To run tests and print additional debug output to the console, use the `-Pdebug`
flag:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>co.elastic</groupId>
<artifactId>jenkins-library</artifactId>
<version>1.1.210-SNAPSHOT</version>
<version>1.1.211-SNAPSHOT</version>
<name>APM Pipeline Shared Library</name>
<description>Pipeline Shared Library containing utility steps.</description>
<url>https://github.com/elastic/apm-pipeline-library</url>
Expand Down
55 changes: 55 additions & 0 deletions resources/scripts/artifacts-api-latest-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

#
# It queries the artifacts-api entry point to fetch all the existing
# snapshot versions and their metadata
# It prints the output in the console in addition to the file
# latest-versions.json
#
# Since it prints the output in the console avoid any cosmetic changes
# with echo or set -x
#
set -eo pipefail

URL="https://artifacts-api.elastic.co/v1"
OUTPUT=latest-versions.json

QUERY_OUTPUT=$(curl -s ${URL}/versions | jq -r '.aliases[] | select(contains("SNAPSHOT"))')
LENGTH=$(echo $QUERY_OUTPUT | wc -l)
i=0
echo "{" > "${OUTPUT}"
for version in ${QUERY_OUTPUT}; do
## Array separator
i=$(($i + 1))
comma=""
if [ ${i} -gt 1 ] ; then
comma=","
elif [ ${i} -ge ${LENGTH} ] ; then
comma=""
fi
LATEST_OUTPUT=$(curl -s ${URL}/versions/${version}/builds/latest | jq 'del(.build.projects,.manifests) | . |= .build')
BRANCH=$(echo $LATEST_OUTPUT | jq -r .branch)
{
echo "${comma}\"$BRANCH\":"
echo "${LATEST_OUTPUT}"
} >> "${OUTPUT}"
done
echo "}" >> "${OUTPUT}"

cat "${OUTPUT}"
81 changes: 81 additions & 0 deletions src/test/groovy/ArtifactsApiStepTests.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import org.junit.Before
import org.junit.Test
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue

class ArtifactsApiStepTests extends ApmBasePipelineTest {

@Override
@Before
void setUp() throws Exception {
super.setUp()
script = loadScript('vars/artifactsApi.groovy')
}

@Test
void testWindows() throws Exception {
testWindows() {
script.call()
}
}

@Test
void test_missing_action() throws Exception {
testMissingArgument('action') {
script.call()
}
}

@Test
void test_unsupported_action() throws Exception {
try {
script.call(action: 'unknown')
} catch(e) {
//NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', "artifactsApi: unsupported action."))
assertJobStatusFailure()
}

@Test
void test_latest_versions() throws Exception {
helper.registerAllowedMethod('sh', [Map.class],{'''
{
"6.8":
{
"release_branch": "6.8",
"branch": "6.8",
"version": "6.8.16-SNAPSHOT",
"build_id": "6.8.16-ac54b152"
},
"7.x":
{
"release_branch": "7.x",
"branch": "7.x",
"version": "7.13.0-SNAPSHOT",
"build_id": "7.13.0-a6f186fd"
}
}'''})
def obj = script.call(action: 'latest-versions')
assertTrue(obj.get('6.8').branch.equals('6.8'))
printCallStack()
}
}
Loading

0 comments on commit cda303f

Please sign in to comment.