Skip to content

Create Platform PRs #198

Create Platform PRs

Create Platform PRs #198

Workflow file for this run

name: Create Platform PRs
on:
workflow_dispatch:
inputs:
ios-branch:
description: "iOS Branch"
required: true
type: string
macos-branch:
description: "macOS Branch"
required: true
type: string
asana-task-url:
description: "Asana Task URL"
required: true
type: string
pr-title:
description: "Pull Request Title"
required: true
type: string
token:
description: "PRs Author's GitHub token"
required: true
type: string
jobs:
ios-pr:
name: Create iOS Pull Request
uses: ./.github/workflows/create-pr.yml
with:
repo: duckduckgo/iOS
branch: ${{ github.event.inputs.ios-branch }}
pr-title: ${{ github.event.inputs.pr-title }}
asana-task-url: ${{ github.event.inputs.asana-task-url }}
secrets:
github-token: ${{ github.event.inputs.token }}
macos-pr:
name: Create macOS Pull Request
uses: ./.github/workflows/create-pr.yml
with:
repo: duckduckgo/macos-browser
branch: ${{ github.event.inputs.macos-branch }}
pr-title: ${{ github.event.inputs.pr-title }}
asana-task-url: ${{ github.event.inputs.asana-task-url }}
secrets:
github-token: ${{ github.event.inputs.token }}
bsk-pr:
needs: [ios-pr, macos-pr]
name: Create BSK Pull Request
runs-on: ubuntu-latest
outputs:
urls: ${{ steps.create-pr.outputs.urls }}
steps:
- name: Create BSK PR Body
id: create-body
env:
GITHUB_TOKEN: ${{ github.event.inputs.token }}
run: |
pr_body_path=$(mktemp)
template="$(curl $(gh api https://api.github.com/repos/duckduckgo/BrowserServicesKit/contents/.github/PULL_REQUEST_TEMPLATE.md --jq .download_url))"
sed <<< "$template" \
-e 's~\(Task.*URL:.*\)~\1${{ github.event.inputs.asana-task-url }}~' \
-e 's~\(iOS PR:.*\)~\1${{ needs.ios-pr.outputs.url }}~' \
-e 's~\(macOS PR:.*\)~\1${{ needs.macos-pr.outputs.url }}~' \
> "$pr_body_path"
echo "pr_body_path=${pr_body_path}" >> $GITHUB_OUTPUT
- name: Create BSK PR
id: create-pr
env:
GITHUB_TOKEN: ${{ github.event.inputs.token }}
run: |
url="$(gh pr create --repo duckduckgo/BrowserServicesKit \
--title "${{ github.event.inputs.pr-title }}" \
--body-file "${{ steps.create-body.outputs.pr_body_path }}" \
--assignee "${{ github.actor }}" \
--draft \
--head "${{ github.ref }}")"
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "urls<<$EOF" >> $GITHUB_OUTPUT
echo "BSK PR: ${url}" >> $GITHUB_OUTPUT
echo "iOS PR: ${{ needs.ios-pr.outputs.url }}" >> $GITHUB_OUTPUT
echo "macOS PR: ${{ needs.macos-pr.outputs.url }}" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "BSK PR: ${url}" >> $GITHUB_STEP_SUMMARY
echo "iOS PR: ${{ needs.ios-pr.outputs.url }}" >> $GITHUB_STEP_SUMMARY
echo "macOS PR: ${{ needs.macos-pr.outputs.url }}" >> $GITHUB_STEP_SUMMARY
asana:
needs: [bsk-pr]
name: Comment on Asana Task
runs-on: ubuntu-latest
steps:
- name: Get Asana Task ID
id: get-task-id
run: |
task_url_regex='^https://app.asana.com/[0-9]/[0-9]*/([0-9]*)/f$'
if [[ "${{ github.event.inputs.asana-task-url }}" =~ ${task_url_regex} ]]; then
echo "task_id=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
else
echo "::error::Asana Task URL has incorrect format (attempted to match ${task_url_regex})."
fi
- name: Comment on Asana
env:
ASANA_ACCESS_TOKEN: ${{ secrets.ASANA_ACCESS_TOKEN }}
run: |
comment="${{ needs.bsk-pr.outputs.urls }}"
curl --silent --request POST \
--url https://app.asana.com/api/1.0/tasks/${{ steps.get-task-id.outputs.task_id }}/stories \
--header "Accept: application/json" \
--header "Authorization: Bearer ${{ env.ASANA_ACCESS_TOKEN }}" \
--header "Content-Type: application/json" \
--data "{ \"data\": { \"text\": \"${comment//$'\n'/\\n}\" } }"