Skip to content

Commit b0bf30a

Browse files
authored
OPS-60 Added generate jira release as a combine of create and update release (#155)
1 parent e33a29d commit b0bf30a

File tree

2 files changed

+123
-2
lines changed

2 files changed

+123
-2
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Generate release candidate
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
# kosli commands picks up org, flow, trail and api-token from these environment variables
8+
KOSLI_ORG: "${{ vars.KOSLI_ORG }}"
9+
KOSLI_FLOW: "jira-example-release"
10+
KOSLI_API_TOKEN: "${{ secrets.KOSLI_PUBLIC_API_TOKEN }}"
11+
KOSLI_CLI_VERSION: "${{ vars.KOSLI_CLI_VERSION }}"
12+
KOSLI_ENV_STAGING: "${{ vars.KOSLI_ENV_STAGING }}"
13+
KOSLI_ENV_PROD: "${{ vars.KOSLI_ENV_PROD }}"
14+
KOSLI_FLOW_SOURCE: "jira-example-source"
15+
# KOSLI_DRY_RUN: true
16+
DEBUG: true
17+
JIRA_BASE_URL: "${{ vars.JIRA_BASE_URL }}"
18+
JIRA_USERNAME: ${{ secrets.KOSLI_JIRA_USERNAME }}
19+
JIRA_API_TOKEN: ${{ secrets.KOSLI_JIRA_API_TOKEN }}
20+
JIRA_PROJECT_ID: "${{ vars.JIRA_PROJECT_ID }}"
21+
22+
23+
jobs:
24+
generate-candidate:
25+
name: Create or update Jira release candidate
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Setup Kosli cli
33+
uses: kosli-dev/setup-cli-action@v2
34+
with:
35+
version:
36+
${{ vars.KOSLI_CLI_VERSION }}
37+
38+
- name: Create or get Jira release candidate
39+
id: release-candidate
40+
run: |
41+
source scripts/lib-jira.sh
42+
43+
CURRENT_REL_JSON=$(get_current_release_candidate ${{ env.JIRA_PROJECT_ID }})
44+
REL_VALUES_JSON=$(echo "${CURRENT_REL_JSON}" | jq .values)
45+
if [ "${REL_VALUES_JSON}" == "[]" ]; then
46+
echo "No release candidate exist: ${CURRENT_REL_JSON}"
47+
echo "release-was-created=true" >> $GITHUB_OUTPUT
48+
49+
# Create the release and get the release ID
50+
TIMESTAMP=$(date -u "+%Y-%m-%d-%H-%M-%S")
51+
CREATE_RESULT_JSON=$(create_release ${{ env.JIRA_PROJECT_ID }} ${TIMESTAMP})
52+
RELEASE_ID=$(echo "${CREATE_RESULT_JSON}" | jq .id)
53+
echo "RELEASE_ID=${RELEASE_ID}" >> $GITHUB_ENV
54+
55+
PROJECT_KEY=$(echo "${{ vars.JIRA_PROJECT_KEY }}" | cut -d',' -f1)
56+
REL_LINK="${JIRA_BASE_URL}/projects/${PROJECT_KEY}/versions/${RELEASE_ID}"
57+
echo "REL_LINK=${REL_LINK}" >> $GITHUB_ENV
58+
fi
59+
60+
- name: Begin trail
61+
if: ${{ steps.release-candidate.outputs.release-was-created }}
62+
uses: ./.github/actions/kosli-begin-trail
63+
with:
64+
kosli-trail: ${{ env.RELEASE_ID }}
65+
external-url: JireRelease=${{ env.REL_LINK }}
66+
67+
- name: Add trail to jira release
68+
if: ${{ steps.release-candidate.outputs.release-was-created }}
69+
run: |
70+
source scripts/lib-jira.sh
71+
kosli_trail_link="https://app.kosli.com/${{ env.KOSLI_ORG }}/flows/${{ env.KOSLI_FLOW }}/trails/${{ env.RELEASE_ID }}"
72+
add_trail_link_to_release ${{ env.RELEASE_ID }} ${kosli_trail_link}
73+
74+
- name: Report current prod SW
75+
if: ${{ steps.release-candidate.outputs.release-was-created }}
76+
run: |
77+
source scripts/lib-kosli.sh
78+
get_current_running_env_json ${{ env.KOSLI_ENV_PROD }} > /tmp/prod-env.json
79+
create_running_sw_short_list_json /tmp/prod-env.json > /tmp/prod-sw.json
80+
81+
kosli attest custom \
82+
--type=running-sw \
83+
--name prod-software \
84+
--trail ${{ env.RELEASE_ID }} \
85+
--attestation-data /tmp/prod-sw.json
86+
echo "Current prod SW:" >> $GITHUB_STEP_SUMMARY
87+
cat /tmp/prod-sw.json | jq >> $GITHUB_STEP_SUMMARY
88+
89+
- name: Report current staging SW
90+
run: |
91+
source scripts/lib-kosli.sh
92+
get_current_running_env_json ${{ env.KOSLI_ENV_STAGING }} > /tmp/staging-env.json
93+
create_running_sw_short_list_json /tmp/staging-env.json > /tmp/staging-sw.json
94+
95+
kosli attest custom \
96+
--type=running-sw \
97+
--name staging-software \
98+
--trail ${{ env.RELEASE_ID }} \
99+
--attestation-data /tmp/staging-sw.json
100+
echo "Current staging SW:" >> $GITHUB_STEP_SUMMARY
101+
cat /tmp/staging-sw.json | jq >> $GITHUB_STEP_SUMMARY
102+
103+
- name: Add Jira issues to release
104+
run: |
105+
source scripts/lib-jira.sh
106+
source scripts/lib-kosli.sh
107+
108+
JIRA_KEYS_IN_REL=($(get_issue_keys_in_release ${{ env.RELEASE_ID }}))
109+
JIRA_KEYS_IN_KOSLI=($(get_issue_keys_between_staging_and_prod ${KOSLI_ENV_STAGING} ${KOSLI_ENV_PROD} ${KOSLI_FLOW_SOURCE}))
110+
111+
# Add all new jira issues between prod and staging
112+
echo "Adding Jira issues:" >> $GITHUB_STEP_SUMMARY
113+
for JIRA_KEY in ${JIRA_KEYS_IN_KOSLI[@]}; do
114+
if [[ ! " ${JIRA_KEYS_IN_REL[@]} " =~ " ${JIRA_KEY} " ]]; then
115+
add_issue_to_release ${JIRA_KEY} ${{ env.RELEASE_ID }}
116+
echo ${JIRA_KEY} >> $GITHUB_STEP_SUMMARY
117+
fi
118+
done

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ SHELL := bash
33
deploy_to_staging:
44
gh workflow run deploy-to-staging.yml --ref main
55

6+
generate_jira_release:
7+
gh workflow run generate-jira-release.yml --ref main
8+
69
create_release_candidate:
7-
gh workflow run create-release.yml --ref main
10+
gh workflow run generate-jira-release.yml --ref main
811

912
update_release_candidate:
10-
gh workflow run update-release.yml --ref main
13+
gh workflow run generate-jira-release.yml --ref main
1114

1215
check_release_to_prod:
1316
gh workflow run release-to-prod.yml --ref main

0 commit comments

Comments
 (0)