update jira ticket #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update jira ticket | |
on: | |
workflow_run: | |
workflows: | |
- release | |
types: | |
- completed | |
conclusion: success | |
jobs: | |
update_jira: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: get previous release tag | |
id: get_prev_release | |
run: | | |
PREV_TAG=$(git describe --tags --abbrev=0 $(git rev-list --tags --skip=1 --max-count=1) 2>/dev/null || echo "") | |
echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV | |
- name: get commit messages since last release | |
id: get_commit_messages | |
run: | | |
if [[ -z "${{ env.PREV_TAG }}" ]]; then | |
COMMITS=$(git log --pretty=format:"%s" --reverse) | |
else | |
COMMITS=$(git log ${{ env.PREV_TAG }}..HEAD --pretty=format:"%s" --reverse) | |
fi | |
echo "$COMMITS" > commit_messages.txt | |
- name: get jira and update | |
id: extract_jira_id | |
run: | | |
JIRA_ENTRIES="" | |
while IFS= read -r COMMIT_MSG; do | |
JIRA_ID=$(echo "$COMMIT_MSG" | grep -oE '#[^ ]+' | head -n 1 | tr -d '#') | |
if [[ -n "$JIRA_ID" ]]; then | |
JIRA_RESPONSE=$( | |
curl -s -u "${{ secrets.JIRA_GURI }}:${{ secrets.JIRA_GURI_TOKEN }}" \ | |
-X GET -H "Accept: application/json" \ | |
"${{ secrets.JIRA_DOMAIN }}/rest/api/2/issue/$JIRA_ID" | |
) | |
JIRA_TITLE=$(echo "$JIRA_RESPONSE" | jq -r '.fields.summary') | |
JIRA_LINK="${{ secrets.JIRA_DOMAIN }}/browse/$JIRA_ID" | |
JIRA_ENTRIES+="\n$COMMIT_MSG #$JIRA_ID\n- [**$JIRA_TITLE**]($JIRA_LINK)" | |
curl -s -u "${{ secrets.JIRA_GURI }}:${{ secrets.JIRA_GURI_TOKEN }}" \ | |
-X POST -H "Accept: application/json" \ | |
--data '{"transition": {"id": "31"}}' \ | |
"${{ secrets.JIRA_DOMAIN }}/rest/api/2/issue/$JIRA_ID" | |
fi | |
done < commit_messages.txt | |
echo "JIRA_ENTRIES<<EOF" >> $GITHUB_ENV | |
echo -e "$JIRA_ENTRIES" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Get last release tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
id: get_last_release | |
run: | | |
LATEST_RELEASE=$(gh release list --limit 1 --json tagName -q '.[0].tagName') | |
echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_ENV | |
- name: Update Release Notes | |
env: | |
LATEST_RELEASE: ${{ steps.get_last_release.outputs.tag }} | |
run: | | |
RELEASE_NOTES=$(gh release view ${{ env.LATEST_RELEASE }} --json body -q .body) | |
UPDATED_NOTES="## Updated Release Notes\n\n$RELEASE_NOTES\n\n###Jira tasks\n${{ env.JIRA_ENTRIES }}" | |
gh release edit ${{ github.event.release.tag_name }} --notes "$UPDATED_NOTES" |