Skip to content

Commit c6a19e3

Browse files
authored
Merge pull request #1953 from b9a1/less-redirects
Avoid some unnecessary redirects
2 parents 4be6590 + 9ad730a commit c6a19e3

File tree

8 files changed

+63
-27
lines changed

8 files changed

+63
-27
lines changed

.github/actions/deploy-to-github-pages/action.yml

+35-14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ inputs:
2020
cloudflare-zone:
2121
description: The Cloudflare zone to purge.
2222
required: false
23+
external-https:
24+
description: Whether HTTPS is set up externally, e.g. on Cloudflare instead of GitHub.
25+
default: false
26+
required: false
2327
outputs:
2428
url:
2529
description: The URL to which the site was deployed
@@ -41,6 +45,15 @@ runs:
4145
id: pages
4246
uses: actions/configure-pages@v5
4347

48+
- name: set base URL
49+
shell: bash
50+
run: |
51+
base_url="${{ steps.pages.outputs.base_url }}"
52+
if [ "${{ inputs.external-https }}" = true ] ; then
53+
base_url="$(echo "$base_url" | sed 's/^http:/https:/')"
54+
fi
55+
echo "base_url=$base_url" >>"$GITHUB_ENV"
56+
4457
- name: configure Hugo and Pagefind version
4558
shell: bash
4659
run: |
@@ -59,7 +72,7 @@ runs:
5972
env:
6073
HUGO_RELATIVEURLS: false
6174
shell: bash
62-
run: hugo config && hugo --baseURL "${{ steps.pages.outputs.base_url }}/"
75+
run: hugo config && hugo --baseURL "${{ env.base_url }}/"
6376

6477
- name: run Pagefind ${{ env.PAGEFIND_VERSION }} to build the search index
6578
shell: bash
@@ -110,7 +123,6 @@ runs:
110123
id: remap
111124
shell: bash
112125
run: |
113-
base_url='${{ steps.pages.outputs.base_url }}'
114126
echo "result=$(echo "$base_url" |
115127
sed 's|^\(.*\)\(/git-scm\.com\)$|(\1)?\2(.*)|') file://$PWD/public\$2" \
116128
>>$GITHUB_OUTPUT
@@ -120,14 +132,25 @@ runs:
120132
sed -n 's|^\(https\?:\/\/.*\)\(/git-scm\.com\)$|--remap '\''(\1.*) file://../$1'\''|p')" \
121133
>>$GITHUB_OUTPUT
122134
135+
- name: check for downgrades to unencrypted HTTP
136+
if: startsWith(env.base_url, 'https://')
137+
shell: bash
138+
# The `--require-https` option of lychee could come in handy,
139+
# but it also complains about `http://` links to other sites,
140+
# and (more importantly) doesn't work in offline mode.
141+
# A simple `grep` should work without any false positives,
142+
# unless git-scm.com mentions the base URL of one of its forks,
143+
# which is unlikely.
144+
run: '! grep -FInr "http:${base_url#https:}" public'
145+
123146
- name: check for broken links
124147
id: lychee
125148
uses: lycheeverse/lychee-action@v2
126149
with:
127150
args: >-
128151
--offline
129152
--fallback-extensions html
130-
--base '${{ steps.pages.outputs.base_url }}'
153+
--base '${{ env.base_url }}'
131154
--remap '${{ steps.remap.outputs.result }}'
132155
${{ steps.remap.outputs.remap-dotdot }}
133156
--exclude file:///path/to/repo.git/
@@ -192,23 +215,21 @@ runs:
192215
- name: Install @playwright/test
193216
shell: bash
194217
run: npm install @playwright/test
195-
- name: Edit /etc/hosts to map git-scm.com to GitHub
218+
- name: Edit /etc/hosts to map the deployed domain to GitHub
196219
shell: bash
197-
# This side-steps the Cloudflare caches
198-
run: sudo sh -c 'echo "185.199.108.153 git-scm.com" >>/etc/hosts'
220+
# This side-steps any caches that might be configured on the domain,
221+
# and works even when the real server is not reachable from GitHub.
222+
run: |
223+
host="$(echo "$base_url" | sed -E 's|^https?://([^:/]+).*|\1|')"
224+
sudo sh -c "echo '185.199.108.153 $host' >>/etc/hosts"
199225
- name: Run Playwright tests
200226
shell: bash
201227
id: playwright
202228
env:
203-
PLAYWRIGHT_TEST_URL: ${{ steps.pages.outputs.base_url }}
204-
run: |
229+
PLAYWRIGHT_TEST_URL: ${{ env.base_url }}
205230
# avoid test failures when HTTPS is enforced half-way through
206-
case "$PLAYWRIGHT_TEST_URL" in
207-
https://*|http://git-scm.com) ;; # okay, leave as-is
208-
http://*) PLAYWRIGHT_TEST_URL="https://${PLAYWRIGHT_TEST_URL#http://}";;
209-
esac &&
210-
echo "result=$PLAYWRIGHT_TEST_URL" >>$GITHUB_OUTPUT &&
211-
npx playwright test --project=chrome
231+
PLAYWRIGHT_EXTERNAL_HTTPS: ${{ inputs.external-https }}
232+
run: npx playwright test --project=chrome
212233
- uses: actions/upload-artifact@v4
213234
if: always() && steps.playwright.outputs.result != ''
214235
with:

