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
118 changes: 118 additions & 0 deletions .github/workflows/generate-jira-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Generate release candidate

on:
workflow_dispatch:

env:
# kosli commands picks up org, flow, trail and api-token from these environment variables
KOSLI_ORG: "${{ vars.KOSLI_ORG }}"
KOSLI_FLOW: "jira-example-release"
KOSLI_API_TOKEN: "${{ secrets.KOSLI_PUBLIC_API_TOKEN }}"
KOSLI_CLI_VERSION: "${{ vars.KOSLI_CLI_VERSION }}"
KOSLI_ENV_STAGING: "${{ vars.KOSLI_ENV_STAGING }}"
KOSLI_ENV_PROD: "${{ vars.KOSLI_ENV_PROD }}"
KOSLI_FLOW_SOURCE: "jira-example-source"
# KOSLI_DRY_RUN: true
DEBUG: true
JIRA_BASE_URL: "${{ vars.JIRA_BASE_URL }}"
JIRA_USERNAME: ${{ secrets.KOSLI_JIRA_USERNAME }}
JIRA_API_TOKEN: ${{ secrets.KOSLI_JIRA_API_TOKEN }}
JIRA_PROJECT_ID: "${{ vars.JIRA_PROJECT_ID }}"


jobs:
generate-candidate:
name: Create or update Jira release candidate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Kosli cli
uses: kosli-dev/setup-cli-action@v2
with:
version:
${{ vars.KOSLI_CLI_VERSION }}

- name: Create or get Jira release candidate
id: release-candidate
run: |
source scripts/lib-jira.sh

CURRENT_REL_JSON=$(get_current_release_candidate ${{ env.JIRA_PROJECT_ID }})
REL_VALUES_JSON=$(echo "${CURRENT_REL_JSON}" | jq .values)
if [ "${REL_VALUES_JSON}" == "[]" ]; then
echo "No release candidate exist: ${CURRENT_REL_JSON}"
echo "release-was-created=true" >> $GITHUB_OUTPUT

# Create the release and get the release ID
TIMESTAMP=$(date -u "+%Y-%m-%d-%H-%M-%S")
CREATE_RESULT_JSON=$(create_release ${{ env.JIRA_PROJECT_ID }} ${TIMESTAMP})
RELEASE_ID=$(echo "${CREATE_RESULT_JSON}" | jq .id)
echo "RELEASE_ID=${RELEASE_ID}" >> $GITHUB_ENV

PROJECT_KEY=$(echo "${{ vars.JIRA_PROJECT_KEY }}" | cut -d',' -f1)
REL_LINK="${JIRA_BASE_URL}/projects/${PROJECT_KEY}/versions/${RELEASE_ID}"
echo "REL_LINK=${REL_LINK}" >> $GITHUB_ENV
fi

- name: Begin trail
if: ${{ steps.release-candidate.outputs.release-was-created }}
uses: ./.github/actions/kosli-begin-trail
with:
kosli-trail: ${{ env.RELEASE_ID }}
external-url: JireRelease=${{ env.REL_LINK }}

- name: Add trail to jira release
if: ${{ steps.release-candidate.outputs.release-was-created }}
run: |
source scripts/lib-jira.sh
kosli_trail_link="https://app.kosli.com/${{ env.KOSLI_ORG }}/flows/${{ env.KOSLI_FLOW }}/trails/${{ env.RELEASE_ID }}"
add_trail_link_to_release ${{ env.RELEASE_ID }} ${kosli_trail_link}

- name: Report current prod SW
if: ${{ steps.release-candidate.outputs.release-was-created }}
run: |
source scripts/lib-kosli.sh
get_current_running_env_json ${{ env.KOSLI_ENV_PROD }} > /tmp/prod-env.json
create_running_sw_short_list_json /tmp/prod-env.json > /tmp/prod-sw.json

kosli attest custom \
--type=running-sw \
--name prod-software \
--trail ${{ env.RELEASE_ID }} \
--attestation-data /tmp/prod-sw.json
echo "Current prod SW:" >> $GITHUB_STEP_SUMMARY
cat /tmp/prod-sw.json | jq >> $GITHUB_STEP_SUMMARY

- name: Report current staging SW
run: |
source scripts/lib-kosli.sh
get_current_running_env_json ${{ env.KOSLI_ENV_STAGING }} > /tmp/staging-env.json
create_running_sw_short_list_json /tmp/staging-env.json > /tmp/staging-sw.json

kosli attest custom \
--type=running-sw \
--name staging-software \
--trail ${{ env.RELEASE_ID }} \
--attestation-data /tmp/staging-sw.json
echo "Current staging SW:" >> $GITHUB_STEP_SUMMARY
cat /tmp/staging-sw.json | jq >> $GITHUB_STEP_SUMMARY

- name: Add Jira issues to release
run: |
source scripts/lib-jira.sh
source scripts/lib-kosli.sh

JIRA_KEYS_IN_REL=($(get_issue_keys_in_release ${{ env.RELEASE_ID }}))
JIRA_KEYS_IN_KOSLI=($(get_issue_keys_between_staging_and_prod ${KOSLI_ENV_STAGING} ${KOSLI_ENV_PROD} ${KOSLI_FLOW_SOURCE}))

# Add all new jira issues between prod and staging
echo "Adding Jira issues:" >> $GITHUB_STEP_SUMMARY
for JIRA_KEY in ${JIRA_KEYS_IN_KOSLI[@]}; do
if [[ ! " ${JIRA_KEYS_IN_REL[@]} " =~ " ${JIRA_KEY} " ]]; then
add_issue_to_release ${JIRA_KEY} ${{ env.RELEASE_ID }}
echo ${JIRA_KEY} >> $GITHUB_STEP_SUMMARY
fi
done
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ SHELL := bash
deploy_to_staging:
gh workflow run deploy-to-staging.yml --ref main

generate_jira_release:
gh workflow run generate-jira-release.yml --ref main

create_release_candidate:
gh workflow run create-release.yml --ref main
gh workflow run generate-jira-release.yml --ref main

update_release_candidate:
gh workflow run update-release.yml --ref main
gh workflow run generate-jira-release.yml --ref main

check_release_to_prod:
gh workflow run release-to-prod.yml --ref main
Expand Down