From e74955de463d559b408c72d8004be6d79d80c3ff Mon Sep 17 00:00:00 2001 From: Tore Martin Hagen Date: Thu, 19 Jun 2025 14:40:13 +0200 Subject: [PATCH 1/2] MRJP-6 Added Jira issue list custom attestation type --- .github/actions/common/lib-kosli.sh | 18 +++++++++++ .github/workflows/setup-kosli.yml | 30 ++++--------------- Makefile | 4 +++ .../jira-issue-list-schema.json | 19 ++++++++++++ 4 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 Makefile create mode 100644 custom-attestation-types/jira-issue-list-schema.json diff --git a/.github/actions/common/lib-kosli.sh b/.github/actions/common/lib-kosli.sh index 374c7b1..565fb33 100755 --- a/.github/actions/common/lib-kosli.sh +++ b/.github/actions/common/lib-kosli.sh @@ -42,6 +42,12 @@ function get_oldest_commit_sha echo "$envJson" | jq -r '[.[] | .flows[]] | sort_by(.git_commit_info.timestamp) | .[0].git_commit_info.sha1' } +function get_commits_between_tags +{ + local -r oldTag=$1; shift + local -r newTag=$1; shift + git log --format="%H" --reverse ${oldTag}..${newTag} +} function get_commits_between_staging_and_prod { @@ -98,3 +104,15 @@ function get_issue_keys_between_staging_and_prod issueKeys=$(get_all_jira_issue_keys_for_commits ${flowName} "${commits}") echo ${issueKeys} | tr ' ' '\n' | sort -u | tr '\n' ' ' } + +function get_issue_keys_between_commits +{ + local -r oldCommit=$1; shift + local -r newCommit=$1; shift + local -r flowName=$1; shift + + commits=$(get_commits_between_tags ${oldCommit} ${newCommit}) + debug_log "Commits between ${oldCommit} ${newCommit}:\n${commits}" + issueKeys=$(get_all_jira_issue_keys_for_commits ${flowName} "${commits}") + echo ${issueKeys} | tr ' ' '\n' | sort -u | tr '\n' ' ' +} diff --git a/.github/workflows/setup-kosli.yml b/.github/workflows/setup-kosli.yml index 207789c..588e5b3 100644 --- a/.github/workflows/setup-kosli.yml +++ b/.github/workflows/setup-kosli.yml @@ -51,33 +51,13 @@ jobs: # --template-file kosli-flow-templates/release-template.yml ### Custom attestation types ### -# - name: Create approval-jira attestation type -# run: -# kosli create attestation-type approval-jira -# --description "Approval from Jira. Must have at least 1 approver and all approvers must have APPROVED it" -# --schema custom-attestation-types/approval-jira-schema.json -# --jq '(.approvers | length) > 0' -# --jq '[.approvers[].status == "APPROVED"] | all' -# -# - name: Create running-sw attestation type -# run: -# kosli create attestation-type running-sw -# --description "List of running software in an environment" -# --schema custom-attestation-types/running-sw-schema.json + - name: Create running-sw attestation type + run: + kosli create attestation-type jira-issue-list + --description "List of Jira issues" + --schema custom-attestation-types/jira-issue-list-schema.json ### environments ### -# - name: Create dev env -# run: -# kosli create environment ${{ env.KOSLI_ENV_DEV }} -# --description "A simulated development environment" -# --type server -# -# - name: Create staging env -# run: -# kosli create environment ${{ env.KOSLI_ENV_STAGING }} -# --description "A simulated staging environment" -# --type server - - name: Create prod env run: kosli create environment ${{ env.KOSLI_ENV_PROD }} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b1f1744 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SHELL := bash + +report_all_envs: + gh workflow run simulate-environment-reporting-prod.yml --ref main diff --git a/custom-attestation-types/jira-issue-list-schema.json b/custom-attestation-types/jira-issue-list-schema.json new file mode 100644 index 0000000..151d524 --- /dev/null +++ b/custom-attestation-types/jira-issue-list-schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "JIRA Issue List", + "description": "A list of JIRA issue keys", + "type": "array", + "items": { + "type": "string", + "pattern": "^[A-Z]+-[0-9]+$", + "description": "JIRA issue key in format PROJECT-NUMBER (e.g., MRJP-4)" + }, + "minItems": 0, + "uniqueItems": true, + "examples": [ + [], + ["MRJP-4"], + ["MRJP-4", "MRJP-5"], + ["ABC-123", "XYZ-456", "TEST-1"] + ] +} From b73096307dc2cacb783e5f482cfcec60da112980 Mon Sep 17 00:00:00 2001 From: Tore Martin Hagen Date: Fri, 20 Jun 2025 07:23:17 +0200 Subject: [PATCH 2/2] Added kosli attest jira issues list action --- .../kosli-attest-jira-issues-list/action.yml | 47 +++++++++++++++++++ .github/workflows/setup-kosli.yml | 4 +- ...hema.json => jira-issues-list-schema.json} | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 .github/actions/kosli-attest-jira-issues-list/action.yml rename custom-attestation-types/{jira-issue-list-schema.json => jira-issues-list-schema.json} (93%) diff --git a/.github/actions/kosli-attest-jira-issues-list/action.yml b/.github/actions/kosli-attest-jira-issues-list/action.yml new file mode 100644 index 0000000..79a5eb1 --- /dev/null +++ b/.github/actions/kosli-attest-jira-issues-list/action.yml @@ -0,0 +1,47 @@ +name: Kosli Attest Jira Issue List + +# Attest a list of jira issues referred between two git commits + +inputs: + # The Following environment variables must be set in your GitHub action + # before using this composite + # env: + # KOSLI_ORG: kosli + # KOSLI_FLOW: your-flow-name + # KOSLI_TRAIL: your-trail-name (often release ID) + # KOSLI_API_TOKEN: "${{ secrets.KOSLI_API_TOKEN }}" + # KOSLI_CLI_VERSION: 2.11.11 + kosli-source-flow: + description: "Flow where Jira Issues are recorded" + old-commit: + description: "Oldest commit (will not be included)" + required: true + new-commit: + description: "Newest commit" + required: true + +runs: + using: "composite" + steps: + - name: Setup Kosli cli + uses: kosli-dev/setup-cli-action@v2 + with: + version: + ${{ env.KOSLI_CLI_VERSION }} + + - name: Attest Jira issue list + shell: bash + run: | + source ${GITHUB_ACTION_PATH}/../common/lib-kosli.sh + ISSUES=$(get_issue_keys_between_commits \ + ${{ inputs.old-commit }} ${{ inputs.new-commit }} \ + ${{ inputs.kosli-source-flow }}) + echo ${ISSUES} | jq -R 'split(" ")' > /tmp/jira-issues.json + + kosli attest custom \ + --type=jira-issues-list \ + --name jira-issues \ + --attestation-data /tmp/jira-issues.json \ + --annotate "JiraIssues=${ISSUES}" + + echo "Jira issues: ${ISSUES}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/setup-kosli.yml b/.github/workflows/setup-kosli.yml index 588e5b3..a6f58b6 100644 --- a/.github/workflows/setup-kosli.yml +++ b/.github/workflows/setup-kosli.yml @@ -53,9 +53,9 @@ jobs: ### Custom attestation types ### - name: Create running-sw attestation type run: - kosli create attestation-type jira-issue-list + kosli create attestation-type jira-issues-list --description "List of Jira issues" - --schema custom-attestation-types/jira-issue-list-schema.json + --schema custom-attestation-types/jira-issues-list-schema.json ### environments ### - name: Create prod env diff --git a/custom-attestation-types/jira-issue-list-schema.json b/custom-attestation-types/jira-issues-list-schema.json similarity index 93% rename from custom-attestation-types/jira-issue-list-schema.json rename to custom-attestation-types/jira-issues-list-schema.json index 151d524..4bbb3d8 100644 --- a/custom-attestation-types/jira-issue-list-schema.json +++ b/custom-attestation-types/jira-issues-list-schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "JIRA Issue List", + "title": "JIRA Issues List", "description": "A list of JIRA issue keys", "type": "array", "items": {