-
Notifications
You must be signed in to change notification settings - Fork 34
126 lines (110 loc) · 4.13 KB
/
create-prs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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}\" } }"