Skip to content

Commit

Permalink
Merge branch 'main' into sabrina/improve-zoom-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SabrinaTardio committed May 7, 2024
2 parents 08faec9 + 773cffa commit f1a026b
Show file tree
Hide file tree
Showing 665 changed files with 32,568 additions and 13,893 deletions.
2 changes: 1 addition & 1 deletion .github/actions/asana-create-action-item/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ runs:

- id: get-asana-user-id
if: github.event_name != 'schedule'
uses: duckduckgo/apple-infra/actions/asana-get-user-id-for-github-handle@main
uses: duckduckgo/apple-toolbox/actions/asana-get-user-id-for-github-handle@main
with:
access-token: ${{ inputs.access-token }}
github-handle: ${{ github.actor }}
Expand Down
36 changes: 36 additions & 0 deletions .github/actions/asana-get-build-variants-list/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Get The List of Build Variants From Asana
description: |
Fetch the lists of build variants to measure retention (ATB) and attribution (Origin) from different Asana projects and combine them in a list.
inputs:
access-token:
description: "Asana access token"
required: true
type: string
github-token:
description: "GitHub Token"
required: false
type: string
atb-asana-task-id:
description: "Asana Task id for the ATB list."
required: true
type: string
origin-asana-section-id:
description: "Asana Section id for the Origins list"
required: true
type: string
outputs:
build-variants:
description: "The list of build variants to create"
value: ${{ steps.get-build-variants-task.outputs.build-variants }}
runs:
using: "composite"
steps:
- id: get-build-variants-task
shell: bash
env:
ASANA_ACCESS_TOKEN: ${{ inputs.access-token }}
GITHUB_TOKEN: ${{ inputs.github-token || github.token }}
ORIGIN_ASANA_SECTION_ID: ${{ inputs.origin-asana-section-id }}
ATB_ASANA_TASK_ID: ${{ inputs.atb-asana-task-id }}
run: |
${{ github.action_path }}/get_build_variants_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
#
# This scripts fetches Asana tasks from the Origins section defined in the Asana project https://app.asana.com/0/1206716555947156/1206716715679835.
#

set -e -o pipefail

asana_api_url="https://app.asana.com/api/1.0"

# Create a JSON string with the `origin-variant` pairs from the list of .
_create_origins_and_variants() {
local response="$1"
local origin_field="Origin"
local atb_field="ATB"

# for each element in the data array.
# filter out element with null `origin`.
# select `origin` and `variant` from the custom_fields response and make a key:value pair structure like {origin: <origin_value>, variant: <variant_value>}.
# if variant is not null we need to create two entries. One only with `origin` and one with `origin` and `variant`
# replace the new line with a comma
# remove the trailing comma at the end of the line.
jq -c '.data[]
| select(.custom_fields[] | select(.name == "'"${origin_field}"'").text_value != null)
| {origin: (.custom_fields[] | select(.name == "'"${origin_field}"'") | .text_value), variant: (.custom_fields[] | select(.name == "'"${atb_field}"'") | .text_value)}
| if .variant != null then {origin}, {origin, variant} else {origin} end' <<< "$response" \
| tr '\n' ',' \
| sed 's/,$//'
}

# Fetch all the Asana tasks in the section specified by ORIGIN_ASANA_SECTION_ID for a project.
# This function fetches only uncompleted tasks.
# If there are more than 100 items the function takes care of pagination.
# Returns a JSON string consisting of a list of `origin-variant` pairs concatenated by a comma. Eg. `{"origin":"app","variant":"ab"},{"origin":"app.search","variant":null}`.
_fetch_origin_tasks() {
# Fetches only tasks that have not been completed yet, includes in the response section name, name of the task and its custom fields.
local query="completed_since=now&opt_fields=name,custom_fields.id_prefix,custom_fields.name,custom_fields.text_value&opt_expand=custom_fields&opt_fields=memberships.section.name&limit=100"

local url="${asana_api_url}/sections/${ORIGIN_ASANA_SECTION_ID}/tasks?${query}"
local response
local origin_variants=()

# go through all tasks in the section (there may be multiple requests in case there are more than 100 tasks in the section)
# repeat until no more pages (next_page.uri is null)
while true; do
response="$(curl -fLSs "$url" -H "Authorization: Bearer ${ASANA_ACCESS_TOKEN}")"

# extract the object in the data array and append to result
origin_variants+=("$(_create_origins_and_variants "$response")")

# set new URL to next page URL
url="$(jq -r .next_page.uri <<< "$response")"

# break on last page
if [[ "$url" == "null" ]]; then
break
fi
done

echo "${origin_variants}"
}

