Skip to content

Commit d396f8b

Browse files
authored
Allow privileged testing of PRs (#5307)
1 parent 43b22c7 commit d396f8b

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

.github/workflows/sheldon.yaml

+21-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,34 @@ name: Pull request feedback
22

33
on:
44
pull_request_target:
5-
types: [ opened, synchronize ]
5+
types: [ opened, synchronize, labeled ]
66

77
jobs:
88
test:
99
runs-on: ubuntu-latest
1010
env:
1111
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
1212
steps:
13-
- uses: actions/checkout@v2
13+
# owner-test just checks out the PR -- this has an exfiltration risk, make SURE that
14+
# this can only be triggered by people with repo write access -- such as people that can add
15+
# labels to a PR
16+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests
17+
- name: Checkout repo for OWNER TEST
18+
uses: actions/checkout@v2
19+
if: contains(github.event.pull_request.labels.*.name, 'safe to test')
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
23+
# otherwise, checkout the current master, and the pr to the subdirectory 'pr'
24+
- name: Checkout base repo for pull-request test
25+
uses: actions/checkout@v2
26+
if: "! contains(github.event.pull_request.labels.*.name, 'safe to test')"
27+
- name: Checkout pull-request
28+
uses: actions/checkout@v2
29+
if: "! contains(github.event.pull_request.labels.*.name, 'safe to test')"
30+
with:
31+
path: pull-request
32+
ref: ${{ github.event.pull_request.head.sha }}
1433

1534
- name: Check for relevant changes
1635
uses: dorny/paths-filter@v2
@@ -29,34 +48,26 @@ jobs:
2948
echo changed: ${{ steps.changed.outputs.style_files }} ${{ steps.changed.outputs.locale_files }}
3049
3150
- name: Set up Ruby
32-
if: steps.changed.outputs.style == 'true' || steps.changed.outputs.locale == 'true'
3351
uses: ruby/setup-ruby@v1
3452
with:
3553
ruby-version: 2.7.1
3654
- name: but use cache to speed that up
37-
if: steps.changed.outputs.style == 'true' || steps.changed.outputs.locale == 'true'
3855
uses: actions/cache@v2
3956
with:
4057
path: vendor/bundle
4158
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
4259
restore-keys: |
4360
${{ runner.os }}-gems-
4461
- name: Bundle install
45-
if: steps.changed.outputs.style == 'true' || steps.changed.outputs.locale == 'true'
4662
run: |
4763
bundle config path vendor/bundle
4864
bundle update sheldon --jobs 4 --retry 3
4965
50-
- name: Apply the PR
51-
if: steps.changed.outputs.style == 'true' || steps.changed.outputs.locale == 'true'
52-
run: bundle exec sheldon --token=$GITHUB_TOKEN --apply
53-
5466
- name: Welcome to a new PR
5567
if: github.event.action == 'opened' && steps.changed.outputs.style == 'true'
5668
run: bundle exec sheldon --token=$GITHUB_TOKEN --welcome
5769

5870
- name: See if the styles/locales work
59-
if: steps.changed.outputs.style == 'true' || steps.changed.outputs.locale == 'true'
6071
run: bundle exec rake
6172

6273
- name: report

spec/spec_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'yaml'
44

55
STYLE_ROOT = File.expand_path('../..', __FILE__)
6+
PULL_REQUEST = File.join(STYLE_ROOT, 'pull-request')
7+
STYLE_ROOT = PULL_REQUEST if File.directory?(PULL_REQUEST)
68

79
ISSN = Hash.new { |h,k| h[k] = [] }
810
TITLES = Hash.new { |h,k| h[k] = [] }

0 commit comments

Comments
 (0)