diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 395c6c66..f274274f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,10 +15,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: "3.10" diff --git a/.github/workflows/docs-redirects.yml b/.github/workflows/redirects.yml similarity index 58% rename from .github/workflows/docs-redirects.yml rename to .github/workflows/redirects.yml index d8ae59f9..9c85ec4b 100644 --- a/.github/workflows/docs-redirects.yml +++ b/.github/workflows/redirects.yml @@ -1,16 +1,20 @@ -name: Test d.p.o redirects +name: Test redirects on: push: paths: - - ".github/workflows/docs-redirects.yml" + - ".github/workflows/redirects.yml" - "salt/docs/**" + - "salt/moin/**" - "tests/docs-redirects/**" + - "tests/wiki-redirects/**" pull_request: paths: - - ".github/workflows/docs-redirects.yml" + - ".github/workflows/redirects.yml" - "salt/docs/**" + - "salt/moin/**" - "tests/docs-redirects/**" + - "tests/wiki-redirects/**" workflow_dispatch: permissions: @@ -24,23 +28,30 @@ env: FORCE_COLOR: "1" jobs: - docs-redirects: - name: Hurl + redirects: + name: Hurl (${{ matrix.suite }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + suite: + - docs-redirects + - wiki-redirects + steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Download Hurl ${{ env.HURL_VERSION }} - run: > + run: > curl --no-progress-meter --location --fail --proto '=https' --tlsv1.2 - --output '/tmp/hurl.deb' + --output '/tmp/hurl.deb' "https://github.com/Orange-OpenSource/hurl/releases/download/${{ env.HURL_VERSION }}/hurl_${{ env.HURL_VERSION }}_amd64.deb" env: - HURL_VERSION: "5.0.1" + HURL_VERSION: "7.1.0" - name: Install Hurl run: sudo apt install --yes /tmp/hurl.deb - name: Run tests - run: bash tests/docs-redirects/test.sh + run: bash tests/${{ matrix.suite }}/test.sh diff --git a/.github/workflows/server-list.yml b/.github/workflows/server-list.yml index dc7a4d3f..ebd3f6c7 100644 --- a/.github/workflows/server-list.yml +++ b/.github/workflows/server-list.yml @@ -14,14 +14,14 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Update salt-server-list.rst run: | wget --quiet -O docs/salt-server-list.rst https://salt-public.psf.io/salt-server-list.rst - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 + uses: peter-evans/create-pull-request@v8 with: commit-message: Update docs/salt-server-list.rst branch: salt-server-list diff --git a/salt/moin/configs/wiki-redirects.conf b/salt/moin/configs/wiki-redirects.conf new file mode 100644 index 00000000..d20f4e2e --- /dev/null +++ b/salt/moin/configs/wiki-redirects.conf @@ -0,0 +1,13 @@ +# This file contains redirect configuration for wiki.python.org. +# It is included by ``wiki-static.conf``, +# and tested in ``tests/wiki-redirects/``. + +location /moin/ { + rewrite ^/moin/(.+)$ $scheme://$host/python/$1.html permanent; + return 301 $scheme://$host/python/; +} + +location / { + index index.html; + try_files $uri $uri/ =404; +} diff --git a/salt/moin/configs/wiki-static.conf b/salt/moin/configs/wiki-static.conf index a032d68b..019f0be2 100644 --- a/salt/moin/configs/wiki-static.conf +++ b/salt/moin/configs/wiki-static.conf @@ -12,8 +12,7 @@ server { root /data/www/wiki-static; - location / { - index index.html; - try_files $uri $uri/ =404; - } + # The redirect config is in a separate file + # to allow automatic testing via Hurl (https://hurl.dev/) + include sites.d/wiki-redirects.conf; } diff --git a/salt/moin/init.sls b/salt/moin/init.sls index 638be25f..d603a184 100644 --- a/salt/moin/init.sls +++ b/salt/moin/init.sls @@ -22,6 +22,16 @@ moin: - file: /etc/nginx/sites.d/ - pkg: nginx +/etc/nginx/sites.d/wiki-redirects.conf: + file.managed: + - source: salt://moin/configs/wiki-redirects.conf + - user: root + - group: root + - mode: "0644" + - require: + - file: /etc/nginx/sites.d/ + - pkg: nginx + /etc/consul.d/service-moin.json: file.managed: - source: salt://consul/etc/service.jinja diff --git a/tests/wiki-redirects/nginx.conf b/tests/wiki-redirects/nginx.conf new file mode 100644 index 00000000..55614c2b --- /dev/null +++ b/tests/wiki-redirects/nginx.conf @@ -0,0 +1,5 @@ +server { + listen 10001; + root /var/empty; + include wiki-redirects.conf; +} diff --git a/tests/wiki-redirects/specs/moin-redirects.hurl b/tests/wiki-redirects/specs/moin-redirects.hurl new file mode 100644 index 00000000..a51e3192 --- /dev/null +++ b/tests/wiki-redirects/specs/moin-redirects.hurl @@ -0,0 +1,24 @@ +# Assert that old /moin/ URLs redirect to the static archive. + +GET {{host}}/moin/BeginnersGuide +HTTP 301 +[Asserts] +header "Location" == "http://localhost/python/BeginnersGuide.html" + +GET {{host}}/moin/PythonBooks +HTTP 301 +[Asserts] +header "Location" == "http://localhost/python/PythonBooks.html" + +GET {{host}}/moin/FrontPage +HTTP 301 +[Asserts] +header "Location" == "http://localhost/python/FrontPage.html" + + +# Assert that /moin/ root redirects to /python/. + +GET {{host}}/moin/ +HTTP 301 +[Asserts] +header "Location" == "http://localhost/python/" diff --git a/tests/wiki-redirects/test.sh b/tests/wiki-redirects/test.sh new file mode 100755 index 00000000..dfb75ae3 --- /dev/null +++ b/tests/wiki-redirects/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -euxo pipefail + +# Test the wiki redirects. This script must be run from the repository root. + +docker stop wiki-redirects-nginx || true + +docker run --name wiki-redirects-nginx --detach --quiet --rm --tty \ + --mount type=bind,source=./tests/wiki-redirects/nginx.conf,target=/etc/nginx/conf.d/wiki.conf,readonly \ + --mount type=bind,source=./salt/moin/configs/wiki-redirects.conf,target=/etc/nginx/wiki-redirects.conf,readonly \ + -p 10001:10001 \ + nginx:1.26.1-alpine + +# Wait for the nginx container to start… +sleep 1 + +hurl --color --continue-on-error --variable host=http://localhost:10001 --test ./tests/wiki-redirects/specs/*.hurl + +docker stop wiki-redirects-nginx