Skip to content

Commit e18d7d8

Browse files
authored
OPS-8 Added job to create a release candidate (#16)
* OPS-8 Cleaned up things in lib-jira * OPS-8 Added some debugging * OPS-8 added more debug * OPS-8 do less in job * Fixed wrong URL * Revert back to actual create release * Adding JIRA tickets to release * some debug * some debug * some debug * Added missing kosli command * added some debug * More testing * more debug * Only get existing JIRA keys * Revert back commented out code * OPS-8 Updated apps
1 parent 0becf4c commit e18d7d8

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

.github/workflows/create-release.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ env:
88
KOSLI_ORG: kosli-public
99
KOSLI_API_TOKEN: "${{ secrets.KOSLI_PUBLIC_API_TOKEN }}"
1010
KOSLI_CLI_VERSION: "2.11.8"
11+
KOSLI_ENV_STAGING: "jira-integration-example-staging"
12+
KOSLI_ENV_PROD: "jira-integration-example-prod"
13+
KOSLI_FLOW_FRONTEND: "jira-example-frontend"
14+
KOSLI_FLOW_BACKEND: "jira-example-backend"
1115
# KOSLI_DRY_RUN: true
1216
JIRA_BASE_URL: "https://kosli-team.atlassian.net"
1317
JIRA_USERNAME: ${{ secrets.KOSLI_JIRA_USERNAME }}
@@ -24,14 +28,33 @@ jobs:
2428
with:
2529
fetch-depth: 0
2630

31+
- name: Setup Kosli cli
32+
uses: kosli-dev/setup-cli-action@v2
33+
with:
34+
version:
35+
${{ env.KOSLI_CLI_VERSION }}
36+
2737
- name:
28-
run: |
29-
set -x
38+
run: |
3039
source scripts/lib-jira.sh
31-
current_release=$(get_current_release_candidate ${{ env.JIRA_PROJECT_ID }} | jq '.values')
32-
if [ "${current_release}" != "[]" ]; then
33-
echo "Release candidate already exist: ${current_release}"
40+
source scripts/lib-kosli.sh
41+
42+
# Fail if release already exists
43+
CURRENT_REL_JSON=$(get_CURRENT_REL_candidate ${{ env.JIRA_PROJECT_ID }})
44+
CURRENT_REL=$(echo "${CURRENT_REL_JSON}" | jq .values)
45+
if [ "${CURRENT_REL}" != "[]" ]; then
46+
echo "Release candidate already exist: ${CURRENT_REL}"
3447
exit 1
3548
fi
49+
50+
# Create the release and get the release ID
3651
TIMESTAMP=$(date -u "+%Y-%m-%d-%H-%M-%S")
37-
create_release ${{ env.JIRA_PROJECT_ID }} ${TIMESTAMP}
52+
CREATE_RESULT_JSON=$(create_release ${{ env.JIRA_PROJECT_ID }} ${TIMESTAMP})
53+
RELEASE_ID=$(echo "${CREATE_RESULT_JSON}" | jq .id)
54+
55+
# Add all jira tickets between prod and staging
56+
JIRA_KEYS=$(get_issue_keys_between_staging_and_prod)
57+
echo "Found issues: ${JIRA_KEYS}"
58+
for JIRA_KEY in ${JIRA_KEYS}; do
59+
add_issue_to_release ${JIRA_KEY} ${RELEASE_ID}
60+
done

apps/backend/backend-content.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
This is just a file to test out that changes to back-end source code
22
can trigger a build, reporting to Kosli and Jira
33

4-
counter=6
4+
counter=7

apps/frontend/frontend-content.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
This is just a file to test out that changes to front-end source code
22
can trigger a build, reporting to Kosli and Jira
33

4-
counter=8
4+
counter=9

scripts/lib-jira.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
#JIRA_BASE_API="https://kosli-team.atlassian.net"
3+
#JIRA_BASE_URL="https://kosli-team.atlassian.net"
44
#JIRA_USERNAME="tore@kosli.com"
55
#JIRA_API_TOKEN="xx"
66
#JIRA_PROJECT_ID=10000
@@ -48,15 +48,14 @@ function create_release
4848
{
4949
local -r projectId=$1; shift
5050
local -r releaseName=$1; shift
51+
local -r startDate=$(date -u "+%Y-%m-%d")
5152

52-
local -r url="${JIRA_BASE_API}/rest/api/3/version"
53+
local -r url="${JIRA_BASE_URL}/rest/api/3/version"
5354
local -r data='{
54-
"description": "An excellent version",
55+
"description": "Release '${releaseName}'",
5556
"name": "'${releaseName}'",
5657
"projectId": '${projectId}',
57-
"approvers": [{
58-
"accountId": "'${approverId}'"
59-
}]
58+
"startDate": "'${startDate}'"
6059
}'
6160
loud_curl_jira POST "${url}" "${data}"
6261
}
@@ -65,15 +64,15 @@ function get_current_release_candidate
6564
{
6665
local -r projectId=$1; shift
6766

68-
local -r url="${JIRA_BASE_API}/rest/api/3/project/${projectId}/version?status=unreleased"
67+
local -r url="${JIRA_BASE_URL}/rest/api/3/project/${projectId}/version?status=unreleased"
6968
loud_curl_jira GET "${url}" {}
7069
}
7170

