Skip to content

Commit ed9c592

Browse files
authored
Support pull requests from forks and custom branches in CI workflows (#440)
1 parent d8c8a4c commit ed9c592

4 files changed

Lines changed: 59 additions & 16 deletions

File tree

‎.github/workflows/canary.yaml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ on:
1515

1616
jobs:
1717
test:
18+
permissions:
19+
pull-requests: write
1820
runs-on: ubuntu-latest
1921
steps:
2022
- name: Checkout repository
@@ -51,20 +53,23 @@ jobs:
5153
env:
5254
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5355
INPUTS_REPOS_FILE: ${{ inputs.repos_file }}
54-
GITHUB_REPOSITORY_URL: ${{ github.repositoryUrl }}
56+
GITHUB_REPOSITORY_URL: ${{ github.event.pull_request.head.repo.clone_url || github.repositoryUrl }}
5557
HEAD_REF: ${{ github.head_ref || github.ref_name }}
5658
LABELS_JSON: ${{ toJSON(github.event.pull_request.labels.*.name) }}
5759

5860
- name: Output issue number
61+
env:
62+
ISSUE_NUMBER: ${{ github.event.number }}
5963
run: |
6064
mkdir -p output
61-
echo ${{ github.event.number }} > output/issueNumber
65+
echo "$ISSUE_NUMBER" > output/issueNumber
6266
6367
- name: Install firehose (internal)
6468
if: github.repository == 'dart-lang/ecosystem'
65-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref "$HEAD_REF"
6669
env:
70+
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
6771
HEAD_REF: ${{ github.head_ref || github.ref_name }}
72+
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$HEAD_REF"
6873

6974
- name: Install firehose (external)
7075
if: github.repository != 'dart-lang/ecosystem'
@@ -74,8 +79,9 @@ jobs:
7479
id: fc
7580
env:
7681
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
ISSUE_NUMBER: ${{ github.event.number }}
7783
run: |
78-
COMMENT_ID=$(dart pub global run firehose:comment find --issue ${{ github.event.number }} --author github-actions[bot] --body-includes "## Ecosystem testing")
84+
COMMENT_ID=$(dart pub global run firehose:comment find --issue "$ISSUE_NUMBER" --author github-actions[bot] --body-includes "## Ecosystem testing")
7985
echo "comment-id=$COMMENT_ID" >> "$GITHUB_OUTPUT"
8086
8187
- name: Write comment id to file

‎.github/workflows/health.yaml‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,33 +174,41 @@ jobs:
174174
- uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260
175175
- name: Install firehose (internal)
176176
if: github.repository == 'dart-lang/ecosystem'
177-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref ${{ github.head_ref || github.ref_name }}
177+
env:
178+
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
179+
GIT_REF: ${{ github.head_ref || github.ref_name }}
180+
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
178181
- name: Install firehose (external)
179182
if: github.repository != 'dart-lang/ecosystem'
180183
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/
181184
- name: Find Comment
182185
id: fc
183186
env:
184187
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188+
ISSUE_NUMBER: ${{ github.event.number }}
185189
run: |
186-
COMMENT_ID=$(dart pub global run firehose:comment find --issue ${{ github.event.number }} --author github-actions[bot] --body-includes "## PR Health")
190+
COMMENT_ID=$(dart pub global run firehose:comment find --issue "$ISSUE_NUMBER" --author github-actions[bot] --body-includes "## PR Health")
187191
echo "comment-id=$COMMENT_ID" >> "$GITHUB_OUTPUT"
188192
189193
- name: Update comment
190194
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
191195
if: steps.fc.outputs.comment-id != 0
196+
env:
197+
COMMENT_ID: ${{ steps.fc.outputs.comment-id }}
192198
with:
193199
github-token: ${{ secrets.GITHUB_TOKEN }}
194200
script: |
195201
await github.rest.issues.updateComment({
196202
owner: context.repo.owner,
197203
repo: context.repo.repo,
198-
comment_id: ${{ steps.fc.outputs.comment-id }},
204+
comment_id: process.env.COMMENT_ID,
199205
body: '## PR Health ⚠️\n\nHealth checks are rerunning. These details are out-of-date.'
200206
});
201207
202208
changelog:
203209
if: ${{ contains(inputs.checks, 'changelog') }}
210+
permissions:
211+
pull-requests: write
204212
uses: ./.github/workflows/health_base.yaml
205213
with:
206214
sdk: ${{ inputs.sdk }}
@@ -216,6 +224,8 @@ jobs:
216224

217225
license:
218226
if: ${{ contains(inputs.checks, 'license') }}
227+
permissions:
228+
pull-requests: write
219229
uses: ./.github/workflows/health_base.yaml
220230
with:
221231
sdk: ${{ inputs.sdk }}
@@ -233,6 +243,8 @@ jobs:
233243

234244
coverage:
235245
if: ${{ contains(inputs.checks, 'coverage') }}
246+
permissions:
247+
pull-requests: write
236248
uses: ./.github/workflows/health_base.yaml
237249
with:
238250
sdk: ${{ inputs.sdk }}
@@ -251,6 +263,8 @@ jobs:
251263

252264
breaking:
253265
if: ${{ contains(inputs.checks, 'breaking') }}
266+
permissions:
267+
pull-requests: write
254268
uses: ./.github/workflows/health_base.yaml
255269
with:
256270
sdk: ${{ inputs.sdk }}
@@ -266,6 +280,8 @@ jobs:
266280

267281
do-not-submit:
268282
if: ${{ contains(inputs.checks, 'do-not-submit') }}
283+
permissions:
284+
pull-requests: write
269285
uses: ./.github/workflows/health_base.yaml
270286
with:
271287
sdk: ${{ inputs.sdk }}
@@ -281,6 +297,8 @@ jobs:
281297

282298
leaking:
283299
if: ${{ contains(inputs.checks, 'leaking') }}
300+
permissions:
301+
pull-requests: write
284302
uses: ./.github/workflows/health_base.yaml
285303
with:
286304
sdk: ${{ inputs.sdk }}
@@ -296,6 +314,8 @@ jobs:
296314

297315
unused-dependencies:
298316
if: ${{ contains(inputs.checks, 'unused-dependencies') }}
317+
permissions:
318+
pull-requests: write
299319
uses: ./.github/workflows/health_base.yaml
300320
with:
301321
sdk: ${{ inputs.sdk }}
@@ -321,7 +341,10 @@ jobs:
321341
- uses: dart-lang/setup-dart@65eb853c7ba17dde3be364c3d2858773e7144260
322342
- name: Install firehose (internal)
323343
if: github.repository == 'dart-lang/ecosystem'
324-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref ${{ github.head_ref || github.ref_name }}
344+
env:
345+
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
346+
GIT_REF: ${{ github.head_ref || github.ref_name }}
347+
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
325348
- name: Install firehose (external)
326349
if: github.repository != 'dart-lang/ecosystem'
327350
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/
@@ -336,16 +359,19 @@ jobs:
336359
id: fc
337360
env:
338361
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
362+
ISSUE_NUMBER: ${{ github.event.number }}
339363
run: |
340-
COMMENT_ID=$(dart pub global run firehose:comment find --issue ${{ github.event.number }} --author github-actions[bot] --body-includes "## PR Health")
364+
COMMENT_ID=$(dart pub global run firehose:comment find --issue "$ISSUE_NUMBER" --author github-actions[bot] --body-includes "## PR Health")
341365
echo "comment-id=$COMMENT_ID" >> "$GITHUB_OUTPUT"
342366
343367
- name: Merge all single comments
368+
env:
369+
ISSUE_NUMBER: ${{ github.event.number }}
344370
run: |
345371
mkdir output
346372
echo $'## PR Health\n\n' >> output/comment.md
347373
find single-comments -name '*.md' -exec cat {} + >> output/comment.md
348-
echo ${{ github.event.number }} > output/issueNumber
374+
echo "$ISSUE_NUMBER" > output/issueNumber
349375
350376
- name: Write comment id to file
351377
if: ${{ steps.fc.outputs.comment-id != 0 }}

‎.github/workflows/health_base.yaml‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ jobs:
148148

149149
- name: Install firehose (internal)
150150
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
151-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref ${{ github.head_ref || github.ref_name }}
151+
env:
152+
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
153+
GIT_REF: ${{ github.head_ref || github.ref_name }}
154+
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
152155

153156
- name: Install firehose (external)
154157
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}
@@ -194,11 +197,17 @@ jobs:
194197
INPUTS_HEALTH_YAML_NAME: ${{ inputs.health_yaml_name }}
195198
INPUTS_LICENSE: ${{ inputs.license }}
196199
INPUTS_LICENSE_TEST_STRING: ${{ inputs.license_test_string }}
200+
INPUTS_COVERAGE_WEB: ${{ inputs.coverage_web }}
197201
run: |
198202
cd current_repo/
203+
if [ "$INPUTS_COVERAGE_WEB" = "true" ]; then
204+
COVERAGE_WEB_FLAG="--coverage_web"
205+
else
206+
COVERAGE_WEB_FLAG=""
207+
fi
199208
dart pub global run firehose:health \
200-
--check ${INPUTS_CHECK} \
201-
${{ fromJSON('{"true":"--coverage_web","false":""}')[inputs.coverage_web] }} \
209+
--check "${INPUTS_CHECK}" \
210+
$COVERAGE_WEB_FLAG \
202211
--fail_on "${INPUTS_FAIL_ON}" \
203212
--warn_on "${INPUTS_WARN_ON}" \
204213
--flutter_packages "${INPUTS_FLUTTER_PACKAGES}" \
@@ -218,7 +227,7 @@ jobs:
218227
219228
- name: Ensure comment file exists
220229
run: test -f current_repo/output/comment-${INPUTS_CHECK}.md || echo $'The ${INPUTS_CHECK} workflow has encountered an exception and did not complete.' >> current_repo/output/comment-${INPUTS_CHECK}.md
221-
if: ${{ '$action_state' == 1 }}
230+
if: failure()
222231
env:
223232
INPUTS_CHECK: ${{ inputs.check }}
224233

‎.github/workflows/publish.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ jobs:
147147
- name: Install firehose (internal)
148148
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
149149
env:
150+
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
150151
GIT_REF: ${{ github.head_ref || github.ref_name }}
151-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref "$GIT_REF"
152+
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
152153

153154
- name: Install firehose (external)
154155
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}
@@ -265,8 +266,9 @@ jobs:
265266
- name: Install firehose (internal)
266267
if: ${{ !inputs.local_debug && github.repository == 'dart-lang/ecosystem' }}
267268
env:
269+
GIT_URL: ${{ github.event.pull_request.head.repo.clone_url || 'https://github.com/dart-lang/ecosystem' }}
268270
GIT_REF: ${{ github.head_ref || github.ref_name }}
269-
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref "$GIT_REF"
271+
run: dart pub global activate --source git "$GIT_URL" --git-path pkgs/firehose/ --git-ref "$GIT_REF"
270272

271273
- name: Install firehose (external)
272274
if: ${{ !inputs.local_debug && github.repository != 'dart-lang/ecosystem' }}

0 commit comments

Comments
 (0)