.github/workflows/deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ jobs:
2727
with:
2828
cloudflare-token: ${{ secrets.CLOUDFLARE_TOKEN }}
2929
cloudflare-zone: ${{ secrets.CLOUDFLARE_ZONE }}
30+
external-https: ${{ vars.EXTERNAL_HTTPS }}

ARCHITECTURE.md

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ With this change, the site can be tested in the fork by pushing to the
3434
`gh-pages` branch (which will trigger the `deploy.yml` workflow) and then
3535
navigating to https://git-scm.<user>.github.io/.
3636

37+
If the site will be deployed to a custom domain that supports HTTPS,
38+
but the "[Enforce HTTPS]" option cannot be enabled in the GitHub Pages settings
39+
(this can happen if the domain points to a third-party gateway),
40+
the [GitHub Actions variable] `EXTERNAL_HTTPS` should be set to `true`,
41+
so that the site can be built with a proper HTTPS base URL.
42+
The official `git-scm.com` domain is an example of such a setup.
43+
44+
[Enforce HTTPS]: https://docs.github.com/en/pages/getting-started-with-github-pages/securing-your-github-pages-site-with-https#enforcing-https-for-your-github-pages-site
45+
[GitHub Actions variable]: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#defining-configuration-variables-for-multiple-workflows
46+
3747
## Non-static parts
3848

3949
While the site consists mostly of static content, there are a couple of

