Skip to content

Commit 47f7756

Browse files
[reports] Add pull request Pages previews and consumer documentation (#54) (#55)
* Add reports previews for pull requests * Update wiki submodule pointer for PR #55 * Update the URL for the pull request report preview environment. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Update the URL for the pull request report preview environment. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Adds ways to trigger tests in pull requests. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Fix the URL for the pull request report preview environment. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Updates the workflow to include closing pull requests and improves the deployment of preview reports. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Remove pull request reports preview deployment and update main reports deployment conditions Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Adds support for additional arguments in documentation and test generation commands. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Remove keeping files and exclude assets during report deployments Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Fix tests Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Adds steps to restore and copy previews during report generation. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Add a comment with preview URLs to pull requests. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Update directory paths for permissions and restore previews in reports. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Updates report generation command to include destination and coverage options. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Updates publication directories to use ./tmp/reports/ instead of ./public Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * Updates pull request event types to include 'closed' and removes unnecessary permissions. Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> * docs: add documentation for GitHub Actions workflows and repository setup procedures --------- Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent cfe9391 commit 47f7756

10 files changed

Lines changed: 215 additions & 32 deletions

File tree

.github/wiki

Submodule wiki updated from 60910d0 to 6e2dfcc

.github/workflows/reports.yml

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ name: Generate Reports and Deploy to GitHub Pages
33
on:
44
workflow_call:
55
workflow_dispatch:
6+
pull_request:
7+
types: [ "opened", "synchronize", "reopened", "closed" ]
68
push:
79
branches: [ "main" ]
810

911
permissions:
1012
contents: write
11-
pages: write
12-
id-token: write
13+
pull-requests: write
1314

1415
concurrency:
1516
group: "pages"
1617
cancel-in-progress: false
1718

1819
jobs:
1920
reports:
21+
if: github.event_name != 'pull_request' || github.event.action != 'closed'
2022
name: Generate Reports
2123
runs-on: ubuntu-latest
24+
25+
env:
26+
PAGES_ARTIFACT_NAME: ${{ github.event_name == 'pull_request' && format('github-pages-pr-{0}', github.event.pull_request.number) || 'github-pages' }}
27+
REPORTS_ROOT_VERSION: ${{ github.event_name == 'pull_request' && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }}
28+
2229
steps:
2330
- uses: actions/checkout@v6
2431

@@ -41,45 +48,98 @@ jobs:
4148
env:
4249
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
4350
COMPOSER_CACHE_DIR: /tmp/composer-cache
44-
COMPOSER_ROOT_VERSION: dev-main
51+
COMPOSER_ROOT_VERSION: ${{ env.REPORTS_ROOT_VERSION }}
4552
run: composer install --prefer-dist --no-progress --no-interaction --no-scripts
4653

4754
- name: Mark workspace as safe for git
4855
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
4956

5057
- name: Generate reports
5158
env:
52-
COMPOSER_ROOT_VERSION: dev-main
53-
run: composer dev-tools reports
59+
COMPOSER_ROOT_VERSION: ${{ env.REPORTS_ROOT_VERSION }}
60+
run: composer dev-tools reports -- --target=tmp/reports --coverage=tmp/reports/coverage
5461

5562
- name: Fix permissions
5663
run: |
57-
chmod -c -R +rX "public/" | while read line; do
64+
chmod -c -R +rX "tmp/reports/" | while read line; do
5865
echo "::warning title=Invalid file permissions automatically fixed::$line"
5966
done
6067
61-
- name: Upload artifact
62-
if: github.ref == 'refs/heads/main'
63-
uses: actions/upload-pages-artifact@v5
64-
with:
65-
path: public/
66-
67-
deploy:
68-
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
68+
- name: Add .nojekyll
69+
run: touch tmp/reports/.nojekyll
6970

70-
name: Deploy to GitHub Pages
71-
needs: reports
71+
- name: Restore previews from gh-pages
72+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
73+
uses: actions/checkout@v6
74+
continue-on-error: true
75+
with:
76+
ref: gh-pages
77+
path: gh-pages-current
7278

73-
permissions:
74-
pages: write
75-
id-token: write
79+
- name: Copy existing previews into publish directory
80+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
81+
run: |
82+
if [ -d "gh-pages-current/previews" ]; then
83+
mkdir -p tmp/reports/previews
84+
cp -R gh-pages-current/previews/. tmp/reports/previews/
85+
fi
86+
87+
- name: Deploy main reports
88+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
89+
uses: peaceiris/actions-gh-pages@v4
90+
with:
91+
github_token: ${{ secrets.GITHUB_TOKEN }}
92+
publish_branch: gh-pages
93+
publish_dir: ./tmp/reports/
94+
destination_dir: .
95+
keep_files: false
96+
force_orphan: false
97+
98+
- name: Deploy PR preview
99+
if: github.event_name == 'pull_request'
100+
uses: peaceiris/actions-gh-pages@v4
101+
with:
102+
github_token: ${{ secrets.GITHUB_TOKEN }}
103+
publish_branch: gh-pages
104+
publish_dir: ./tmp/reports/
105+
destination_dir: previews/pr-${{ github.event.pull_request.number }}
106+
keep_files: false
107+
force_orphan: false
108+
109+
- name: Comment preview URLs on pull request
110+
if: github.event_name == 'pull_request'
111+
uses: marocchino/sticky-pull-request-comment@v2
112+
with:
113+
header: pr-preview
114+
message: |
115+
🚀 Preview is available for this pull request.
76116
77-
environment:
78-
name: github-pages
79-
url: ${{ steps.deployment.outputs.page_url }}
117+
- Docs: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/
118+
- Coverage: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/coverage/
80119
120+
cleanup_preview:
121+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
122+
name: Cleanup Pull Request Preview
81123
runs-on: ubuntu-latest
124+
82125
steps:
83-
- name: Deploy to GitHub Pages
84-
id: deployment
85-
uses: actions/deploy-pages@v5
126+
- name: Checkout gh-pages
127+
uses: actions/checkout@v6
128+
with:
129+
ref: gh-pages
130+
path: gh-pages
131+
132+
- name: Remove preview directory
133+
run: |
134+
rm -rf "gh-pages/previews/pr-${{ github.event.pull_request.number }}"
135+
cd gh-pages
136+
touch .nojekyll
137+
git config user.name "github-actions[bot]"
138+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
139+
git add -A
140+
git diff --cached --quiet || git commit -m "chore: remove preview for PR #${{ github.event.pull_request.number }}"
141+
142+
- name: Push changes
143+
run: |
144+
cd gh-pages
145+
git push

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ on:
1616
type: number
1717
default: 80
1818
pull_request:
19+
paths:
20+
- 'src/**'
21+
- 'tests/**'
22+
- 'composer.json'
23+
- 'composer.lock'
24+
- '.github/workflows/tests.yml'
1925
push:
2026
branches: [ "main" ]
2127

docs/configuration/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ command supports them.
1010

1111
tooling-defaults
1212
overriding-defaults
13+
repository-setup
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Repository Setup
2+
================
3+
4+
To fully utilize the automation and documentation features provided by FastForward DevTools, consumer repositories require specific configurations in GitHub.
5+
6+
GitHub Pages
7+
------------
8+
9+
FastForward DevTools automatically generates and deploys reports, test coverage, and API documentation to GitHub Pages.
10+
11+
1. Navigate to your repository on GitHub.
12+
2. Go to **Settings** > **Pages**.
13+
3. Under **Build and deployment** > **Branch**:
14+
* Select the ``gh-pages`` branch.
15+
* Select ``/ (root)`` as the folder.
16+
* Click **Save**.
17+
18+
.. note::
19+
The ``gh-pages`` branch is automatically created and updated by the ``reports.yml`` workflow. If the branch does not exist yet, run the workflow manually once or wait for the first push to ``main``.
20+
21+
GitHub Wiki
22+
-----------
23+
24+
The wiki synchronization feature allows you to maintain documentation in Markdown within your repository and have it automatically published to the GitHub Wiki.
25+
26+
.. important::
27+
**Initial Manual Step Required**
28+
GitHub does not create the underlying wiki repository until at least one page is created via the web interface. You **MUST** create an initial ``Home.md`` page manually before using ``dev-tools wiki --init`` or any automated sync features.
29+
30+
1. Navigate to your repository on GitHub.
31+
2. Click the **Wiki** tab.
32+
3. Click **Create the first page** (or **New Page**).
33+
4. Ensure the title is ``Home`` and add some initial content.
34+
5. Click **Save Page**.
35+
36+
Once this is done, the wiki can be cloned as a submodule and synchronized by the DevTools commands.
37+
38+
Workflow Permissions
39+
--------------------
40+
41+
GitHub Actions must have permission to push changes to your repository (for Wiki updates and GitHub Pages deployments).
42+
43+
1. Go to **Settings** > **Actions** > **General**.
44+
2. Scroll down to **Workflow permissions**.
45+
3. Select **Read and write permissions**.
46+
4. Click **Save**.
47+
48+
.. warning::
49+
Without these permissions, the ``wiki.yml`` and ``reports.yml`` workflows will fail when attempting to deploy content.

docs/usage/github-actions.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
GitHub Actions Workflows
2+
========================
3+
4+
FastForward DevTools provides a set of reusable GitHub Actions workflows that automate testing, documentation generation, and wiki synchronization. These workflows are synchronized into consumer repositories via the ``dev-tools:sync`` command.
5+
6+
Workflow Inheritance
7+
--------------------
8+
9+
Workflows in consumer repositories (located in ``.github/workflows/``) are typically "thin wrappers" that inherit logic from the central ``dev-tools`` repository.
10+
11+
Example of an inherited workflow:
12+
13+
.. code-block:: yaml
14+
15+
name: "Fast Forward Reports"
16+
uses: php-fast-forward/dev-tools/.github/workflows/reports.yml@main
17+
secrets: inherit
18+
19+
This approach ensures that all libraries in the ecosystem benefit from infrastructure updates without requiring manual changes to every repository.
20+
21+
Fast Forward Reports
22+
--------------------
23+
24+
The ``reports.yml`` workflow is responsible for generating technical documentation and quality reports.
25+
26+
**Triggers:**
27+
* Push to ``main``.
28+
* Pull Request (opened, synchronized, reopened, closed).
29+
* Manual trigger (workflow_dispatch).
30+
31+
**Behavior:**
32+
* **Main Branch**: Runs all checks and deploys the final reports to the root of the ``gh-pages`` branch.
33+
* **Pull Requests**:
34+
* Generates a **Preview** of the documentation and coverage.
35+
* Deploys the preview to ``gh-pages`` under ``previews/pr-{number}/``.
36+
* Posts a **Sticky Comment** on the PR with links to the live preview and coverage report.
37+
* **Cleanup**: When a PR is closed, the workflow automatically removes the preview directory from the ``gh-pages`` branch to keep the repository clean.
38+
39+
Fast Forward Wiki
40+
-----------------
41+
42+
The ``wiki.yml`` workflow synchronizes the documentation generated by the ``dev-tools wiki`` command with the GitHub Wiki repository.
43+
44+
**Behavior:**
45+
* **Submodule Management**: It manages a submodule at ``.github/wiki`` that points to the actual wiki repository.
46+
* **Pull Requests**: Pushes documentation changes to a dedicated branch (e.g., ``pr-123``) in the wiki repository for review.
47+
* **Merge**: When a PR is merged into ``main``, it pushes the changes to the ``master`` branch of the wiki, making them live.
48+
49+
.. note::
50+
See :doc:`../configuration/repository-setup` for mandatory initial setup required for the Wiki workflow to function.
51+
52+
Fast Forward Tests
53+
------------------
54+
55+
The ``tests.yml`` workflow provides standard Continuous Integration.
56+
57+
* Runs PHPUnit tests across supported PHP versions (defaults to 8.3).
58+
* Validates code style using ECS.
59+
* Performs static analysis.
60+
61+
Maintenance Workflows
62+
---------------------
63+
64+
* **Auto Assign**: Automatically assigns reviewers to PRs.
65+
* **Label Sync**: Synchronizes repository labels with ecosystem standards.

docs/usage/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ task-oriented guidance instead of class-by-class reference.
1010
common-workflows
1111
testing-and-coverage
1212
documentation-workflows
13+
github-actions
1314
syncing-packaged-skills
1415
syncing-consumer-projects

resources/github-actions/reports.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name: "Fast Forward Reports"
22

33
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
46
push:
57
branches:
68
- main
79
workflow_dispatch:
810

911
permissions:
1012
contents: write
11-
pages: write
12-
id-token: write
13+
pull-requests: write
1314

1415
jobs:
1516
reports:

src/Console/Command/ReportsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9090
$docs = $this->processBuilder
9191
->withArgument('--ansi')
9292
->withArgument('--target', $input->getOption('target'))
93-
->build('composer dev-tools docs');
93+
->build('composer dev-tools docs --');
9494

9595
$coverage = $this->processBuilder
9696
->withArgument('--ansi')
9797
->withArgument('--coverage', $input->getOption('coverage'))
98-
->build('composer dev-tools tests');
98+
->build('composer dev-tools tests --');
9999

100100
$this->processQueue->add(process: $docs, detached: true);
101101
$this->processQueue->add(process: $coverage, detached: true);

tests/Console/Command/ReportsCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ protected function setUp(): void
9090
$this->processBuilder->withArgument(Argument::cetera())
9191
->willReturn($this->processBuilder->reveal());
9292

93-
$this->processBuilder->build('composer dev-tools docs')
93+
$this->processBuilder->build('composer dev-tools docs --')
9494
->willReturn($this->docsProcess->reveal());
9595

96-
$this->processBuilder->build('composer dev-tools tests')
96+
$this->processBuilder->build('composer dev-tools tests --')
9797
->willReturn($this->testsProcess->reveal());
9898

9999
$this->processQueue->run($this->output->reveal())

0 commit comments

Comments
 (0)