Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/testRail-evidence-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: "TestRail evidence integration example"
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
actions: read
jobs:
testRail-evidence-example:
runs-on: ubuntu-latest
env:
REGISTRY_URL: ${{ vars.JF_URL }}
REPO_NAME: 'docker-testrail-repo'
IMAGE_NAME: 'docker-testrail-image'
TAG_NAME: ${{ github.run_number }}
BUILD_NAME: 'testrail-docker-build'
BUILD_NUMBER: ${{ github.run_number }}
ATTACH_OPTIONAL_MARKDOWN_TO_EVIDENCE: true
steps:
- uses: jfrog/setup-jfrog-cli@v4
name: jfrog-cli setup
env:
JF_URL: ${{ vars.ARTIFACTORY_URL }}
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
examples/testRail/**
sparse-checkout-cone-mode: false
- name: Build and publish Docker image
run: |
docker build . --file ./examples/testRail/Dockerfile --tag $REGISTRY_URL/$REPO_NAME/$IMAGE_NAME:$TAG_NAME
jf rt docker-push $REGISTRY_URL/$REPO_NAME/$IMAGE_NAME:$TAG_NAME $REPO_NAME --build-name=$BUILD_NAME --build-number=$BUILD_NUMBER
jf rt build-publish $BUILD_NAME $BUILD_NUMBER

# Steps to run automated tests
- name: Automated tests run
uses: cypress-io/github-action@v6
with:
install: true
install-command: npm install
start: npm run start
quiet: true
wait-on: 'http://localhost:3000/app.html'
wait-on-timeout: 120
working-directory: examples/testRail
continue-on-error: true
- name: Merge test run results
run: |
npm run merge-json
npm run merge-junit
working-directory: examples/testRail

# Upload automated test runs reports to TestRail
- name: Upload Results to TestRail UI
uses: gurock/trcli-action@main
with:
host: ${{ secrets.TESTRAIL_HOST }}
username: ${{ secrets.TESTRAIL_USERNAME }}
password: ${{ secrets.TESTRAIL_API_KEY }}
project: 'TestRail Project'
report_file_path: './examples/testRail/reports/junit-report.xml'
title: 'Automated Test Run Results'
run_description: 'GitHub Workflow Run Id: $BUILD_NUMBER'
auto_create_cases_yes: 'true'
close_run: 'true'

# This is an optional step to generate a markdown report
- name: Generate optional markdown report
if: env.ATTACH_OPTIONAL_MARKDOWN_TO_EVIDENCE == 'true'
run: npm run generate:md
working-directory: examples/testRail
env:
IMAGE_REF: ${{ env.REGISTRY_URL }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }}

#Steps to attach evidence to the package
- name: Attach evidence to the package
working-directory: examples/testRail
run: |
jf evd create \
--package-name $IMAGE_NAME \
--package-version $TAG_NAME \
--package-repo-name $REPO_NAME \
--key "${{ secrets.PRIVATE_KEY }}" \
--key-alias "${{ secrets.PRIVATE_KEY_ALIAS }}" \
--predicate "reports/overall-report.json" \
--predicate-type "http://testrail.com/test-results" \
${{ env.ATTACH_OPTIONAL_MARKDOWN_TO_EVIDENCE == 'true' && '--markdown "reports/results.md"' || '' }}
18 changes: 18 additions & 0 deletions examples/testRail/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use official Node.js image
FROM node:20

# Set working directory
WORKDIR /app

# Copy package files and install dependencies
COPY examples/testRail/package*.json ./
RUN npm install

# Copy the rest of the app
COPY . .

# Expose the port your app runs on (adjust if needed)
EXPOSE 3000

# Start the app
CMD ["npm", "run", "start"]
117 changes: 117 additions & 0 deletions examples/testRail/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# TestRail Evidence Integration Example

This project demonstrates how to automate end-to-end testing for Dockerized applications, upload test results to TestRail, and attach the signed test results as evidence to the Docker image in JFrog Artifactory using GitHub Actions and JFrog CLI.

## Overview

The workflow builds a Docker image, runs automated tests, uploads test results to TestRail, generates test result evidence (JSON and Markdown), pushes the image to Artifactory, and attaches the signed TestRail test results as evidence to the image package. This enables traceability and compliance for testing in your CI/CD pipeline with TestRail integration.

## Prerequisites

- JFrog CLI 2.65.0 or above (installed automatically in the workflow)
- Artifactory configured as a Docker registry
- TestRail instance with API access
- The following GitHub repository variables:
- `JF_URL` (Artifactory Docker registry domain, e.g. `mycompany.jfrog.io`)
- `ARTIFACTORY_URL` (Artifactory base URL)
- The following GitHub repository secrets:
- `JF_ACCESS_TOKEN` (Artifactory access token)
- `PRIVATE_KEY` (Private key for signing evidence)
- `PRIVATE_KEY_ALIAS` (Key alias for signing evidence)
- `TESTRAIL_HOST` (TestRail instance URL)
- `TESTRAIL_USERNAME` (TestRail username)
- `TESTRAIL_API_KEY` (TestRail API key)

## Environment Variables Used

- `REGISTRY_URL` - Docker registry domain (from `JF_URL`)
- `REPO_NAME` - Docker repository name
- `IMAGE_NAME` - Docker image name
- `TAG_NAME` - Docker image tag (uses GitHub run number)
- `BUILD_NAME` - Build name for Artifactory
- `BUILD_NUMBER` - Build number (uses GitHub run number)
- `ATTACH_OPTIONAL_MARKDOWN_TO_EVIDENCE` - Set to `true` to attach a Markdown report as evidence

## Workflow

```mermaid
graph TD
A[Workflow Dispatch Trigger] --> B[Setup JFrog CLI]
B --> C[Checkout Repository]
C --> D[Build and Publish Docker Image]
D --> E[Run Automated Tests]
E --> F[Merge Test Run Results]
F --> G[Upload Results to TestRail]
G --> H{Attach Optional Markdown Report?}
H -->|Yes| I[Generate Markdown Report]
H -->|No| J[Skip Markdown Report]
I --> K[Attach Evidence to Package]
J --> K[Attach Evidence to Package]
```

## Example Usage

You can trigger the workflow manually from the GitHub Actions tab. The workflow will:

- Build and test the Docker image
- Run Automated Tests
- Merge test results (JSON and JUnit XML)
- Upload test results to TestRail
- Push the image to Artifactory
- Attach the TestRail test results as evidence

## Key Commands Used

- **Build and Push Docker Image:**
```bash
docker build . --file ./examples/testRail/Dockerfile --tag $REGISTRY_URL/$REPO_NAME/$IMAGE_NAME:$TAG_NAME
jf rt docker-push $REGISTRY_URL/$REPO_NAME/$IMAGE_NAME:$TAG_NAME $REPO_NAME --build-name=$BUILD_NAME --build-number=$BUILD_NUMBER
jf rt build-publish $BUILD_NAME $BUILD_NUMBER
```

- **Run Automated Tests:**
```yaml
uses: cypress-io/github-action@v6
with:
install: true
install-command: npm install
start: npm run start
quiet: true
wait-on: 'http://localhost:3000/app.html'
wait-on-timeout: 120
working-directory: examples/testRail
continue-on-error: true

- **Upload Results to TestRail:**
```yaml
uses: gurock/trcli-action@main
with:
host: ${{ secrets.TESTRAIL_HOST }}
username: ${{ secrets.TESTRAIL_USERNAME }}
password: ${{ secrets.TESTRAIL_API_KEY }}
project: 'TestRail Project'
report_file_path: './examples/testRail/reports/junit-report.xml'
title: 'Automated Test Run Results'
run_description: 'GitHub Workflow Run Id: $BUILD_NUMBER'
auto_create_cases_yes: 'true'
close_run: 'true'
```

- **Attach Evidence:**
```bash
jf evd create \
--package-name $IMAGE_NAME \
--package-version $TAG_NAME \
--package-repo-name $REPO_NAME \
--key "${{ secrets.PRIVATE_KEY }}" \
--key-alias "${{ secrets.PRIVATE_KEY_ALIAS }}" \
--predicate "reports/overall-report.json" \
--predicate-type "http://testrail.com/test-results" \
[--markdown "reports/results.md"]
```
The --markdown flag is included only if ATTACH_OPTIONAL_MARKDOWN_TO_EVIDENCE is set to true.

## References
- [TestRail API Documentation](https://support.testrail.com/hc/en-ust)
- [JFrog Evidence Management](https://jfrog.com/help/r/jfrog-artifactory-documentation/evidence-management)
- [JFrog CLI Documentation](https://jfrog.com/getcli/)
27 changes: 27 additions & 0 deletions examples/testRail/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
projectId: "my-example", // Replace with your actual project ID
fixturesFolder: false,
reporter: "cypress-multi-reporters",
reporterOptions: {
reporterEnabled: "mochawesome, mocha-junit-reporter",
mochawesomeReporterOptions: {
reportDir: "reports",
reportFilename: "test-results.json",
overwrite: false,
html: false,
json: true
},
mochaJunitReporterReporterOptions: {
mochaFile: "reports/junit-results-[hash].xml",
toConsole: false
}
},
e2e: {
supportFile: 'tests/support/e2e.js',
setupNodeEvents(on, config) {},
baseUrl: "http://localhost:3000",
specPattern: "tests/e2e/*.cy.js"
},
});
Loading