Skip to content

Commit f231977

Browse files
committed
gh-pages: add separate workflow job for pull requests
1 parent 9d0b8d5 commit f231977

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

.github/workflows/publish-website.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ name: Deploy gh-pages branch to GitHub Pages
22

33
on:
44
push:
5-
branches: ["gh-pages"]
6-
7-
# Allows us to run this workflow manually from the Actions tab
5+
branches:
6+
- "gh-pages"
7+
# Do a dry-run (update, no deploy) for PRs.
8+
pull_request:
9+
# Allow running this workflow manually from the Actions tab.
810
workflow_dispatch:
911

1012
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
@@ -20,23 +22,44 @@ concurrency:
2022
cancel-in-progress: false
2123

2224
jobs:
23-
deploy:
24-
environment:
25-
name: github-pages
26-
url: ${{ steps.deployment.outputs.page_url }}
25+
build:
26+
# Don't run on forks.
27+
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer'
2728
runs-on: ubuntu-latest
2829
steps:
29-
- name: Checkout
30+
# By default use the `gh-pages` branch.
31+
# For testing changes to the workflow or the scripts, use the PR branch
32+
# to have access to the latest version of the workflow/scripts.
33+
- name: Determine branch to use
34+
id: base_branch
35+
env:
36+
REF: ${{ github.ref }}
37+
run: |
38+
if [ "${{ github.event_name }}" == "pull_request" ]; then
39+
echo "BRANCH=$REF" >> "$GITHUB_OUTPUT"
40+
else
41+
echo 'BRANCH=gh-pages' >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Checkout code
3045
uses: actions/checkout@v4
46+
with:
47+
ref: ${{ steps.base_branch.outputs.BRANCH }}
3148

3249
- name: Install PHP
33-
run: |
34-
sudo apt-get update
35-
sudo apt-get install -y php
50+
uses: shivammathur/setup-php@v2
51+
with:
52+
php-version: '8.4'
53+
ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0
54+
coverage: none
3655

3756
- name: Generate /phars/index.html
38-
run: |
39-
php build/generate_phars_list.php
57+
run: php build/generate_phars_list.php
58+
59+
- name: Check GitHub Pages status
60+
uses: crazy-max/ghaction-github-status@v4
61+
with:
62+
pages_threshold: major_outage
4063

4164
- name: Setup Pages
4265
uses: actions/configure-pages@v5
@@ -45,7 +68,21 @@ jobs:
4568
uses: actions/upload-pages-artifact@v3
4669
with:
4770
path: './src'
71+
72+
deploy:
73+
needs: build
74+
# Don't run on forks.
75+
if: github.repository == 'PHPCSStandards/PHP_CodeSniffer' && github.event_name != 'pull_request' && needs.build.result == 'success'
4876

77+
name: "Deploy the website"
78+
runs-on: ubuntu-latest
79+
80+
environment:
81+
name: github-pages
82+
url: ${{ steps.deployment.outputs.page_url }}
83+
84+
steps:
4985
- name: Deploy to GitHub Pages
5086
id: deployment
5187
uses: actions/deploy-pages@v4
88+

0 commit comments

Comments
 (0)