Skip to content

Commit

Permalink
Implement sensitive workflows for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Serious-senpai committed Oct 3, 2024
1 parent cbd20b7 commit 00aad63
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Trigger PR sensitive workflows

on: pull_request # Require approval
# IMPORTANT: Change settings in Actions/General to "Require approval for all outside collaborators".
# Before approving workflow from public forks, triple check the code.

permissions:
contents: read

jobs:
pr-sha:
name: Get pull request SHA
runs-on: ubuntu-latest

steps:
- name: Save pull request HEAD SHA
run: echo ${{ github.event.pull_request.head.sha }} > pr.txt

- name: Upload pull request HEAD SHA
uses: actions/upload-artifact@v4
with:
name: pr-sha
path: pr.txt
51 changes: 44 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ name: Run tests

on:
push:
branches:
- main

pull_request_target:
workflow_run:
workflows: Trigger PR sensitive workflows
types: completed

permissions:
contents: read

jobs:
python:
name: Test web application
if: ${{ github.event_name == 'push' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -28,11 +28,27 @@ jobs:

steps:
- name: Checkout repository
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4

- name: Get pull request HEAD SHA
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/download-artifact@v4
with:
name: pr-sha
path: /tmp/
run-id: ${{ github.event.workflow_run.id }}

- name: Print pull request HEAD SHA
id: pr-sha-step
if: ${{ github.event_name == 'workflow_run' }}
run: echo "sha=$(cat /tmp/pr.txt)" > $GITHUB_OUTPUT

- name: Checkout pull request directory
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/checkout@v4
with:
# IMPORTANT: Change settings in Actions/General to "Require approval for all outside collaborators".
# Before approving workflow from public forks, triple check the code.
ref: ${{ github.event.pull_request.head.sha }}
ref: ${{ steps.pr-sha-step.outputs.sha }}

- name: Setup Python
uses: actions/setup-python@v5
Expand Down Expand Up @@ -67,6 +83,7 @@ jobs:

flutter:
name: Test client application
if: ${{ github.event_name == 'push' || github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -78,8 +95,28 @@ jobs:

steps:
- name: Checkout repository
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4

- name: Get pull request HEAD SHA
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/download-artifact@v4
with:
name: pr-sha
path: /tmp/
run-id: ${{ github.event.workflow_run.id }}

- name: Print pull request HEAD SHA
id: pr-sha-step
if: ${{ github.event_name == 'workflow_run' }}
run: echo "sha=$(cat /tmp/pr.txt)" > $GITHUB_OUTPUT

- name: Checkout pull request directory
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/checkout@v4
with:
ref: ${{ steps.pr-sha-step.outputs.sha }}

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
Expand Down

0 comments on commit 00aad63

Please sign in to comment.