From e1be5a5a5174ec1ab7a42c298129ce941a4a1ade Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Wed, 14 Feb 2024 17:54:01 +0100 Subject: [PATCH 1/2] Update 'This release includes' in Code Freeze workflow --- .github/workflows/code_freeze.yml | 11 ++- scripts/extract_release_notes.sh | 2 +- scripts/update_this_release_includes.sh | 92 +++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100755 scripts/update_this_release_includes.sh diff --git a/.github/workflows/code_freeze.yml b/.github/workflows/code_freeze.yml index 9f99e65808..f6299b5f66 100644 --- a/.github/workflows/code_freeze.yml +++ b/.github/workflows/code_freeze.yml @@ -28,6 +28,7 @@ jobs: - name: Check out the code uses: actions/checkout@v4 with: + fetch-depth: 0 # Fetch all history and tags in order to extract Asana task URLs from git log submodules: recursive - name: Prepare fastlane @@ -56,7 +57,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 }}" \ @@ -73,6 +75,13 @@ jobs: --output /dev/null \ -d "{ \"data\": { \"assignee\": \"$assignee_id\" }}" + - name: Populate release contents + env: + ASANA_ACCESS_TOKEN: ${{ secrets.ASANA_ACCESS_TOKEN }} + GH_TOKEN: ${{ github.token }} + run: | + ./scripts/update_this_release_includes.sh ${{ steps.create_release_task.outputs.asana_task_id }} + run_tests: name: Run Tests diff --git a/scripts/extract_release_notes.sh b/scripts/extract_release_notes.sh index fba7600977..175cbf5ee0 100755 --- a/scripts/extract_release_notes.sh +++ b/scripts/extract_release_notes.sh @@ -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 diff --git a/scripts/update_this_release_includes.sh b/scripts/update_this_release_includes.sh new file mode 100755 index 0000000000..b34064ea47 --- /dev/null +++ b/scripts/update_this_release_includes.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# +# This script extracts release notes from Asana release task description. +# +# Usage: +# ./update_this_release_includes.sh +# + +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 " + 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' '

Release notes

' + if [[ -n "${release_notes[*]}" ]]; then + printf '%s' '
    ' + for release_note in "${release_notes[@]}"; do + escaped_release_note="$(sed -e 's//\>/g' <<< "${release_note}")" + printf '%s' "
  • ${escaped_release_note}
  • " + done + printf '%s' '
' + fi + + printf '%s' '

This release includes:

' + + # if task_urls is not empty + if [[ -n "${task_urls[*]}" ]]; then + printf '%s' '' + fi + + printf '%s' '' +} + +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 \ No newline at end of file From 4103fc73ecf0298ef6d6cfa5b28940717f791b72 Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Wed, 14 Feb 2024 18:29:45 +0100 Subject: [PATCH 2/2] Populate release contents in bump_internal_release --- .github/workflows/bump_internal_release.yml | 45 +++++++++------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/.github/workflows/bump_internal_release.yml b/.github/workflows/bump_internal_release.yml index ae339d2171..35f0d408eb 100644 --- a/.github/workflows/bump_internal_release.yml +++ b/.github/workflows/bump_internal_release.yml @@ -14,11 +14,11 @@ on: jobs: - update_embedded_files: + assert_release_branch: - name: Update Embedded Files + name: Assert Release Branch - runs-on: macos-13-xlarge + runs-on: ubuntu-latest timeout-minutes: 10 steps: @@ -30,32 +30,11 @@ jobs: *) echo "👎 Not a release branch"; exit 1 ;; esac - - name: Check out the code - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Select Xcode - run: sudo xcode-select -s /Applications/Xcode_$(<.xcode-version).app/Contents/Developer - - - name: Prepare fastlane - run: bundle install - - - name: Update embedded files - env: - APPLE_API_KEY_BASE64: ${{ secrets.APPLE_API_KEY_BASE64 }} - APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} - APPLE_API_KEY_ISSUER: ${{ secrets.APPLE_API_KEY_ISSUER }} - run: | - git config --global user.name "Dax the Duck" - git config --global user.email "dax@duckduckgo.com" - bundle exec fastlane update_embedded_files - run_tests: name: Run Tests - needs: update_embedded_files + needs: assert_release_branch uses: ./.github/workflows/pr.yml secrets: ASANA_ACCESS_TOKEN: ${{ secrets.ASANA_ACCESS_TOKEN }} @@ -73,8 +52,9 @@ jobs: - name: Check out the code uses: actions/checkout@v4 with: - submodules: recursive + fetch-depth: 0 # Fetch all history and tags in order to extract Asana task URLs from git log ref: ${{ github.ref_name }} + submodules: recursive - name: Select Xcode run: sudo xcode-select -s /Applications/Xcode_$(<.xcode-version).app/Contents/Developer @@ -92,6 +72,19 @@ jobs: git config --global user.email "dax@duckduckgo.com" bundle exec fastlane bump_internal_release update_embedded_files:false + - name: Extract Asana Task ID + id: task-id + uses: ./.github/actions/asana-extract-task-id + with: + task-url: ${{ github.event.inputs.asana-task-url }} + + - name: Populate release contents + env: + ASANA_ACCESS_TOKEN: ${{ secrets.ASANA_ACCESS_TOKEN }} + GH_TOKEN: ${{ github.token }} + run: | + ./scripts/update_this_release_includes.sh ${{ steps.task-id.outputs.task-id }} + prepare_release: name: Prepare Release needs: increment_build_number