From b3f6685204b727df89c112010c0817b8aece980f Mon Sep 17 00:00:00 2001 From: Darin Spivey Date: Mon, 25 Mar 2024 14:46:56 -0400 Subject: [PATCH] fix(ci): Fix `Jenkinsfile` suitable for the public This repository is now public which forces CI changes to the Jenkinsfile stages. Ref: LOG-19546 --- Jenkinsfile | 136 ++++++++++++++++++---------------------------- package.json | 47 ++++++++++++---- release.config.js | 31 ----------- 3 files changed, 90 insertions(+), 124 deletions(-) delete mode 100644 release.config.js diff --git a/Jenkinsfile b/Jenkinsfile index cef27d0..74b94f5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,15 @@ +library 'magic-butler-catalogue' + def DEFAULT_BRANCH = 'main' -def CURRENT_BRANCH = [env.CHANGE_BRANCH, env.BRANCH_NAME]?.find{branch -> branch != null} +def CURRENT_BRANCH = currentBranch() +def WORKSPACE_PATH = "/tmp/workspace/${env.BUILD_TAG.replace('%2F', '/')}" +def CREDS = [ + string( + credentialsId: 'github-api-token', + variable: 'GITHUB_TOKEN' + ), +] def NPMRC = [ configFile(fileId: 'npmrc', variable: 'NPM_CONFIG_USERCONFIG') ] @@ -8,8 +17,8 @@ def NPMRC = [ pipeline { agent { node { - label 'ec2-fleet' - customWorkspace("/tmp/workspace/${env.BUILD_TAG}") + label 'rust-x86_64' + customWorkspace(WORKSPACE_PATH) } } @@ -17,27 +26,18 @@ pipeline { timeout time: 1, unit: 'HOURS' timestamps() ansiColor 'xterm' + withCredentials(CREDS) } environment { - GITHUB_USER = 'jenkins' - GITHUB_TOKEN = credentials('github-api-token') NPM_CONFIG_CACHE = '.npm' SPAWN_WRAP_SHIM_ROOT = '.npm' RUSTUP_HOME = '/opt/rust/rustup' CARGO_HOME = '/opt/rust/cargo' - CARGO_REGISTRIES_CRATES_IO_PROTOCOL = 'sparse' PATH = """${sh( returnStdout: true, script: 'echo /opt/rust/cargo/bin:\$PATH' )} - """ - // for the semantic-release-rust executable, we must have this set even when not publishing the crate directly - CARGO_REGISTRY_TOKEN = "not-in-use" - LAST_COMMITTER = sh(script: 'git log -1 --format=%ae', returnStdout: true).trim() - } - - tools { - nodejs 'NodeJS 14' + // """ } post { @@ -47,92 +47,64 @@ pipeline { } stages { - stage('Lint and Test') { - parallel { - stage('Lint') { - agent { - docker { - label 'ec2-fleet' - customWorkspace "/tmp/workspace/${BUILD_TAG}" - image 'us.gcr.io/logdna-k8s/rust:bullseye-1-stable-x86_64' - reuseNode true - } - } - steps { - sh 'make lint' - } - } - stage('Unit Tests') { - agent { - docker { - label 'ec2-fleet' - customWorkspace "/tmp/workspace/${BUILD_TAG}" - image 'us.gcr.io/logdna-k8s/rust:bullseye-1-stable-x86_64' - reuseNode true - } - } - steps { - sh 'make test' - } + stage('Validate PR Source') { + when { + expression { env.CHANGE_FORK } + not { + triggeredBy 'issueCommentCause' } } + steps { + error("A maintainer needs to approve this PR for CI by commenting") + } } - stage('Release Lint and Test') { - stages { - stage('Validate') { - steps { - script { - sh "mkdir -p ${NPM_CONFIG_CACHE}" - configFileProvider(NPMRC) { - sh 'npm i && npm run lint' - } - } + stage('Commitlint and dry release test'){ + tools { + nodejs 'NodeJS 20' + } + environment { + GIT_BRANCH = "${CURRENT_BRANCH}" + // This is not populated on PR builds and is needed for the release dry runs + BRANCH_NAME = "${CURRENT_BRANCH}" + CHANGE_ID = "" + } + steps { + script { + configFileProvider(NPMRC) { + sh 'npm install --ignore-scripts' + sh 'npm run commitlint' + sh 'npm run release:dry' } } + } + } - stage('Release Test') { - when { - not { - branch 'main' - } - } - environment { - GIT_BRANCH = "${CURRENT_BRANCH}" - BRANCH_NAME = "${CURRENT_BRANCH}" - RUSTUP_HOME = '/opt/rust/cargo' - CHANGE_ID = "" - } - steps { - script { - sh "mkdir -p ${NPM_CONFIG_CACHE}" - sh "unset CARGO_REGISTRIES_CRATES_IO_PROTOCOL; cargo install cargo-edit" - configFileProvider(NPMRC) { - sh 'npm i && npm run release:dry' - } - } - } - } + stage('Unit Tests') { + steps { + sh "make clean" + sh 'make test' + } + } + stage('Clippy') { + steps { + // `cargo-audit` is installed on `make test` stage + sh 'make lint' } } stage('Release') { when { - beforeAgent true branch DEFAULT_BRANCH - not { - changelog '\\[skip ci\\]' - } } - environment { - RUSTUP_HOME = '/opt/rust/cargo' + tools { + nodejs 'NodeJS 20' } steps { script { - sh "mkdir -p ${NPM_CONFIG_CACHE}" - sh "unset CARGO_REGISTRIES_CRATES_IO_PROTOCOL; cargo install cargo-edit" configFileProvider(NPMRC) { - sh 'npm i && npm run release' + sh 'npm install' + sh 'npm run release' } } } diff --git a/package.json b/package.json index 77cab3b..3a0a674 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,50 @@ { - "name": "@answerbook/opentelemetry-rs", + "name": "@mezmo/opentelemetry-rs", "description": "A library providing quick-protobuf bindings and RFC compliant validation for OpenTelemetry metrics and logs types", - "version": "0.0.0", - "private": true, + "license": "Mozilla Public License 2.0", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/mezmo/opentelemetry-rs.git" + }, + "version": "1.2.1", "files": [ - "release.config.js", "README.md" ], "scripts": { - "lint": "commitlint-logdna", + "commitlint": "./node_modules/.bin/commitlint-logdna", "release": "semantic-release", "release:dry": "semantic-release --no-ci --dry-run --branches=${BRANCH_NAME:-main}" }, - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/answerbook/opentelemetry-rs.git" + "release": { + "branches": [ + "main" + ], + "extends": [ + "@answerbook/release-config-logdna" + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/changelog", { + "changelogFile": "CHANGELOG.md" + } + ], + [ + "@semantic-release/github", { + "assets": "CHANGELOG.md" + } + ], + [ + "@semantic-release/git", { + "assets": "CHANGELOG.md" + } + ] + ] }, - "license": "SEE LICENSE IN LICENSE", "devDependencies": { "@answerbook/commitlint-config-logdna": "^2.1.0", - "@answerbook/release-config-logdna": "^1.3.0", - "semantic-release": "^18.0.1" + "@answerbook/release-config-logdna": "^2.0.1", + "semantic-release": "^19.0.5" } } diff --git a/release.config.js b/release.config.js deleted file mode 100644 index f8805e3..0000000 --- a/release.config.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict' - -const now = new Date() -const year = now.getFullYear() -const day = String(now.getDate()).padStart(2, '0') -const month = String(now.getMonth() + 1).padStart(2, '0') - -module.exports = { - extends: '@answerbook/release-config-logdna' -, branches: ['main'] -, plugins: [ - '@semantic-release/commit-analyzer', - '@semantic-release/release-notes-generator', - '@semantic-release/changelog', - ['@semantic-release/exec', { - prepareCmd: 'cargo set-version ${nextRelease.version} && ' - + 'cargo package --allow-dirty --target-dir dist; sleep 2' - }], - '@semantic-release/github', - ['@semantic-release/git', { - assets: [ - "CHANGELOG.md", - "package.json", - "Cargo*", - "dist/*" - ] - , message: `release: ${year}-${month}-${day}, ` - + 'Version <%= nextRelease.version %> [skip ci]' - }] - ] -}