Skip to content

Commit

Permalink
GHA: Create Release Task (#4988)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1174433894299346/1207724126864064/f

### Description
Github Action that creates the task for Android Release

### Steps to test this PR
Example of working
https://github.com/duckduckgo/Android/actions/runs/11015390483

More test steps in the Asana task
  • Loading branch information
malmstein authored Oct 2, 2024
1 parent b0f0858 commit b6181ba
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/actions/assign-release-task/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: 'Assign Android Release Task in Asana'
description: 'Assigns the latest Asana Release task to the user who runs the workflow'
inputs:
task_name:
description: 'The name of the task to search for'
required: true
asana_token:
description: 'Asana Personal Access Token'
required: true
project_gid:
description: 'Asana Project GID to search within'
required: true
username:
description: 'The Github username to search for'
required: true
runs:
using: 'composite'
steps:
- name: Find task in Asana and assign it to owner
shell: bash
run: |
task_name="${{ inputs.task_name }}"
asana_token="${{ inputs.asana_token }}"
project_gid="${{ inputs.project_gid }}"
username="${{ inputs.username }}"
# Make the API request to get tasks from the specified project
response=$(curl -s -X GET "https://app.asana.com/api/1.0/projects/${project_gid}/tasks" \
-H "Authorization: Bearer ${asana_token}")
# Check if the response contains any tasks that match the specified task name exactly
task_id=$(echo "$response" | jq -r '.data[] | select(.name == "'"$task_name"'") | .gid')
if [ -z "$task_id" ]; then
echo "No tasks with the exact name '$task_name' found in project GID '$project_gid'."
exit 1
else
echo "Task ID for the task named '$task_name': $task_id"
fi
asana_user_id=$(grep -E "^$username: " .github/actions/assign-release-task/github_asana_mapping.yml | awk -F': ' '{print $2}' | tr -d '"')
if [ -z "asana_user_id" ]; then
echo "User $username not found."
exit 1
else
echo "User ID for $username: $asana_user_id"
fi
echo "Assigning task ID $task_id to user ID $asana_user_id"
# Assign the task to the user
response=$(curl -s -X PUT "https://app.asana.com/api/1.0/tasks/${task_id}" \
-H "Authorization: Bearer ${asana_token}" \
-H "Content-Type: application/json" \
-d "{\"data\": {\"assignee\": \"${asana_user_id}\"}}")
# Check if the assignment was successful
status=$(echo $response | jq -r '.errors')
if [ "$status" == "null" ]; then
echo "Task $task_id successfully assigned to user $asana_user_id."
else
echo "Failed to assign task: $status"
exit 1
fi
13 changes: 13 additions & 0 deletions .github/actions/assign-release-task/github_asana_mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
malmstein: "1157893581871899"
marcosholgado: "1125189844075764"
aitorvs: "1198194956790048"
CDRussell: "608920331025313"
anikiki: "1200581511061484"
joshliebe: "1200204095365673"
karlenDimla: "1201462763414791"
cmonfortep: "1149059203346875"
lmac012: "1205617573940213"
nalcalag: "1201807753392396"
CrisBarreiro: "1204920898013507"
0nko: "1207418217763343"
mikescamell: "1207908161520961"
63 changes: 63 additions & 0 deletions .github/workflows/release_create_task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Create Android App Release Task

on:
workflow_dispatch:
inputs:
app-version:
description: 'App Version for Release'
required: true
default: 'PLACEHOLDER'

env:
ASANA_PAT: ${{ secrets.GH_ASANA_SECRET }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
create_release_task:
name: Create Android App Release Task in Asana
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check app-version value
run: |
if [ "${{ github.event.inputs.app-version }}" == "PLACEHOLDER" ]; then
echo "Input value cannot be 'PLACEHOLDER'."
exit 1
else
echo "Input value is valid: ${{ github.event.inputs.app-version }}"
fi
- name: Install Release Bridge from Homebrew
run: |
brew tap cdrussell/aarb
brew install aarb
- name: Create task in Asana
run: |
AndroidAsanaBridge version=${{ github.event.inputs.app-version }} action=createRelease,tagPendingTasks,addLinksToDescription,removePendingTasks
- name: Assign task to Github Actor
id: assign-release-task
uses: ./.github/actions/assign-release-task
with:
task_name: 'Android Release ${{ github.event.inputs.app-version }}'
asana_token: ${{ secrets.GH_ASANA_SECRET }}
project_gid: ${{ vars.GH_ANDROID_RELEASE_BOARD_PROJECT_ID }}
username: ${{ github.actor }}

- name: Create Asana task when workflow failed
if: ${{ failure() }}
uses: duckduckgo/[email protected]
with:
asana-pat: ${{ secrets.GH_ASANA_SECRET }}
asana-project: ${{ vars.GH_ANDROID_APP_PROJECT_ID }}
asana-section: ${{ vars.GH_ANDROID_APP_INCOMING_SECTION_ID }}
asana-task-name: GH Workflow Failure - Create Android App Release Task
asana-task-description: The Create Android App Release Task workflow has failed. See https://github.com/duckduckgo/Android/actions/runs/${{ github.run_id }}
action: 'create-asana-task'

0 comments on commit b6181ba

Please sign in to comment.