assets/js/application.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ var DownloadBox = {
5656
var os = window.session.browser.os; // Mac, Win, Linux
5757
if(os == "Mac") {
5858
$(".monitor").addClass("mac");
59-
$("#download-link").text("Download for Mac").attr("href", `${baseURLPrefix}download/mac`);
59+
$("#download-link").text("Download for Mac").attr("href", `${baseURLPrefix}downloads/mac`);
6060
$("#gui-link").removeClass('mac').addClass('gui');
61-
$("#gui-link").text("Mac GUIs").attr("href", `${baseURLPrefix}download/gui/mac`);
61+
$("#gui-link").text("Mac GUIs").attr("href", `${baseURLPrefix}downloads/guis?os=mac`);
6262
$("#gui-os-filter").attr('data-os', 'mac');
6363
$("#gui-os-filter").text("Only show GUIs for my OS (Mac)")
6464
} else if (os == "Windows") {
6565
$(".monitor").addClass("windows");
66-
$("#download-link").text("Download for Windows").attr("href", `${baseURLPrefix}download/win`);
66+
$("#download-link").text("Download for Windows").attr("href", `${baseURLPrefix}downloads/win`);
6767
$("#gui-link").removeClass('mac').addClass('gui');
68-
$("#gui-link").text("Windows GUIs").attr("href", `${baseURLPrefix}download/gui/windows`);
68+
$("#gui-link").text("Windows GUIs").attr("href", `${baseURLPrefix}downloads/guis?os=windows`);
6969
$("#alt-link").removeClass("windows").addClass("mac");
70-
$("#alt-link").text("Mac Build").attr("href", `${baseURLPrefix}download/mac`);
70+
$("#alt-link").text("Mac Build").attr("href", `${baseURLPrefix}downloads/mac`);
7171
$("#gui-os-filter").attr('data-os', 'windows');
7272
$("#gui-os-filter").text("Only show GUIs for my OS (Windows)")
7373
} else if (os == "Linux") {
7474
$(".monitor").addClass("linux");
75-
$("#download-link").text("Download for Linux").attr("href", `${baseURLPrefix}download/linux`);
75+
$("#download-link").text("Download for Linux").attr("href", `${baseURLPrefix}downloads/linux`);
7676
$("#gui-link").removeClass('mac').addClass('gui');
77-
$("#gui-link").text("Linux GUIs").attr("href", `${baseURLPrefix}download/gui/linux`);
77+
$("#gui-link").text("Linux GUIs").attr("href", `${baseURLPrefix}downloads/guis?os=linux`);
7878
$("#alt-link").removeClass("windows").addClass("mac");
79-
$("#alt-link").text("Mac Build").attr("href", `${baseURLPrefix}download/mac`);
79+
$("#alt-link").text("Mac Build").attr("href", `${baseURLPrefix}downloads/mac`);
8080
$("#gui-os-filter").attr('data-os', 'linux');
8181
$("#gui-os-filter").text("Only show GUIs for my OS (Linux)")
8282
} else {

content/downloads/_index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ <h1>Downloads</h1>
1414
<table class="binaries">
1515
<tr>
1616
<td>
17-
<a href="{{< relurl "download/mac" >}}" class="icon mac">macOS</a>
17+
<a href="{{< relurl "downloads/mac" >}}" class="icon mac">macOS</a>
1818
</td>
1919
<td>
20-
<a href="{{< relurl "download/win" >}}" class="icon windows">Windows</a>
20+
<a href="{{< relurl "downloads/win" >}}" class="icon windows">Windows</a>
2121
</td>
2222
</tr>
2323
<tr>
2424
<td>
25-
<a href="{{< relurl "download/linux" >}}" class="icon linux">Linux/Unix</a>
25+
<a href="{{< relurl "downloads/linux" >}}" class="icon linux">Linux/Unix</a>
2626
</td>
2727
</tr>
2828
</table>

layouts/partials/site-root.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h3>Community</h3>
5050
<td nowrap="true"><a href="https://www.kernel.org/pub/software/scm/git/" class="icon older-releases">Tarballs</a></td>
5151
</tr>
5252
<tr>
53-
<td nowrap="true"><a href="{{ relURL "download/win" }}" class="icon windows" id="alt-link">Windows Build</a></td>
53+
<td nowrap="true"><a href="{{ relURL "downloads/win" }}" class="icon windows" id="alt-link">Windows Build</a></td>
5454
<td nowrap="true"><a href="https://github.com/git/git" class="icon source">Source Code</a></td>
5555
</tr>
5656
</table>

playwright.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ module.exports = defineConfig({
3434

3535
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3636
trace: 'on-first-retry',
37+
38+
/* Ignore ERR_CERT_COMMON_NAME_INVALID when tesing against GitHub's server,
39+
if the real certificate is hosted by a third party (e.g. Cloudflare). */
40+
ignoreHTTPSErrors: process.env.PLAYWRIGHT_EXTERNAL_HTTPS === 'true',
3741
},
3842

3943
/* Configure projects for major browsers */

tests/git-scm.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test.describe('Windows', () => {
5959
await expect(page.getByRole('link', { name: 'Graphical UIs' })).toBeHidden()
6060
const windowsGUIs = page.getByRole('link', { name: 'Windows GUIs' })
6161
await expect(windowsGUIs).toBeVisible()
62-
await expect(windowsGUIs).toHaveAttribute('href', /\/download\/gui\/windows$/)
62+
await expect(windowsGUIs).toHaveAttribute('href', /\/downloads\/guis\?os=windows$/)
6363

6464
// navigate to Windows GUIs
6565
await windowsGUIs.click()

0 commit comments

Comments
 (0)