Skip to content

Commit

Permalink
Merge branch 'feature/centos-repository-switch' of https://github.com…
Browse files Browse the repository at this point in the history
…/opendevstack/ods-quickstarters into feature/centos-repository-switch
  • Loading branch information
BraisVQ committed Oct 15, 2024
2 parents 3e45aba + 0b5e93f commit 44924dd
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog-enforcer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].0
- uses: actions/[email protected].1
- uses: dangoslen/changelog-enforcer@v3
with:
changeLogPath: 'CHANGELOG.md'
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/golang/docker
Expand All @@ -24,7 +24,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/jdk/docker
Expand All @@ -41,7 +41,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/nodejs16/docker
Expand All @@ -57,7 +57,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/nodejs18/docker
Expand All @@ -73,7 +73,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/nodejs20/docker
Expand All @@ -89,7 +89,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/nodejs22/docker
Expand All @@ -105,7 +105,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/python/docker
Expand All @@ -118,7 +118,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/rust/docker
Expand All @@ -138,7 +138,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/terraform/docker
Expand All @@ -151,7 +151,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/terraform-2306/docker
Expand All @@ -164,7 +164,7 @@ jobs:
steps:
-
name: Checkout repository
uses: actions/[email protected].0
uses: actions/[email protected].1
-
name: Build docker image
working-directory: common/jenkins-agents/scala/docker
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Add microsoft-edge to nodejs agents for using with cypress ([#1063](https://github.com/opendevstack/ods-quickstarters/pull/1063))
- Replaced centos8 repository for AlmaLinux 8 due to deprecation ([#1063](https://github.com/opendevstack/ods-quickstarters/pull/1063))
- Replaced centos8 repository for rockylinux 8 due to deprecation in terraform agents ([#1067](https://github.com/opendevstack/ods-quickstarters/pull/1067))
- Improvements in the reporter for cypress ([#1042](https://github.com/opendevstack/ods-quickstarters/issues/1042))

### Added

Expand Down Expand Up @@ -467,4 +468,4 @@

## [0.1.0 ods-project-quickstarters] - 2018-07-27

Initial release.
Initial release.
4 changes: 3 additions & 1 deletion docs/modules/quickstarters/pages/e2e-cypress.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ This is a Cypress end-to-end testing project quickstarter with basic setup for h
├── fixtures
│ └── example.json
├── plugins
│ └── index.js
│ ├── index.ts
│ ├── screenshot.ts
│ └── screenshot.types.ts
├── reporters
│ └── custom-reporter.js
├── support
Expand Down
31 changes: 25 additions & 6 deletions e2e-cypress/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ odsComponentPipeline(
// 'release/': 'test'
]
) { context ->

def targetDirectory = "${context.projectId}/${context.componentId}/${context.gitBranch.replaceAll('/', '-')}/${context.buildNumber}"

stageTest(context)
odsComponentStageScanWithSonar(context)


if (fileExists('cypress/screenshots.zip')) {
odsComponentStageUploadToNexus(context,
[
distributionFile: 'cypress/screenshots.zip',
repository: 'leva-documentation',
repositoryType: 'raw',
targetDirectory: "${targetDirectory}"
]
)
}

}

def stageTest(def context) {
stage('Integration Test') {
// OPTIONAL: load environment variables for Azure SSO with MSALv2; please adapt variable names to your OpenShift config
Expand All @@ -54,6 +66,8 @@ def stageTest(def context) {
// "CYPRESS_CLIENT_SECRET=${azureClientSecret}",
// "CYPRESS_USERNAME=${cypressUser}",
// "CYPRESS_PASSWORD=${cypressPassword}"
"COMMIT_INFO_SHA=${context.gitCommit}",
"BUILD_NUMBER=${context.buildNumber}",
]) {
sh 'npm install'
def status = sh(script: 'npm run e2e', returnStatus: true)
Expand All @@ -62,14 +76,19 @@ def stageTest(def context) {
stash(name: "installation-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/installation-junit.xml', allowEmpty: true)
stash(name: "integration-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/integration-junit.xml', allowEmpty: true)
stash(name: "acceptance-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/acceptance-junit.xml', allowEmpty: true)
zip zipFile: 'cypress/videos.zip', archive: false, dir: 'cypress/videos'
stash(name: "acceptance-test-videos-${context.componentId}-${context.buildNumber}", includes: 'cypress/videos.zip', allowEmpty: true)
archiveArtifacts artifacts: 'cypress/videos.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3
if (status != 0) {

if (fileExists('cypress/videos')) {
zip zipFile: 'cypress/videos.zip', archive: false, dir: 'cypress/videos'
stash(name: "acceptance-test-videos-${context.componentId}-${context.buildNumber}", includes: 'cypress/videos.zip', allowEmpty: true)
archiveArtifacts artifacts: 'cypress/videos.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3
}

if (fileExists('cypress/screenshots')) {
zip zipFile: 'cypress/screenshots.zip', archive: false, dir: 'cypress/screenshots'
stash(name: "acceptance-test-screenshots-${context.componentId}-${context.buildNumber}", includes: 'cypress/screenshots.zip', allowEmpty: true)
archiveArtifacts artifacts: 'cypress/screenshots.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3
}

return status
}
}
Expand Down
4 changes: 2 additions & 2 deletions e2e-cypress/files/cypress-acceptance.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default defineConfig({
viewportHeight: 660,
experimentalModifyObstructiveThirdPartyCode:true,
video: true,
setupNodeEvents(on, config) {
return require('./plugins/index.js')(on, config)
async setupNodeEvents(on, config) {
return (await import('./plugins/index')).default(on, config);
},
},
})
4 changes: 2 additions & 2 deletions e2e-cypress/files/cypress-installation.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default defineConfig({
viewportHeight: 660,
experimentalModifyObstructiveThirdPartyCode:true,
video: true,
setupNodeEvents(on, config) {
return require('./plugins/index.js')(on, config)
async setupNodeEvents(on, config) {
return (await import('./plugins/index')).default(on, config);
},
},
})
4 changes: 2 additions & 2 deletions e2e-cypress/files/cypress-integration.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default defineConfig({
viewportHeight: 660,
experimentalModifyObstructiveThirdPartyCode:true,
video: true,
setupNodeEvents(on, config) {
return require('./plugins/index.js')(on, config)
async setupNodeEvents(on, config) {
return (await import('./plugins/index')).default(on, config);
},
},
})
4 changes: 2 additions & 2 deletions e2e-cypress/files/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default defineConfig({
viewportHeight: 660,
experimentalModifyObstructiveThirdPartyCode: true,
video: true,
setupNodeEvents(on, config) {
return require('./plugins/index.js')(on, config)
async setupNodeEvents(on, config) {
return (await import('./plugins/index')).default(on, config);
},
},
})
1 change: 1 addition & 0 deletions e2e-cypress/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"mocha-junit-reporter": "^2.2.1",
"npm-run-all": "^4.1.5",
"rimraf": "^6.0.1",
"sharp": "^0.33.5",
"typescript": "^5.5.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
// https://on.cypress.io/plugins-guide
// ***********************************************************

import type { ScreenshotEvidenceData } from './screenshot.types';
import { addEvidenceMetaToScreenshot } from './screenshot';

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
const setupNodeEvents: NonNullable<Cypress.ConfigOptions['setupNodeEvents']> = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
log(message) {
console.log(message);
return null;
},
async takeScreenshotEvidence(data: ScreenshotEvidenceData) {
return await addEvidenceMetaToScreenshot(data);
}
});
};

export default setupNodeEvents;
61 changes: 61 additions & 0 deletions e2e-cypress/files/plugins/screenshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { createHash } from 'crypto';
import { writeFile } from 'fs/promises';
import * as sharp from 'sharp';
import { ScreenshotEvidenceData, ScreenshotEvidenceResult } from './screenshot.types';

const SCREENSHOT_METADATA = {
height: 50,
margin: 10,
textAlign: 'left',
textColor: '#000',
textSize: 'large',
backgroundColor: '#fff',
maxNameLength: 100,
} as const;
const EVIDENCE_HASH_ALGORITHM = 'sha256' as const;

export const addEvidenceMetaToScreenshot = async (data: ScreenshotEvidenceData): Promise<ScreenshotEvidenceResult> => {
const metadata: [string, string][] = [
['Timestamp', data.takenAt],
['Testname', data.name.substring(0, SCREENSHOT_METADATA.maxNameLength)],
['Step', data.step.toString()],
['Screenshot', data.subStep.toString()],
['Build number', process.env.BUILD_NUMBER ?? '-'],
['Git commit', process.env.COMMIT_INFO_SHA ?? '-'],
];

const image = sharp(data.path);
const imageMetadata = await image.metadata();
const imageBuffer = await image
.resize({
background: SCREENSHOT_METADATA.backgroundColor,
fit: 'contain',
height: (imageMetadata.height ?? 0) + SCREENSHOT_METADATA.height,
position: 'bottom',
width: imageMetadata.width ?? 0,
})
.composite([
{
input: {
text: {
align: SCREENSHOT_METADATA.textAlign,
rgba: true,
text: metadata
.map(([key, value]) => `<span foreground="${SCREENSHOT_METADATA.textColor}" size="${SCREENSHOT_METADATA.textSize}"><b>${key}</b>: ${value}</span>`)
.join('\t'),
width: (imageMetadata.width ?? 0) - SCREENSHOT_METADATA.margin * 2,
},
},
left: SCREENSHOT_METADATA.margin,
top: SCREENSHOT_METADATA.margin,
},
])
.toBuffer();
await writeFile(data.path, imageBuffer);

const hash = createHash(EVIDENCE_HASH_ALGORITHM).update(imageBuffer).digest('hex');
return {
hash,
path: data.path,
}
};
21 changes: 21 additions & 0 deletions e2e-cypress/files/plugins/screenshot.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type ScreenshotEvidenceData = {
name: string;
path: string;
step: number;
subStep: number;
takenAt: string;
};

export type ScreenshotEvidenceResult = {
hash: string;
path: string;
};
export const isScreenshotEvidenceResult = (candidate: unknown): candidate is ScreenshotEvidenceResult =>
Boolean(
typeof candidate === 'object' &&
candidate &&
'hash' in candidate &&
'path' in candidate &&
typeof candidate.hash === 'string' &&
typeof candidate.path === 'string'
);
13 changes: 3 additions & 10 deletions e2e-cypress/files/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,10 @@ Cypress.Commands.add('loginToAAD', (username: string, password: string) => {
log.end()
})

let consoleLogs: string[] = []

Cypress.on('log:added', (options) => {
const message = options.message;
if(message) {
consoleLogs.push(message);
}
});
export const consoleLogs: string[] = [];

beforeEach(function() {
consoleLogs = [];
consoleLogs.splice(0);
})

afterEach(function() {
Expand All @@ -88,5 +81,5 @@ afterEach(function() {

cy.writeFile(filePath, consoleLogs.join('\n'));

consoleLogs = [];
consoleLogs.splice(0);
})
Loading

0 comments on commit 44924dd

Please sign in to comment.