# Create a JSON string from the list of ATB items passed.
_create_atb_variant_pairs() {
local response="$1"

# read the response raw and format in a compact JSON mode
# map each element to the structure {variant:<element>}
# remove the array
# replace the new line with a comma
# remove the trailing comma at the end of the line.
jq -R -c 'split(",")
| map({variant: .})
| .[]' <<< "$response" \
| tr '\n' ',' \
| sed 's/,$//'
}

# Fetches all the ATB variants defined in the ATB_ASANA_TASK_ID at the Variants list (comma separated) section.
_fetch_atb_variants() {
local url="${asana_api_url}/tasks/${ATB_ASANA_TASK_ID}?opt_fields=notes"
local atb_variants

# fetches the items
# read the response raw
# select only Variants list section
# output last line of the input to get all the list of variants.
atb_variants="$(curl -fSsL ${url} \
-H "Authorization: Bearer ${ASANA_ACCESS_TOKEN}" \
| jq -r .data.notes \
| grep -A1 '^Variants list' \
| tail -1)"

variants_list=("$(_create_atb_variant_pairs "$atb_variants")")

echo "${variants_list}"
}

main() {
# fetch ATB variants
local atb_variants=$(_fetch_atb_variants)
# fetch Origin variants
local origin_variants=$(_fetch_origin_tasks)
# merges the two list together. Use `include` keyword for later usage in matrix.
# for more info see https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#example-adding-configurations.
local merged_variants="{\"include\": [${atb_variants},${origin_variants}]}"
# write in GitHub output
echo "build-variants=${merged_variants}" >> "$GITHUB_OUTPUT"
}

main
2 changes: 1 addition & 1 deletion .github/actions/asana-log-message/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:

- id: get-asana-user-id
if: github.event_name != 'schedule'
uses: duckduckgo/apple-infra/actions/asana-get-user-id-for-github-handle@main
uses: duckduckgo/apple-toolbox/actions/asana-get-user-id-for-github-handle@main
with:
access-token: ${{ inputs.access-token }}
github-handle: ${{ github.actor }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/bump_internal_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ jobs:
curl -fLSs "https://app.asana.com/api/1.0/tasks/${TASK_ID}?opt_fields=notes" \
-H "Authorization: Bearer ${ASANA_ACCESS_TOKEN}" \
| jq -r .data.notes \
| ./scripts/extract_release_notes.sh > release_notes.txt
release_notes="$(<release_notes.txt)"
if [[ ${#release_notes} == 0 || "$release_notes" == "<-- Add release notes here -->" ]]; then
echo "::error::Release notes are empty. Please add release notes to the Asana task and restart the workflow."
| ./scripts/extract_release_notes.sh -r > raw_release_notes.txt
raw_release_notes="$(<raw_release_notes.txt)"
if [[ ${#raw_release_notes} == 0 || "$raw_release_notes" == *"<-- Add release notes here -->"* ]]; then
echo "::error::Release notes are empty or contain a placeholder. Please add release notes to the Asana task and restart the workflow."
exit 1
fi
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/code_freeze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Get Asana user ID
id: get-asana-user-id
uses: duckduckgo/apple-infra/actions/asana-get-user-id-for-github-handle@main
uses: duckduckgo/apple-toolbox/actions/asana-get-user-id-for-github-handle@main
with:
access-token: ${{ secrets.ASANA_ACCESS_TOKEN }}
github-handle: ${{ github.actor }}
Expand Down Expand Up @@ -172,6 +172,7 @@ jobs:
uses: ./.github/workflows/tag_release.yml
with:
asana-task-url: ${{ needs.create_release_branch.outputs.asana_task_url }}
base-branch: ${{ github.ref_name }}
branch: ${{ needs.create_release_branch.outputs.release_branch_name }}
prerelease: true
secrets:
Expand Down
Loading

0 comments on commit f1a026b

Please sign in to comment.