Skip to content

Commit ffb9700

Browse files
authored
Merge branch 'master' into test-preview-deployment
2 parents 8ffd3db + 552d1c4 commit ffb9700

File tree

11 files changed

+93
-158
lines changed

11 files changed

+93
-158
lines changed

.github/workflows/cloudflare-preview.yml

Lines changed: 36 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,86 @@
1-
name: Cloudflare Pages Preview Deployment
1+
name: Build and Deploy Cloudflare Preview
22

33
on:
4-
# Runs automatically for PRs from ruby/rdoc
5-
# Fork PRs will be filtered out by the if condition
6-
pull_request:
7-
8-
# Allows manual triggering for fork PRs
9-
workflow_dispatch:
4+
workflow_call:
105
inputs:
11-
pull_request_number:
12-
description: 'Pull Request Number (for fork PRs)'
6+
pr_number:
7+
description: 'The pull request number'
8+
required: true
9+
type: string
10+
pr_head_sha:
11+
description: 'The SHA of the PR head commit'
1312
required: true
1413
type: string
14+
pr_checkout_repository:
15+
description: 'The repository to checkout (owner/repo)'
16+
required: true
17+
type: string
18+
secrets:
19+
cloudflare_api_token:
20+
description: 'Cloudflare API Token'
21+
required: true
22+
cloudflare_account_id:
23+
description: 'Cloudflare Account ID'
24+
required: true
25+
matzbot_github_token:
26+
description: 'GitHub Token for Matzbot'
27+
required: true
28+
29+
permissions:
30+
pull-requests: write # To allow commenting on the PR
1531

1632
jobs:
17-
deploy-preview:
33+
build-deploy-and-comment:
34+
name: Build, Deploy, and Comment
1835
runs-on: ubuntu-latest
19-
# Skip if PR from fork and NOT manually triggered
20-
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'ruby/rdoc' }}
21-
2236
steps:
23-
- name: Checkout for PR from main repo
24-
if: ${{ github.event_name == 'pull_request' }}
25-
uses: actions/checkout@v4
26-
with:
27-
ref: ${{ github.event.pull_request.head.ref }}
28-
29-
# For fork PRs that are manually triggered, we need to get the PR details first
30-
- name: Get PR details for fork
31-
if: ${{ github.event_name == 'workflow_dispatch' }}
32-
id: pr_details
33-
uses: actions/github-script@v7
34-
with:
35-
script: |
36-
const prNumber = ${{ inputs.pull_request_number }};
37-
38-
// Get PR details to find the head SHA
39-
const { data: pr } = await github.rest.pulls.get({
40-
owner: context.repo.owner,
41-
repo: context.repo.repo,
42-
pull_number: prNumber
43-
});
44-
45-
console.log(`Fork PR head SHA: ${pr.head.sha}`);
46-
console.log(`Fork PR head ref: ${pr.head.ref}`);
47-
console.log(`Fork PR repo: ${pr.head.repo.full_name}`);
48-
49-
// Set outputs for checkout step
50-
core.setOutput('head_sha', pr.head.sha);
51-
core.setOutput('head_ref', pr.head.ref);
52-
core.setOutput('repo_full_name', pr.head.repo.full_name);
53-
54-
- name: Checkout for manually triggered fork PR
55-
if: ${{ github.event_name == 'workflow_dispatch' }}
37+
- name: Checkout PR Code
5638
uses: actions/checkout@v4
5739
with:
58-
ref: ${{ steps.pr_details.outputs.head_sha }}
59-
repository: ${{ steps.pr_details.outputs.repo_full_name }}
40+
repository: ${{ inputs.pr_checkout_repository }}
41+
ref: ${{ inputs.pr_head_sha }}
6042

6143
- name: Setup Ruby
6244
uses: ruby/setup-ruby@v1
6345
with:
6446
ruby-version: '3.4'
6547
bundler-cache: true
6648

67-
- name: Install dependencies
68-
run: bundle install
69-
7049
- name: Build site
7150
run: bundle exec rake rdoc
7251

73-
- name: Set PR Number
74-
id: pr_number
75-
run: |
76-
if [ "${{ github.event_name }}" == "pull_request" ]; then
77-
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
78-
else
79-
echo "PR_NUMBER=${{ inputs.pull_request_number }}" >> $GITHUB_ENV
80-
fi
81-
82-
# Deploy to Cloudflare Pages using wrangler-action
8352
- name: Deploy to Cloudflare Pages
8453
id: deploy
8554
uses: cloudflare/wrangler-action@v3
8655
with:
87-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
88-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
89-
command: pages deploy ./_site --project-name=rdoc --branch="${{ env.PR_NUMBER }}-preview"
56+
apiToken: ${{ secrets.cloudflare_api_token }}
57+
accountId: ${{ secrets.cloudflare_account_id }}
58+
command: pages deploy ./_site --project-name=rdoc --branch="${{ inputs.pr_number }}-preview"
9059

