Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 841ec00

Browse files
Add multi-trail artifact workflow and supporting scripts for Kosli integration
1 parent 69d7b43 commit 841ec00

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Multi Trail Artifact
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "main" branch
8+
push:
9+
branches: [ "main" ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
env: # Set the secret as an input
16+
APP_NAME: ${{ github.event.repository.name }}
17+
BUILD_NUMBER: ${{ github.run_number }}
18+
GIT_REPO: ${{ github.repository }}
19+
GIT_REPO_URL: ${{ github.event.repository.clone_url }}
20+
GIT_BRANCH: ${{ github.ref_name }}
21+
GIT_COMMIT: ${{ github.sha }}
22+
BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
23+
COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
24+
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_KEY }} # Set the Kosli API token as a secret in your repository
25+
KOSLI_ORG: sofusalbertsen
26+
KOSLI_FLOW: multi-trail-artifact
27+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
28+
jobs:
29+
# This workflow contains a single job called "build"
30+
build:
31+
strategy:
32+
matrix:
33+
flow: [1, 2, 3] # Define a matrix to run the same job for multiple flows
34+
# The type of runner that the job will run on
35+
runs-on: ubuntu-latest
36+
37+
# Steps represent a sequence of tasks that will be executed as part of the job
38+
steps:
39+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
40+
- uses: actions/checkout@v4
41+
- name: setup-kosli-cli
42+
uses: kosli-dev/setup-cli-action@v2
43+
- name: Update Flow
44+
run: kosli create flow ${{env.KOSLI_FLOW}}${{matrix.flow}} --description "Flow${{matrix.flow}} for multi-flow-artifact" --template-file=${{env.KOSLI_FLOW}}/kosli-config/flow.yaml
45+
# Runs a single command using the runners shell
46+
- name: run the scenario up
47+
run: bash ${{env.KOSLI_FLOW}}/1.sh
48+
output:
49+
name: kosli-output
50+
runs-on: ubuntu-latest
51+
needs: build
52+
steps:
53+
- name: Check Kosli Output
54+
run: |
55+
kosli get trail -o json ${GIT_COMMIT} > data.json
56+
echo "Kosli output saved to data.json"
57+
cat data.json
58+
- name: opload-artifact
59+
uses: actions/[email protected]
60+
with:
61+
path: data.json
62+
- name: Check Artifacts
63+
run: |
64+
if grep -q '"name": "app"' data.json; then
65+
echo "Artifact 'app' found in the trail."
66+
else
67+
echo "Artifact 'app' not found in the trail."
68+
exit 1
69+
fi

multi-trail-artifact/1.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -e
3+
# Get the current git commit SHA
4+
GIT_SHA=$(git rev-parse HEAD)
5+
ARTIFACT=artifact.txt
6+
# Write the SHA to artifact.txt
7+
echo "Git sha is: $GIT_SHA" > $ARTIFACT
8+
# This script performs the following Kosli operations:
9+
# 1. Begins a new Kosli trail for the specified Git commit, adding a description with the build number.
10+
# 2. Attests an artifact to the Kosli trail, specifying artifact type, commit URL, commit hash, artifact file, build URL, and artifact name.
11+
# 3. Retrieves the Kosli trail data in JSON format and saves it to 'data.json'.
12+
#
13+
# Required environment variables:
14+
# - GIT_COMMIT: The Git commit hash to associate with the Kosli trail.
15+
# - BUILD_NUMBER: The build number for description purposes.
16+
# - COMMIT_URL: The URL to the commit in the source control system.
17+
# - ARTIFACT: The path to the artifact file to attest.
18+
# - BUILD_URL: The URL to the build/job in the CI system.
19+
20+
kosli begin trail ${GIT_COMMIT} --description "build number ${BUILD_NUMBER}"
21+
kosli attest artifact --trail=${GIT_COMMIT} --artifact-type=file --commit-url=${COMMIT_URL} --commit=${GIT_COMMIT} $ARTIFACT --build-url=${BUILD_URL} --name=app
22+
kosli get trail -o json ${GIT_COMMIT} > data.json

multi-trail-artifact/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Multi trail artifact
2+
3+
This scenario exams the way Kosli behaves when the same binary artifact gets created multiple times, either in different flows, or in different git commits.
4+
5+
To test this, we mimic a monorepo. It is set up to have one GH action workflow per `application` in the repo; N workflows.
6+
7+
Given that all workflows riggers on all commits, that would translate into N flows, with N trails, all trails having the same name.
8+
9+
## Scenario 1
10+
11+
What would happen if we were to do a kosli search on an artifact having multiple trails with the same name (stemming from same commit)?
12+
13+
## Scenario 2
14+
15+
What would happen if we do a kosli search on an artifact that has been produced several times over multiple git commits.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
trail:
3+
artifacts:
4+
- name: app
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
set -e
3+
echo "to be implemented"

0 commit comments

Comments
 (0)