Repository navigation
121 lines (111 loc) · 5.48 KB
/
Copy pathresolveBuildRefs.yml
File metadata and controls
121 lines (111 loc) · 5.48 KB
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
name: Resolve build refs
# Reusable workflow that resolves which Expensify/App and Expensify/Mobile-Expensify commits a build should check out.
#
# App head ref (APP_REF):
# - The head SHA of the App PR (APP_PULL_REQUEST_URL), if provided.
# - Otherwise, empty — callers fall back to the triggering ref (push commit / dispatch branch).
#
# Mobile-Expensify head ref (MOBILE_EXPENSIFY_REF), resolution order:
# 1. An explicit Mobile-Expensify PR URL (MOBILE_EXPENSIFY_PULL_REQUEST_URL), if provided.
# 2. Otherwise, a `MOBILE-EXPENSIFY: <pr-url>` entry in the body of the App PR (APP_PULL_REQUEST_URL).
# 3. Otherwise, empty — callers fall back to the pinned submodule commit.
on:
workflow_call:
inputs:
APP_PULL_REQUEST_URL:
description: The Expensify/App pull request URL. Its description is scanned for a MOBILE-EXPENSIFY entry. Ignored if a Mobile-Expensify PR URL is provided.
required: false
type: string
default: ''
MOBILE_EXPENSIFY_PULL_REQUEST_URL:
description: The Expensify/Mobile-Expensify pull request URL. Overrides MOBILE-EXPENSIFY set in the App PR description.
required: false
type: string
default: ''
outputs:
APP_PR_NUMBER:
description: PR number extracted from the App PR URL (empty if none).
value: ${{ jobs.resolve.outputs.APP_PR_NUMBER }}
APP_REF:
description: Resolved Expensify/App head SHA (empty to use the triggering ref).
value: ${{ jobs.resolve.outputs.APP_REF }}
MOBILE_EXPENSIFY_PR:
description: Resolved Mobile-Expensify PR number (empty if none).
value: ${{ jobs.resolve.outputs.MOBILE_EXPENSIFY_PR }}
MOBILE_EXPENSIFY_REF:
description: Resolved Mobile-Expensify head SHA (empty to use the pinned submodule commit).
value: ${{ jobs.resolve.outputs.MOBILE_EXPENSIFY_REF }}
secrets:
OS_BOTIFY_TOKEN:
description: Token with read access to Expensify/Mobile-Expensify, used to resolve the PR head ref.
required: true
jobs:
resolve:
name: Resolve build refs
runs-on: 'blacksmith-4vcpu-ubuntu-2404'
outputs:
APP_PR_NUMBER: ${{ steps.extractAppPRNumber.outputs.PR_NUMBER }}
APP_REF: ${{ steps.getAppHeadRef.outputs.REF }}
MOBILE_EXPENSIFY_PR: ${{ steps.mobileExpensifyPR.outputs.result }}
MOBILE_EXPENSIFY_REF: ${{ steps.getHeadRef.outputs.REF }}
steps:
- name: Extract App PR number from URL
id: extractAppPRNumber
if: ${{ inputs.APP_PULL_REQUEST_URL != '' }}
run: |
PR_NUMBER=$(echo '${{ inputs.APP_PULL_REQUEST_URL }}' | sed -E 's|.*/pull/([0-9]+).*|\1|')
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "::error::❌ Could not extract PR number from the App PR URL. Please provide a valid GitHub PR URL (e.g., https://github.com/Expensify/App/pull/12345)"
exit 1
fi
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_OUTPUT"
- name: Resolve App head ref from PR number
id: getAppHeadRef
if: ${{ steps.extractAppPRNumber.outputs.PR_NUMBER != '' }}
run: |
set -e
echo "REF=$(gh pr view ${{ steps.extractAppPRNumber.outputs.PR_NUMBER }} -R Expensify/App --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Extract Mobile-Expensify PR number from URL
id: extractMobilePRNumber
if: ${{ inputs.MOBILE_EXPENSIFY_PULL_REQUEST_URL != '' }}
run: |
PR_NUMBER=$(echo '${{ inputs.MOBILE_EXPENSIFY_PULL_REQUEST_URL }}' | sed -E 's|.*/pull/([0-9]+).*|\1|')
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "::error::❌ Could not extract PR number from the Mobile-Expensify PR URL. Please provide a valid GitHub PR URL (e.g., https://github.com/Expensify/Mobile-Expensify/pull/12345)"
exit 1
fi
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_OUTPUT"
- name: Resolve which Mobile-Expensify PR to use
id: mobileExpensifyPR
# v8
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
github-token: ${{ github.token }}
result-encoding: string
script: |
// An explicit Mobile-Expensify PR URL takes precedence over the App PR description
if ('${{ steps.extractMobilePRNumber.outputs.PR_NUMBER }}') {
return '${{ steps.extractMobilePRNumber.outputs.PR_NUMBER }}';
}
if (!'${{ steps.extractAppPRNumber.outputs.PR_NUMBER }}') {
return '';
}
const pullRequest = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: '${{ steps.extractAppPRNumber.outputs.PR_NUMBER }}',
});
const body = pullRequest.data.body ?? '';
const regex = /MOBILE-EXPENSIFY:\s*https:\/\/github.com\/Expensify\/Mobile-Expensify\/pull\/(?<prNumber>\d+)/;
const found = body.match(regex)?.groups?.prNumber || "";
return found.trim();
- name: Resolve Mobile-Expensify head ref from PR number
id: getHeadRef
if: ${{ steps.mobileExpensifyPR.outputs.result != '' }}
run: |
set -e
echo "REF=$(gh pr view ${{ steps.mobileExpensifyPR.outputs.result }} -R Expensify/Mobile-Expensify --json headRefOid --jq '.headRefOid')" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}