From 5a3a08bd020992747fd14b9ecf8cdc84629f3c9f Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 21 Dec 2022 16:45:12 +0100 Subject: [PATCH 1/6] Migrate Jenkinsfile to GH Actions Workflow --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++-- .pre-commit-config.yaml | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 978f9f6..2a6a30b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,31 @@ permissions: contents: read jobs: - hello: + sanity-checks: runs-on: ubuntu-latest steps: - - run: echo "Hello, World!" + - uses: elastic/apm-pipeline-library/.github/actions/pre-commit@current + test: + strategy: + fail-fast: false + matrix: + php-image: + - 7.2-alpine + - 7.3-alpine + - 7.4-alpine + - 8.0-alpine + runs-on: ubuntu-latest + container: php:${{ matrix.php-image }} + steps: + - uses: actions/checkout@v3 + - name: Append PATH + run: echo "${GITHUB_WORKSPACE}" >> $GITHUB_PATH + - name: Install composer + run: .ci/scripts/install-composer.sh + - name: Install dependencies + run: composer --no-progress install + - name: Run tests + env: + VERSION: ${{ matrix.php-image }} + run: composer test + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 18fb3c5..ef0056f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: check-executables-have-shebangs - id: check-merge-conflict -- repo: git@github.com:elastic/apm-pipeline-library +- repo: https://github.com/elastic/apm-pipeline-library rev: current hooks: - id: check-bash-syntax From 4f84d820cfa884267969f7a6be2a6250443b4d13 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 10 Feb 2023 08:51:58 +0100 Subject: [PATCH 2/6] Add test-reporter --- .github/workflows/opentelemetry.yml | 1 + .github/workflows/test-reporter.yml | 20 ++++++++++++++++++++ .github/workflows/test.yml | 5 ++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-reporter.yml diff --git a/.github/workflows/opentelemetry.yml b/.github/workflows/opentelemetry.yml index e91fc5b..f1e39a6 100644 --- a/.github/workflows/opentelemetry.yml +++ b/.github/workflows/opentelemetry.yml @@ -5,6 +5,7 @@ on: workflow_run: workflows: - test + - test-reporter - update-specs types: [completed] diff --git a/.github/workflows/test-reporter.yml b/.github/workflows/test-reporter.yml new file mode 100644 index 0000000..f132e97 --- /dev/null +++ b/.github/workflows/test-reporter.yml @@ -0,0 +1,20 @@ +--- +## Workflow to process the JUnit test results and add a report to the checks. +name: test-reporter +on: + workflow_run: + workflows: + - test + types: + - completed + +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: elastic/apm-pipeline-library/.github/actions/test-report@current + with: + artifact: test-results # artifact name + name: test-report # Name of the check run which will be created + path: "junit-*.xml" # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a6a30b..fae3aaf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,4 +40,7 @@ jobs: env: VERSION: ${{ matrix.php-image }} run: composer test - + - uses: actions/upload-artifact@v3 + with: + name: test-results + path: junit-*.xml From e905ebc13928e14e860c8b04d76eb3eadba5de71 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 13 Feb 2023 11:41:52 +0100 Subject: [PATCH 3/6] Add release --- .github/workflows/opentelemetry.yml | 1 + .github/workflows/release.yml | 37 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/opentelemetry.yml b/.github/workflows/opentelemetry.yml index f1e39a6..e93cb0b 100644 --- a/.github/workflows/opentelemetry.yml +++ b/.github/workflows/opentelemetry.yml @@ -7,6 +7,7 @@ on: - test - test-reporter - update-specs + - release types: [completed] jobs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..239f754 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: release + +on: + push: + tags: + - v?[0-9]+.[0-9]+.[0-9]+ + +permissions: + contents: write + +jobs: + test: + uses: ./.github/workflows/test.yml + release: + needs: + - test + runs-on: ubuntu-latest + steps: + - name: release + run: make -f .ci/Makefile release + env: + GITHUB_TOKEN: ${{ github.token }} + TAG_NAME: ${{ github.ref_name }} + notify: + runs-on: ubuntu-latest + if: always() + needs: + - release + steps: + - run: test $(echo '${{ toJSON(needs) }}' | jq -s 'map(.[].result) | all(.=="success")') = 'true' + - if: always() + uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current + with: + vaultUrl: ${{ secrets.VAULT_ADDR }} + vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} + vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} + slackChannel: "#apm-agent-php" From ecb9d388d40fff8084aabdd290dd9c300a529a3b Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 13 Feb 2023 11:43:16 +0100 Subject: [PATCH 4/6] Remove jenkins related configs --- .ci/Jenkinsfile | 2 +- .ci/jobs/defaults.yml | 59 -------------------------------- .ci/jobs/ecs-logging-php-mbp.yml | 5 --- .github/workflows/test.yml | 2 ++ 4 files changed, 3 insertions(+), 65 deletions(-) delete mode 100644 .ci/jobs/defaults.yml delete mode 100644 .ci/jobs/ecs-logging-php-mbp.yml diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 8b7803a..675eb68 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -1,4 +1,4 @@ -#!/usr/bin/env groovy +/usr/bin/env groovy @Library('apm@current') _ diff --git a/.ci/jobs/defaults.yml b/.ci/jobs/defaults.yml deleted file mode 100644 index 8d96b47..0000000 --- a/.ci/jobs/defaults.yml +++ /dev/null @@ -1,59 +0,0 @@ ---- - -##### GLOBAL METADATA - -- meta: - cluster: apm-ci - -##### JOB DEFAULTS - -- job: - view: APM-CI - project-type: multibranch - logrotate: - daysToKeep: 30 - numToKeep: 100 - number-to-keep: '5' - days-to-keep: '1' - concurrent: true - node: linux - 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 - repo: ecs-logging-php - 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: 3 - do-not-fetch-tags: true - submodule: - disable: false - recursive: true - parent-credentials: true - timeout: 100 - timeout: '15' - use-author: true - wipe-workspace: 'True' - periodic-folder-trigger: 1d - prune-dead-branches: true - publishers: - - email: - recipients: infra-root+build@elastic.co diff --git a/.ci/jobs/ecs-logging-php-mbp.yml b/.ci/jobs/ecs-logging-php-mbp.yml deleted file mode 100644 index c02e78c..0000000 --- a/.ci/jobs/ecs-logging-php-mbp.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- job: - name: apm-agent-php/ecs-logging-php-mbp - display-name: ecs-logging-php - description: Centralized logging for PHP applications with the Elastic stack diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fae3aaf..39296c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,8 @@ jobs: - 7.3-alpine - 7.4-alpine - 8.0-alpine + - 8.1-alpine + - 8.2-alpine runs-on: ubuntu-latest container: php:${{ matrix.php-image }} steps: From bea28a5f6fa6996bdd125a1a3f85b883bf82ad36 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 13 Feb 2023 11:46:10 +0100 Subject: [PATCH 5/6] Remove unnecessary hooks --- .pre-commit-config.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef0056f..323c744 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,5 +10,3 @@ repos: rev: current hooks: - id: check-bash-syntax - - id: check-jenkins-pipelines - - id: check-jjbb From b2402a73a75a6e82096d512cdfed1d0b356b8d98 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 13 Feb 2023 15:37:29 +0100 Subject: [PATCH 6/6] Remove Jenkinsfile --- .ci/Jenkinsfile | 167 ------------------------------------------------ 1 file changed, 167 deletions(-) delete mode 100644 .ci/Jenkinsfile diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile deleted file mode 100644 index 675eb68..0000000 --- a/.ci/Jenkinsfile +++ /dev/null @@ -1,167 +0,0 @@ -/usr/bin/env groovy - -@Library('apm@current') _ - -pipeline { - agent { label 'linux && immutable' } - environment { - REPO = 'ecs-logging-php' - BASE_DIR = "src/go.elastic.co/apm/${env.REPO}" - NOTIFY_TO = credentials('notify-to') - JOB_GCS_BUCKET = credentials('gcs-bucket') - SLACK_CHANNEL = '#apm-agent-php' - } - options { - timeout(time: 1, unit: 'HOURS') - buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30')) - timestamps() - ansiColor('xterm') - disableResume() - durabilityHint('PERFORMANCE_OPTIMIZED') - rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) - quietPeriod(10) - } - triggers { - issueCommentTrigger("${obltGitHubComments()}") - } - stages { - stage('Notify') { - options { skipDefaultCheckout() } - when { - tag pattern: '\\d+.*', comparator: 'REGEXP' - } - steps { - notifyStatus(slackStatus: 'warning', subject: "[${env.REPO}] Release *${env.TAG_NAME}* build just started", - body: "Build: (<${env.RUN_DISPLAY_URL}|here>)") - } - } - stage('Checkout') { - options { skipDefaultCheckout() } - steps { - pipelineManager([ cancelPreviousRunningBuilds: [ when: 'PR' ] ]) - deleteDir() - gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true) - stash allowEmpty: true, name: 'source', useDefaultExcludes: false - } - } - stage('Sanity checks') { - options { skipDefaultCheckout() } - steps { - deleteDir() - unstash 'source' - dir("${BASE_DIR}"){ - preCommit(commit: "${GIT_BASE_COMMIT}", junit: true) - } - } - } - stage('Test'){ - parallel { - stage('on PHP 7.2') { - steps { - buildWithGitHubNotification('7.2-alpine') - } - } - stage('on PHP 7.3') { - agent { label 'linux && immutable' } - steps { - buildWithGitHubNotification('7.3-alpine') - } - } - stage('on PHP 7.4') { - agent { label 'linux && immutable' } - steps { - buildWithGitHubNotification('7.4-alpine') - } - } - stage('on PHP 8.0') { - agent { label 'linux && immutable' } - steps { - buildWithGitHubNotification('8.0-alpine') - } - } - stage('on PHP 8.1') { - agent { label 'linux && immutable' } - steps { - buildWithGitHubNotification('8.1-alpine') - } - } - stage('on PHP 8.2') { - agent { label 'linux && immutable' } - steps { - buildWithGitHubNotification('8.2-alpine') - } - } - } - } - stage('Release') { - options { skipDefaultCheckout() } - when { - beforeAgent true - tag pattern: '\\d+.*', comparator: 'REGEXP' - } - agent { label 'docker && ubuntu-18.04 && immutable' } - environment { - RELEASE_URL_MESSAGE = "()" - } - steps { - deleteDir() - unstash 'source' - dir("${BASE_DIR}") { - withCredentials([string(credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7', variable: 'GITHUB_TOKEN')]) { - sh(script: 'make -f .ci/Makefile release', label: 'release') - } - } - } - post { - failure { - notifyStatus(slackStatus: 'danger', subject: "[${env.REPO}] Release *${env.TAG_NAME}* failed", body: "Build: (<${env.RUN_DISPLAY_URL}|here>)") - } - success { - notifyStatus(slackStatus: 'good', subject: "[${env.REPO}] Release *${env.TAG_NAME}* published", body: "Build: (<${env.RUN_DISPLAY_URL}|here>)\nRelease URL: ${env.RELEASE_URL_MESSAGE}") - } - always { - script { - currentBuild.description = "${currentBuild.description?.trim() ? currentBuild.description : ''} released" - } - } - } - } - } - post { - cleanup { - notifyBuildResult() - } - } -} - -def build(version){ - deleteDir() - unstash 'source' - dir("${BASE_DIR}"){ - try { - docker.image("php:${version}").inside("-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${WORKSPACE}/${BASE_DIR}") { - sh(label: 'Install composer', script: '.ci/scripts/install-composer.sh') - sh(label: 'Install dependencies', script: 'composer --no-progress --no-ansi install') - sh(label: 'Run tests', script: "VERSION=${version} composer test") - } - } catch(e){ - error(e.toString()) - } finally { - junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'junit-*.xml') - } - } -} - -def buildWithGitHubNotification(version){ - withGithubNotify(context: "php-${version}") { - build(version) - } -} - -def notifyStatus(def args = [:]) { - slackSend(channel: env.SLACK_CHANNEL, color: args.slackStatus, message: "${args.subject}. ${args.body}", - tokenCredentialId: 'jenkins-slack-integration-token') - // transform slack URL format '()' to 'URL'. - def bodyEmail = args.body.replaceAll('\\(<', '').replaceAll('\\|.*>\\)', '') - emailext(subject: args.subject, to: "${env.NOTIFY_TO}", body: bodyEmail) -}