From fd68195c057c4fb3325b4f8230f98bdc2669eb16 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Mon, 7 Aug 2023 14:09:20 +0200 Subject: [PATCH] [workflow] gosigar (#171) --- .ci/Jenkinsfile | 139 ---------------------------- .ci/jobs/defaults.yml | 19 ---- .ci/jobs/folders.yml | 10 -- .ci/jobs/main.yml | 44 --------- .github/examples.bat | 5 + .github/examples.sh | 8 ++ .github/workflows/ci.yml | 59 ++++++++++++ .github/workflows/opentelemetry.yml | 18 ++++ README.md | 2 +- sys/windows/syscall_windows_test.go | 8 ++ 10 files changed, 99 insertions(+), 213 deletions(-) delete mode 100644 .ci/Jenkinsfile delete mode 100644 .ci/jobs/defaults.yml delete mode 100644 .ci/jobs/folders.yml delete mode 100644 .ci/jobs/main.yml create mode 100644 .github/examples.bat create mode 100755 .github/examples.sh create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/opentelemetry.yml diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile deleted file mode 100644 index d97a9ef02..000000000 --- a/.ci/Jenkinsfile +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env groovy - -@Library('apm@current') _ - -pipeline { - agent { label 'ubuntu-20 && immutable' } - environment { - REPO = 'gosigar' - BASE_DIR = "src/github.com/elastic/${env.REPO}" - PIPELINE_LOG_LEVEL='INFO' - } - options { - timeout(time: 1, unit: 'HOURS') - buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10', daysToKeepStr: '30')) - timestamps() - ansiColor('xterm') - disableResume() - durabilityHint('PERFORMANCE_OPTIMIZED') - rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) - quietPeriod(10) - } - triggers { - issueCommentTrigger('(?i)(.*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?|/test).*') - } - stages { - stage('Checkout') { - steps { - deleteDir() - gitCheckout(basedir: "${BASE_DIR}") - stash allowEmpty: true, name: 'source', useDefaultExcludes: false - } - } - stage('Lint'){ - steps { - withGoEnv(){ - dir("${BASE_DIR}"){ - sh(label: 'lint', script: ''' - go mod tidy && git diff --exit-code - gofmt -l . | read && echo "Code differs from gofmt's style. Run 'gofmt -w .'" 1>&2 && exit 1 || true - ''') - sh(label: 'Go vet', script: 'go vet') - } - } - } - } - stage('Build and test'){ - matrix { - agent {label "${PLATFORM}"} - axes { - axis { - name 'GO_VERSION' - values '1.15.8', '1.16' - } - axis { - name 'PLATFORM' - values 'macosx&&x86_64', 'macosx&&arm64', 'ubuntu-20 && immutable', 'windows-2012-r2 && windows-immutable' - } - } - excludes { - exclude { - axis { - name 'GO_VERSION' - values '1.15.8' - } - axis { - name 'PLATFORM' - values 'macosx&&arm64' - } - } - exclude { - axis { - name 'GO_VERSION' - values '1.16' - } - axis { - name 'PLATFORM' - notValues 'macosx&&arm64' - } - } - } - stages { - stage('build'){ - steps { - deleteDir() - unstash 'source' - withGoEnv(version: env.GO_VERSION){ - dir("${BASE_DIR}"){ - cmd(label: 'Go build', script: 'go build') - } - } - } - } - stage('test'){ - steps { - withGoEnv(version: env.GO_VERSION){ - dir("${BASE_DIR}"){ - goTestJUnit(options: '-v ./...', output: 'junit-report.xml') - buildExamples() - } - } - } - post{ - cleanup{ - junit(testResults: "${BASE_DIR}/junit-report.xml", allowEmptyResults: true) - } - } - } - } - } - } - } - post { - cleanup { - notifyBuildResult(prComment: true) - } - } -} - -def getExamplesDirs(){ - return [ - "examples/df", - "examples/free", - "examples/ps", - "examples/uptime" - ] -} - -def buildExamples(){ - getExamplesDirs().each { exampleDir -> - cmd(label: "Build Example ${exampleDir}", script: "go build -o ${exampleDir}/out.exe ./${exampleDir}") - dir("${exampleDir}"){ - def prefix = '' - if(isUnix()){ - prefix = './' - } - cmd(label: "Running Example ${exampleDir}", script: "${prefix}out.exe") - } - } -} diff --git a/.ci/jobs/defaults.yml b/.ci/jobs/defaults.yml deleted file mode 100644 index bb26a2fca..000000000 --- a/.ci/jobs/defaults.yml +++ /dev/null @@ -1,19 +0,0 @@ - ---- - -##### GLOBAL METADATA - -- meta: - cluster: beats-ci - -##### JOB DEFAULTS - -- job: - logrotate: - numToKeep: 20 - node: linux - concurrent: true - publishers: - - email: - recipients: infra-root+build@elastic.co - prune-dead-branches: true diff --git a/.ci/jobs/folders.yml b/.ci/jobs/folders.yml deleted file mode 100644 index 472766f99..000000000 --- a/.ci/jobs/folders.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -#https://docs.openstack.org/infra/jenkins-job-builder/project_folder.html -- job: - name: Library - description: Library related Jobs - project-type: folder - -- view: - name: Library - view-type: list diff --git a/.ci/jobs/main.yml b/.ci/jobs/main.yml deleted file mode 100644 index 027cdb734..000000000 --- a/.ci/jobs/main.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- job: - name: Library/gosigar - display-name: Go sigar - description: Jenkins pipeline for Go sigar is a golang implementation of the sigar API. - view: Beats - project-type: multibranch - script-path: .ci/Jenkinsfile - scm: - - github: - branch-discovery: no-pr - discover-pr-forks-strategy: merge-current - discover-pr-forks-trust: permission - discover-pr-origin: merge-current - discover-tags: true - head-filter-regex: '(master|main|PR-.*|v\d+\.\d+\.\d+)' - notification-context: 'gosigar' - repo: gosigar - repo-owner: elastic - credentials-id: 2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken - ssh-checkout: - credentials: f6c7695a-671e-4f4f-a331-acdce44ff9ba - build-strategies: - - tags: - ignore-tags-older-than: -1 - ignore-tags-newer-than: -1 - - regular-branches: true - - change-request: - ignore-target-only-changes: false - clean: - after: true - before: true - prune: true - shallow-clone: true - depth: 4 - do-not-fetch-tags: true - submodule: - disable: false - recursive: true - parent-credentials: true - timeout: 100 - timeout: '15' - use-author: true - wipe-workspace: 'True' diff --git a/.github/examples.bat b/.github/examples.bat new file mode 100644 index 000000000..1e1453572 --- /dev/null +++ b/.github/examples.bat @@ -0,0 +1,5 @@ +set examples=examples\df examples\free examples\ps examples\uptime +(for %%i in (%examples%) do ( + go build -o %%i\out.exe ./%%i + %%i\out.exe +)) diff --git a/.github/examples.sh b/.github/examples.sh new file mode 100755 index 000000000..170d8aef9 --- /dev/null +++ b/.github/examples.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +for exampleDir in "examples/df" "examples/free" "examples/ps" "examples/uptime" ; do + go build -o ${exampleDir}/out.exe ./${exampleDir} + pushd ${exampleDir} + ./out.exe + popd +done diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..4c5a5b139 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +--- + name: ci + + on: + workflow_dispatch: + push: + branches: + - master + pull_request: + + permissions: + contents: read + + ## Concurrency only allowed in the main branch. + ## So old builds running for old commits within the same Pull Request are cancelled + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + + jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + + - name: Lint + run: |- + go mod tidy && git diff --exit-code + gofmt -l . | read && echo "Code differs from gofmt's style. Run 'gofmt -w .'" 1>&2 && exit 1 || true + go vet + + test: + strategy: + fail-fast: false + matrix: + go-version: ['1.15', '1.16'] + os: [macos-latest, ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + cache: true + cache-dependency-path: '**/go.sum' + + - name: Build + run: go build + + - name: Test + run: go test -v ./... + + - name: Run examples + run: ${{ startsWith(matrix.os,'windows') && '.github/examples.bat' || '.github/examples.sh' }} diff --git a/.github/workflows/opentelemetry.yml b/.github/workflows/opentelemetry.yml new file mode 100644 index 000000000..b2ec57de2 --- /dev/null +++ b/.github/workflows/opentelemetry.yml @@ -0,0 +1,18 @@ +--- + name: OpenTelemetry Export Trace + + on: + workflow_run: + workflows: + - ci + types: [completed] + + jobs: + otel-export-trace: + runs-on: ubuntu-latest + steps: + - uses: elastic/apm-pipeline-library/.github/actions/opentelemetry@current + with: + vaultUrl: ${{ secrets.VAULT_ADDR }} + vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} + vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} diff --git a/README.md b/README.md index ab8f5bcfe..18cabdb4d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Go sigar [![Build Status](https://beats-ci.elastic.co/job/Beats/job/gosigar/job/master/badge/icon)](https://beats-ci.elastic.co/job/Beats/job/gosigar/job/master/) +# Go sigar [![ci](https://github.com/elastic/gosigar/actions/workflows/ci.yml/badge.svg)](https://github.com/elastic/gosigar/actions/workflows/ci.yml) ## Overview diff --git a/sys/windows/syscall_windows_test.go b/sys/windows/syscall_windows_test.go index bde47a82c..7b8bb361d 100644 --- a/sys/windows/syscall_windows_test.go +++ b/sys/windows/syscall_windows_test.go @@ -92,6 +92,10 @@ func TestEnumProcesses(t *testing.T) { } func TestGetDiskFreeSpaceEx(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("test is not running on latest windows versions. See https://github.com/elastic/gosigar/issues/172") + return + } drives, err := GetLogicalDriveStrings() if err != nil { t.Fatal(err) @@ -393,6 +397,10 @@ func TestGetVolumes(t *testing.T) { } func TestGetVolumePathsForVolume(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("test is not running on latest windows versions. See https://github.com/elastic/gosigar/issues/172") + return + } volumes, err := GetVolumes() if err != nil { t.Fatal(err)