Update Actions and deploy using the configured Pages URL
This commit is contained in:
6 files changed
+64
-18
No files matched your search
@@ -3,4 +3,7 @@ updates:
|
|||||||
- package-ecosystem: github-actions
|
- package-ecosystem: github-actions
|
||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
interval: monthly
|
interval: weekly
|
||||||
|
groups:
|
||||||
|
github-actions:
|
||||||
|
patterns: ["*"]
|
||||||
@@ -10,14 +10,15 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python: ['3.9', '3.13']
|
python: ['3.9', '3.x']
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- uses: actions/setup-python@v7
|
- uses: actions/setup-python@v7.1.0
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python }}
|
python-version: ${{ matrix.python }}
|
||||||
|
check-latest: true
|
||||||
- run: python -m unittest discover -s tests -v
|
- run: python -m unittest discover -s tests -v
|
||||||
- run: bash -n scripts/bootstrap.sh deploy.sh && sh -n setup.sh
|
- run: bash -n scripts/bootstrap.sh deploy.sh && sh -n setup.sh
|
||||||
- run: python scripts/build_site.py
|
- run: python scripts/build_site.py
|
||||||
@@ -5,6 +5,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
pages: read
|
||||||
concurrency:
|
concurrency:
|
||||||
group: pages
|
group: pages
|
||||||
cancel-in-progress: false
|
cancel-in-progress: false
|
||||||
@@ -12,18 +13,22 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- uses: actions/setup-python@v7
|
- uses: actions/setup-python@v7.1.0
|
||||||
with:
|
with:
|
||||||
python-version: '3.13'
|
python-version: '3.x'
|
||||||
|
check-latest: true
|
||||||
- run: python -m unittest discover -s tests -v
|
- run: python -m unittest discover -s tests -v
|
||||||
|
- name: Read GitHub Pages configuration
|
||||||
|
id: pages
|
||||||
|
uses: actions/configure-pages@v6.0.0
|
||||||
- name: Build website and installer
|
- name: Build website and installer
|
||||||
env:
|
env:
|
||||||
SITE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
SITE_URL: ${{ steps.pages.outputs.base_url }}
|
||||||
run: python scripts/build_site.py --site-url "$SITE_URL"
|
run: python scripts/build_site.py --site-url "$SITE_URL"
|
||||||
- uses: actions/upload-pages-artifact@v5
|
- uses: actions/upload-pages-artifact@v5.0.0
|
||||||
with:
|
with:
|
||||||
path: _site
|
path: _site
|
||||||
deploy:
|
deploy:
|
||||||
@@ -38,4 +43,4 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Deploy GitHub Pages
|
- name: Deploy GitHub Pages
|
||||||
id: deployment
|
id: deployment
|
||||||
uses: actions/deploy-pages@v5
|
uses: actions/deploy-pages@v5.0.1
|
||||||
+13
-3
@@ -44,9 +44,19 @@ old package fails safely rather than silently installing another version.
|
|||||||
## Forks and custom domains
|
## Forks and custom domains
|
||||||
|
|
||||||
For another account or repository, update links in the README and `site/`.
|
For another account or repository, update links in the README and `site/`.
|
||||||
The workflow passes its own account/repository URL to `scripts/build_site.py`.
|
The workflow reads the canonical URL from GitHub Pages using `configure-pages`
|
||||||
For a custom domain, change the workflow's `SITE_URL` and the website's
|
and passes it to `scripts/build_site.py`. The build applies that HTTPS URL to
|
||||||
`BASE_URL` in `site/app.js` together.
|
the website, command builder, metadata and bootstrap, including inherited custom
|
||||||
|
domains. Configure custom domains in GitHub Pages settings; no source edit is
|
||||||
|
needed for deployments. For a local custom-domain build, pass `--site-url`.
|
||||||
|
|
||||||
The landing page has no external fonts, analytics, trackers or runtime assets.
|
The landing page has no external fonts, analytics, trackers or runtime assets.
|
||||||
Its customization form only changes a local preview and generated command.
|
Its customization form only changes a local preview and generated command.
|
||||||
|
|
||||||
|
## Dependency maintenance
|
||||||
|
|
||||||
|
Actions use the latest reviewed stable release versions. Dependabot checks
|
||||||
|
weekly and groups Action updates into one pull request. CI tests both the
|
||||||
|
minimum supported Python and the latest stable Python 3; the Pages build also
|
||||||
|
uses the latest stable Python 3 patch release. The runtime has no third-party
|
||||||
|
Python packages or JavaScript dependencies.
|
||||||
+13
-5
@@ -6,10 +6,11 @@ import hashlib
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import re
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
DEFAULT_SITE_URL = 'https://meghdadfadaee.github.io/shell-gleam'
|
||||||
PACKAGE_FILES = (
|
PACKAGE_FILES = (
|
||||||
'setup.sh', 'deploy.sh', 'README.md', 'LICENSE', 'VERSION',
|
'setup.sh', 'deploy.sh', 'README.md', 'LICENSE', 'VERSION',
|
||||||
'src/server_status.py', 'src/install.py', 'config/default.json',
|
'src/server_status.py', 'src/install.py', 'config/default.json',
|
||||||
@@ -19,12 +20,19 @@ ASSETS = ('index.html', 'style.css', 'app.js', 'favicon.svg', 'social.svg')
|
|||||||
|
|
||||||
|
|
||||||
def build(output, site_url):
|
def build(output, site_url):
|
||||||
|
site_url = site_url.rstrip('/')
|
||||||
|
if not re.fullmatch(r'https?://[A-Za-z0-9.-]+(?::[0-9]+)?(?:/[A-Za-z0-9._~%-]+)*', site_url):
|
||||||
|
raise ValueError('site URL must be an HTTP(S) origin with an optional path')
|
||||||
|
# Pages can report HTTP when HTTPS enforcement is disabled, even when TLS works.
|
||||||
|
# Remote installation always uses verified HTTPS.
|
||||||
|
site_url = re.sub(r'^http:', 'https:', site_url)
|
||||||
output = Path(output).resolve()
|
output = Path(output).resolve()
|
||||||
if output == ROOT or ROOT.is_relative_to(output):
|
if output == ROOT or ROOT.is_relative_to(output):
|
||||||
raise ValueError('output must not contain the source repository')
|
raise ValueError('output must not contain the source repository')
|
||||||
output.mkdir(parents=True, exist_ok=True)
|
output.mkdir(parents=True, exist_ok=True)
|
||||||
for name in ASSETS:
|
for name in ASSETS:
|
||||||
shutil.copyfile(ROOT / 'site' / name, output / name)
|
source = (ROOT / 'site' / name).read_text()
|
||||||
|
(output / name).write_text(source.replace(DEFAULT_SITE_URL, site_url))
|
||||||
(output / '.nojekyll').write_text('')
|
(output / '.nojekyll').write_text('')
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
with gzip.GzipFile(fileobj=buffer, mode='wb', filename='', mtime=0) as compressed:
|
with gzip.GzipFile(fileobj=buffer, mode='wb', filename='', mtime=0) as compressed:
|
||||||
@@ -45,12 +53,12 @@ def build(output, site_url):
|
|||||||
(output / 'downloads').mkdir(exist_ok=True)
|
(output / 'downloads').mkdir(exist_ok=True)
|
||||||
(output / artifact).write_bytes(data)
|
(output / artifact).write_bytes(data)
|
||||||
(output / 'downloads/SHA256SUMS').write_text(digest + ' ' + Path(artifact).name + '\n')
|
(output / 'downloads/SHA256SUMS').write_text(digest + ' ' + Path(artifact).name + '\n')
|
||||||
template = (ROOT / 'scripts/bootstrap.sh').read_text()
|
template = (ROOT / 'scripts/bootstrap.sh').read_text().replace(DEFAULT_SITE_URL, site_url)
|
||||||
installer = template.replace('@@SHA256@@', digest).replace('@@ARCHIVE@@', artifact).replace('@@SITE_URL@@', site_url.rstrip('/'))
|
installer = template.replace('@@SHA256@@', digest).replace('@@ARCHIVE@@', artifact).replace('@@SITE_URL@@', site_url.rstrip('/'))
|
||||||
(output / 'setup.sh').write_text(installer)
|
(output / 'setup.sh').write_text(installer)
|
||||||
(output / 'setup.sh').chmod(0o755)
|
(output / 'setup.sh').chmod(0o755)
|
||||||
manifest = {'name': 'shell-gleam', 'version': (ROOT / 'VERSION').read_text().strip(),
|
manifest = {'name': 'shell-gleam', 'version': (ROOT / 'VERSION').read_text().strip(),
|
||||||
'archive': artifact, 'sha256': digest, 'files': list(PACKAGE_FILES)}
|
'site_url': site_url, 'archive': artifact, 'sha256': digest, 'files': list(PACKAGE_FILES)}
|
||||||
(output / 'release.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
(output / 'release.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
||||||
print('Built ShellGleam site: ' + str(output))
|
print('Built ShellGleam site: ' + str(output))
|
||||||
return manifest
|
return manifest
|
||||||
@@ -59,6 +67,6 @@ def build(output, site_url):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
parser.add_argument('--output', type=Path, default=ROOT / '_site')
|
parser.add_argument('--output', type=Path, default=ROOT / '_site')
|
||||||
parser.add_argument('--site-url', default='https://meghdadfadaee.github.io/shell-gleam')
|
parser.add_argument('--site-url', default=DEFAULT_SITE_URL)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
build(args.output, args.site_url)
|
build(args.output, args.site_url)
|
||||||
@@ -48,6 +48,25 @@ class BuildTests(unittest.TestCase):
|
|||||||
with tarfile.open(Path(directory) / 'output' / release['archive']) as package:
|
with tarfile.open(Path(directory) / 'output' / release['archive']) as package:
|
||||||
self.assertFalse(any('local-secret' in name for name in package.getnames()))
|
self.assertFalse(any('local-secret' in name for name in package.getnames()))
|
||||||
|
|
||||||
|
def test_custom_domain_updates_all_public_install_urls(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
output = Path(directory)
|
||||||
|
release = builder.build(output, 'http://status.example.org/tools/shell-gleam/')
|
||||||
|
canonical = 'https://status.example.org/tools/shell-gleam'
|
||||||
|
self.assertEqual(release['site_url'], canonical)
|
||||||
|
for name in ('index.html', 'app.js', 'setup.sh'):
|
||||||
|
text = (output / name).read_text()
|
||||||
|
self.assertIn(canonical, text)
|
||||||
|
self.assertNotIn(builder.DEFAULT_SITE_URL, text)
|
||||||
|
|
||||||
|
def test_invalid_site_url_is_rejected_before_writing(self):
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
output = Path(directory) / 'output'
|
||||||
|
for url in ('file:///etc', 'https://example.org/\';touch', 'https://example.org/\nnext'):
|
||||||
|
with self.subTest(url=url), self.assertRaises(ValueError):
|
||||||
|
builder.build(output, url)
|
||||||
|
self.assertFalse(output.exists())
|
||||||
|
|
||||||
def test_source_root_cannot_be_output(self):
|
def test_source_root_cannot_be_output(self):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
builder.build(ROOT, 'https://example.github.io/shell-gleam')
|
builder.build(ROOT, 'https://example.github.io/shell-gleam')
|
||||||
|
|||||||
Reference in new issue
Block a user