Skip to content

Commit

Permalink
Update 'This release includes' in Code Freeze workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Feb 14, 2024
1 parent 473dcb8 commit d44fb86
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/code_freeze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ jobs:
-H "Content-Type: application/json" \
-d "{ \"data\": { \"name\": \"$task_name\" }}" \
| jq -r .data.new_task.gid)"
echo "asana_task_url=https://app.asana.com/0/0/${asana_task_id}/f" >> $GITHUB_OUTPUT
echo "asana_task_id=${asana_task_id}" >> $GITHUB_OUTPUT
echo "asana_task_url=https://app.asana.com/0/0/${asana_task_id}/f" >> $GITHUB_OUTPUT
curl -fLSs -X POST "https://app.asana.com/api/1.0/sections/${{ vars.MACOS_APP_DEVELOPMENT_RELEASE_SECTION_ID }}/addTask" \
-H "Authorization: Bearer ${{ env.ASANA_ACCESS_TOKEN }}" \
Expand All @@ -73,6 +74,12 @@ jobs:
--output /dev/null \
-d "{ \"data\": { \"assignee\": \"$assignee_id\" }}"
- name: Populate release contents
env:
ASANA_ACCESS_TOKEN: ${{ secrets.ASANA_ACCESS_TOKEN }}
run: |
./scripts/update_this_release_includes.sh ${{ steps.create_release_task.outputs.asana_task_id }}
run_tests:

name: Run Tests
Expand Down
2 changes: 1 addition & 1 deletion scripts/extract_release_notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# cat release_task_description.txt | ./extract_release_notes.sh
#

notes_start="release notes:"
notes_start="release notes"
notes_end="this release includes:"
is_release_notes=0
has_release_notes=0
Expand Down
92 changes: 92 additions & 0 deletions scripts/update_this_release_includes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
#
# This script extracts release notes from Asana release task description.
#
# Usage:
# ./update_this_release_includes.sh <release-task-id>
#

set -e -o pipefail

ASANA_ACCESS_TOKEN="1/14371688810375:01ca08516a957e423eed3fbc99ada1db"
task_url_regex='^https://app.asana.com/[0-9]/[0-9]*/([0-9]*)/f$'
cwd="$(dirname "${BASH_SOURCE[0]}")"
release_task_id="$1"

if [[ -z "$release_task_id" ]]; then
echo "Usage: $0 <release-task-id>"
exit 1
fi

get_task_id() {
local url="$1"
if [[ "$url" =~ ${task_url_regex} ]]; then
echo "${BASH_REMATCH[1]}"
fi
}

fetch_current_release_notes() {
curl -fLSs "https://app.asana.com/api/1.0/tasks/${release_task_id}?opt_fields=notes" \
-H "Authorization: Bearer ${ASANA_ACCESS_TOKEN}" \
| jq -r .data.notes \
| "${cwd}"/extract_release_notes.sh
}

construct_task_description() {
local release_notes=("$@")
local escaped_release_note
printf '%s' '<body><h1>Release notes</h1>'
if [[ -n "${release_notes[*]}" ]]; then
printf '%s' '<ul>'
for release_note in "${release_notes[@]}"; do
escaped_release_note="$(sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g' <<< "${release_note}")"
printf '%s' "<li>${escaped_release_note}</li>"
done
printf '%s' '</ul>'
fi

printf '%s' '<h2>This release includes:</h2>'

# if task_urls is not empty
if [[ -n "${task_urls[*]}" ]]; then
printf '%s' '<ul>'
for url in "${task_urls[@]}"; do
task_id=$(get_task_id "$url")
if [[ -n "$task_id" ]]; then
printf '%s' "<li><a data-asana-gid='${task_id}'/></li>"
fi
done
printf '%s' '</ul>'
fi

printf '%s' '</body>'
}

fetch_task_urls() {
git fetch -q --tags
last_release_tag="$(gh api /repos/duckduckgo/macos-browser/releases/latest --jq .tag_name)"

task_urls=
# shellcheck disable=SC2046
read -ra task_urls <<< $(git log "${last_release_tag}"..HEAD | grep 'Task.*URL' | awk '{ print $3; }' | grep asana | uniq)
}

main() {
fetch_task_urls
local release_notes=()
local html_notes
local request_payload
# shellcheck disable=SC2046
while read -r line; do
release_notes+=("$line")
done <<< "$(fetch_current_release_notes)"
html_notes="$(construct_task_description "${release_notes[@]}")"
request_payload="{\"data\":{\"html_notes\":\"${html_notes}\"}}"

curl -fLSs -X PUT "https://app.asana.com/api/1.0/tasks/${release_task_id}?opt_fields=permalink_url" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${ASANA_ACCESS_TOKEN}" \
-d "$request_payload"
}

main

0 comments on commit d44fb86

Please sign in to comment.