91-
# Comment on PR with preview URL - works for both regular PRs and fork PRs
9260
- name: Comment on PR with preview URL
9361
uses: actions/github-script@v7
9462
with:
63+
github-token: ${{ secrets.matzbot_github_token }}
9564
script: |
96-
const prNumber = ${{ env.PR_NUMBER }};
65+
const prNumber = ${{ inputs.pr_number }};
9766
const url = "${{ steps.deploy.outputs.deployment-url }}";
9867
const commentMarker = "🚀 Preview deployment available at:";
68+
const commitSha = '${{ inputs.pr_head_sha }}';
9969
100-
// Get commit SHA based on event type
101-
let commitSha;
102-
if ('${{ github.event_name }}' === 'pull_request') {
103-
commitSha = '${{ github.event.pull_request.head.sha }}';
104-
} else {
105-
// For workflow_dispatch, get the SHA from the PR details
106-
commitSha = '${{ steps.pr_details.outputs.head_sha }}';
107-
}
108-
109-
// Get all comments on the PR
11070
const comments = await github.rest.issues.listComments({
11171
issue_number: prNumber,
11272
owner: context.repo.owner,
11373
repo: context.repo.repo,
11474
per_page: 100
11575
});
11676
117-
// Look for our previous bot comment
11877
const existingComment = comments.data.find(comment =>
11978
comment.body.includes(commentMarker)
12079
);
12180
12281
const commentBody = `${commentMarker} [${url}](${url}) (commit: ${commitSha})`;
12382
12483
if (existingComment) {
125-
// Update existing comment
12684
await github.rest.issues.updateComment({
12785
comment_id: existingComment.id,
12886
owner: context.repo.owner,
@@ -131,7 +89,6 @@ jobs:
13189
});
13290
console.log("Updated existing preview comment");
13391
} else {
134-
// Create new comment
13592
await github.rest.issues.createComment({
13693
issue_number: prNumber,
13794
owner: context.repo.owner,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: PR Preview Check and Trigger
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
# For PRs from the main repo - direct call to the shared workflow
8+
trigger-main-repo-preview:
9+
name: Trigger Preview (Main Repo)
10+
uses: ./.github/workflows/cloudflare-preview.yml
11+
if: github.event.pull_request.head.repo.fork == false
12+
with:
13+
pr_number: ${{ github.event.pull_request.number }}
14+
pr_head_sha: ${{ github.event.pull_request.head.sha }}
15+
pr_checkout_repository: ${{ github.repository }}
16+
secrets:
17+
cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
18+
cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
19+
matzbot_github_token: ${{ secrets.MATZBOT_GITHUB_TOKEN }}
20+
21+
# For fork PRs - this job requires approval
22+
wait-for-approval:
23+
name: Wait for Approval (Fork PR)
24+
runs-on: ubuntu-latest
25+
if: github.event.pull_request.head.repo.fork == true
26+
environment: fork-preview-protection
27+
# This job only serves as an approval gate - it doesn't do anything else
28+
steps:
29+
- run: echo "Approval granted. Proceeding with preview deployment for commit ${{ github.event.pull_request.head.sha }}."
30+
31+
# Once approval is granted, call the shared workflow
32+
trigger-fork-preview:
33+
name: Trigger Preview (Fork - After Approval)
34+
needs: wait-for-approval
35+
uses: ./.github/workflows/cloudflare-preview.yml
36+
if: github.event.pull_request.head.repo.fork == true
37+
with:
38+
pr_number: ${{ github.event.pull_request.number }}
39+
pr_head_sha: ${{ github.event.pull_request.head.sha }}
40+
pr_checkout_repository: ${{ github.event.pull_request.head.repo.full_name }}
41+
secrets:
42+
cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
43+
cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
44+
matzbot_github_token: ${{ secrets.MATZBOT_GITHUB_TOKEN }}

.github/workflows/pr-preview-comment.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

.github/workflows/push_gem.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
steps:
2525
- name: Harden Runner
26-
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
26+
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
2727
with:
2828
egress-policy: audit
2929

@@ -43,4 +43,4 @@ jobs:
4343
tag_name="$(git describe --tags --abbrev=0)"
4444
gh release create "${tag_name}" --verify-tag --generate-notes
4545
env:
46-
GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }}
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

lib/rdoc/code_object/context/section.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22
require 'cgi/escape'
3+
require 'cgi/util' unless defined?(CGI::EscapeExt)
34

45
##
56
# A section of documentation like:

lib/rdoc/code_object/method_attr.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def block_params=(value)
283283

284284
def html_name
285285
require 'cgi/escape'
286+
require 'cgi/util' unless defined?(CGI::EscapeExt)
286287

287288
CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
288289
end

lib/rdoc/markup/to_html.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22
require 'cgi/escape'
3-
# For CGI.unescape on earlier rubies
4-
require 'cgi/util' if RUBY_VERSION < '3.5'
3+
require 'cgi/util' unless defined?(CGI::EscapeExt)
54

65
##
76
# Outputs RDoc markup as HTML.

lib/rdoc/markup/to_label.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22
require 'cgi/escape'
3+
require 'cgi/util' unless defined?(CGI::EscapeExt)
34

45
##
56
# Creates HTML-safe labels suitable for use in id attributes. Tidylinks are

lib/rdoc/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ module RDoc
55
##
66
# RDoc version you are using
77

8-
VERSION = '6.13.1'
8+
VERSION = '6.14.1'
99

1010
end

rdoc.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentat
5151
"exe/rdoc",
5252
"exe/ri",
5353
"man/ri.1",
54+
"rdoc.gemspec",
5455
]
5556
template_files = Dir.glob("lib/rdoc/generator/template/**/*")
56-
lib_files = Dir.glob("lib/**/*.{rb,kpeg,ry}")
57+
lib_files = Dir.glob("lib/**/*.{rb,kpeg,ry}", base: File.expand_path('..', __FILE__))
5758

5859
s.files = (non_lib_files + template_files + lib_files).uniq
5960

0 commit comments

Comments
 (0)