7271
function get_release
7372
{
7473
local -r releaseId=$1; shift
7574

76-
local -r url="${JIRA_BASE_API}/rest/api/3/version/${releaseId}?expand=approvers"
75+
local -r url="${JIRA_BASE_URL}/rest/api/3/version/${releaseId}?expand=approvers"
7776
loud_curl_jira GET "${url}" {}
7877
}
7978

@@ -84,7 +83,7 @@ function add_approver_to_release
8483
local -r approverId=$1; shift
8584
local -r releaseId=$1; shift
8685

87-
local -r url="${JIRA_BASE_API}/rest/api/3/version/${releaseId}"
86+
local -r url="${JIRA_BASE_URL}/rest/api/3/version/${releaseId}"
8887
local -r data='{
8988
"approvers": [{
9089
"accountId": "'${approverId}'"
@@ -97,7 +96,7 @@ function add_issue_to_release() {
9796
local -r issueKey=$1; shift
9897
local -r releaseId=$1; shift
9998

100-
local -r url="${JIRA_BASE_API}/rest/api/3/issue/${issueKey}"
99+
local -r url="${JIRA_BASE_URL}/rest/api/3/issue/${issueKey}"
101100
local -r data='{
102101
"fields": {
103102
"fixVersions": [{
@@ -111,14 +110,14 @@ function add_issue_to_release() {
111110
function get_issue {
112111
local -r issueKey=$1; shift
113112

114-
local -r url="${JIRA_BASE_API}/rest/api/3/issue/${issueKey}"
113+
local -r url="${JIRA_BASE_URL}/rest/api/3/issue/${issueKey}"
115114
loud_curl_jira GET "${url}" {}
116115
}
117116

118-
RELEASE_NAME=2025.02.20-r1
117+
#RELEASE_NAME=2025.02.20-r1
119118
#get_current_release_candidate ${JIRA_PROJECT_ID}
120119
#create_release ${JIRA_PROJECT_ID} ${RELEASE_NAME}
121120
#get_release 10033
122-
get_issue OPS-5
121+
#get_issue OPS-5
123122
#add_issue_to_release OPS-5 10033
124123
#add_approver_to_release ${JIRA_APPROVER_ID} 10033

scripts/lib-kosli.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22

3-
export KOSLI_ORG=kosli-public
4-
export KOSLI_API_TOKEN="xx"
5-
KOSLI_ENV_STAGING=jira-integration-example-staging
6-
KOSLI_ENV_PROD=jira-integration-example-prod
7-
KOSLI_FLOW_FRONTEND=jira-example-frontend
8-
KOSLI_FLOW_BACKEND=jira-example-backend
3+
#export KOSLI_ORG=kosli-public
4+
#export KOSLI_API_TOKEN="xx"
5+
#KOSLI_ENV_STAGING=jira-integration-example-staging
6+
#KOSLI_ENV_PROD=jira-integration-example-prod
7+
#KOSLI_FLOW_FRONTEND=jira-example-frontend
8+
#KOSLI_FLOW_BACKEND=jira-example-backend
99

1010
function loud_curl
1111
{
@@ -83,8 +83,7 @@ function get_jira_issue_keys_from_trail
8383
local -r trailName=$1; shift
8484

8585
local -r url="https://app.kosli.com/api/v2/attestations/${KOSLI_ORG}/${flowName}/trail/${trailName}/jira-ticket"
86-
set -o pipefail
87-
loud_curl_kosli GET "${url}" {} | jq -r '.[].jira_results[].issue_id'
86+
loud_curl_kosli GET "${url}" {} | jq -r '.[].jira_results[] | select(.issue_exists == true) | .issue_id'
8887
}
8988

9089
function get_all_jira_issue_keys_for_commits
@@ -143,15 +142,16 @@ function get_artifact_flow_commit_mapping_json
143142
function get_issue_keys_between_staging_and_prod
144143
{
145144
commits=$(get_commits_between_staging_and_prod ${KOSLI_ENV_STAGING} ${KOSLI_ENV_PROD})
145+
echo "Commits between staging and prod: ${commits}" >&2
146146
issueKeys=""
147147
keys=$(get_all_jira_issue_keys_for_commits ${KOSLI_FLOW_FRONTEND} "${commits}")
148148
issueKeys+=" ${keys}"
149149
keys=$(get_all_jira_issue_keys_for_commits ${KOSLI_FLOW_BACKEND} "${commits}")
150150
issueKeys+=" ${keys}"
151-
echo ${issueKeys} | tr ' ' '\n' | sort -u
151+
echo ${issueKeys} | tr ' ' '\n' | sort -u | tr '\n' ' '
152152
}
153153

154-
get_issue_keys_between_staging_and_prod
154+
#get_issue_keys_between_staging_and_prod
155155

156156
#artifactFlowMapping=$(get_artifact_flow_commit_mapping_json ${KOSLI_ENV_STAGING} ${KOSLI_ENV_PROD})
157157
#

0 commit comments

Comments
 (0)