Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 4e9f87f

Browse files
authored
actions: run unit-tests and linting in GH actions (#3138)
1 parent 524dbcc commit 4e9f87f

6 files changed

Lines changed: 103 additions & 62 deletions

File tree

.ci/Jenkinsfile

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pipeline {
5252
string(name: 'runTestsSuites', defaultValue: '', description: 'A comma-separated list of test suites to run (default: empty to run all test suites)')
5353
string(name: 'testMatrixFile', defaultValue: '.ci/.e2e-tests.yaml', description: 'The file with the test suite and scenarios to be tested.')
5454
booleanParam(name: "forceSkipGitChecks", defaultValue: false, description: "If it's needed to check for Git changes to filter by modified sources")
55-
booleanParam(name: "forceSkipPresubmit", defaultValue: false, description: "If it's needed to execute the pre-submit tests: unit and precommit.")
5655
booleanParam(name: "notifyOnGreenBuilds", defaultValue: false, description: "If it's needed to notify to Slack with green builds.")
5756
string(name: 'SLACK_CHANNEL', defaultValue: 'observablt-bots', description: 'The Slack channel(s) where errors will be posted. For multiple channels, use a comma-separated list of channels')
5857
string(name: 'ELASTIC_AGENT_DOWNLOAD_URL', defaultValue: '', description: 'If present, it will override the download URL for the Elastic agent artifact. (I.e. https://snapshots.elastic.co/8.0.0-59098054/downloads/beats/elastic-agent/elastic-agent-8.0.0-SNAPSHOT-linux-x86_64.tar.gz')
@@ -85,7 +84,6 @@ pipeline {
8584
KIBANA_VERSION = "${params.KIBANA_VERSION.trim()}"
8685
STACK_VERSION = "${params.STACK_VERSION.trim()}"
8786
FORCE_SKIP_GIT_CHECKS = "${params.forceSkipGitChecks}"
88-
FORCE_SKIP_PRESUBMIT = "${params.forceSkipPresubmit}"
8987
HELM_CHART_VERSION = "${params.HELM_CHART_VERSION.trim()}"
9088
HELM_VERSION = "${params.HELM_VERSION.trim()}"
9189
KIND_VERSION = "${params.KIND_VERSION.trim()}"
@@ -108,61 +106,6 @@ pipeline {
108106
checkSkipTests()
109107
}
110108
}
111-
stage('Pre-Submit') {
112-
when {
113-
beforeAgent true
114-
expression { return env.FORCE_SKIP_PRESUBMIT == "false" }
115-
}
116-
parallel {
117-
stage('Sanity checks') {
118-
agent { label 'ubuntu-20.04 && immutable && docker' }
119-
environment {
120-
PATH = "${env.REAL_BASE_DIR}/bin:${env.PATH}"
121-
GO111MODULE = 'auto'
122-
}
123-
options { skipDefaultCheckout() }
124-
steps {
125-
withGithubNotify(context: 'Sanity checks', tab: 'tests') {
126-
deleteDir()
127-
unstash 'source'
128-
withGoEnv(version: "${GO_VERSION}"){
129-
dir(BASE_DIR){
130-
retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh script: '.ci/scripts/install-dependencies.sh', label: 'Install dependencies' }
131-
preCommit(commit: "${GIT_BASE_COMMIT}", junit: true)
132-
}
133-
}
134-
}
135-
}
136-
}
137-
stage('Unit Tests') {
138-
options { skipDefaultCheckout() }
139-
when {
140-
beforeAgent true
141-
anyOf {
142-
expression { return env.FORCE_SKIP_GIT_CHECKS == "true" }
143-
expression { return env.SKIP_TESTS == "false" }
144-
}
145-
}
146-
steps {
147-
withGithubNotify(context: 'Tests', tab: 'tests') {
148-
deleteDir()
149-
unstash 'source'
150-
withGoEnv(version: "${GO_VERSION}"){
151-
dir(BASE_DIR){
152-
sh script: '.ci/scripts/build-test.sh', label: 'Build and test'
153-
}
154-
}
155-
}
156-
}
157-
post {
158-
always {
159-
junit2otel(traceName: 'junit-unit-tests', allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/outputs/TEST-unit-*.xml")
160-
archiveArtifacts allowEmptyArchive: true, artifacts: "${BASE_DIR}/outputs/TEST-unit-*.xml"
161-
}
162-
}
163-
}
164-
}
165-
}
166109
stage('Build Docs') {
167110
options { skipDefaultCheckout() }
168111
when {
@@ -173,8 +116,6 @@ pipeline {
173116
}
174117
}
175118
steps {
176-
deleteDir()
177-
unstash 'source'
178119
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
179120
dir("${BASE_DIR}/e2e") {
180121
sh(label: 'Build docs', script: 'make build-docs')
@@ -188,7 +129,6 @@ pipeline {
188129
}
189130
}
190131
}
191-
192132
stage('Deploy Test Infra') {
193133
failFast true
194134
options { skipDefaultCheckout() }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: golangci-lint
2+
on:
3+
pull_request:
4+
5+
permissions:
6+
contents: read
7+
pull-requests: read
8+
9+
jobs:
10+
golangci:
11+
strategy:
12+
matrix:
13+
os: [ ubuntu-latest, windows-latest ]
14+
name: lint
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Fetch Go version from .go-version
19+
run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
20+
- uses: actions/setup-go@v3
21+
with:
22+
go-version: ${{ env.GO_VERSION }}
23+
- name: golangci-lint
24+
uses: golangci/golangci-lint-action@v3
25+
with:
26+
version: v1.47.2
27+
args: --timeout=30m --whole-files
28+
# Optional: show only new issues if it's a pull request. The default value is `false`.
29+
only-new-issues: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
## Workflow to process the JUnit test results and add a report to the checks.
3+
name: Test Report
4+
on:
5+
workflow_run:
6+
workflows:
7+
- pull-request
8+
types:
9+
- completed
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
report:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: elastic/apm-pipeline-library/.github/actions/test-report@gh_actions
19+
with:
20+
artifact: test-results # artifact name
21+
name: JUnit Tests # Name of the check run which will be created
22+
path: "**/*.xml" # Path to test results (inside artifact .zip)
23+
reporter: java-junit # Format of test results

.github/workflows/pull-request.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
## Workflow to lint and test
3+
name: pull-request
4+
5+
permissions:
6+
contents: read
7+
8+
on:
9+
pull_request:
10+
push:
11+
12+
jobs:
13+
pre-commit:
14+
runs-on: ubuntu-latest
15+
env:
16+
JENKINS_URL: https://beats-ci.elastic.co/
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Fetch Go version from .go-version
20+
run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
21+
- uses: actions/setup-python@v3
22+
- uses: actions/setup-go@v3
23+
with:
24+
go-version: ${{ env.GO_VERSION }}
25+
- name: Install dependencies
26+
run: |
27+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0
28+
go install golang.org/x/lint/golint
29+
30+
- uses: pre-commit/action@v3.0.0
31+
32+
test:
33+
name: Run Test
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v3
37+
- name: Fetch Go version from .go-version
38+
run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
39+
- uses: actions/setup-go@v3
40+
with:
41+
go-version: ${{ env.GO_VERSION }}
42+
cache: true
43+
cache-dependency-path: go.sum
44+
- name: build
45+
run: .ci/scripts/build-test.sh
46+
- uses: actions/upload-artifact@v3 # upload test results
47+
if: success() || failure() # run this step even if previous step failed
48+
with:
49+
name: test-results
50+
path: outputs/TEST-unit-*.xml

.go-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.17
1+
1.18

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ repos:
5252
(?x)^(
5353
.*/?\.*.(tar.gz)
5454
)$
55-
- id: check-jjbb
5655
- id: check-gherkin-lint
5756
args: [
5857
"--disable", "AvoidOutlineForSingleExample,TooClumsy,TooManyTags,TooLongStep,TooManyDifferentTags,TooManySteps,UseBackground",

0 commit comments

Comments
 (0)