diff --git a/.github/actions/check_deployment/action.yml b/.github/actions/check_deployment/action.yml new file mode 100644 index 000000000..708f4913c --- /dev/null +++ b/.github/actions/check_deployment/action.yml @@ -0,0 +1,42 @@ +name: Check deployment +description: Check deployment +inputs: + version: + description: The version to check for + required: true + origin: + description: The origin of the deployment + required: true +runs: + using: composite + steps: + - name: Check deployment + shell: python + run: | + from json import loads + from sys import exit, stderr + from time import sleep + from traceback import print_exc + from urllib.request import urlopen + + REQUEST_URL="${{ inputs.origin }}/api/version" + VERSION="${{ inputs.version }}" + + print("REQUEST_URL =", REQUEST_URL, file=stderr) + print("VERSION =", VERSION, file=stderr) + + def get_running_version(): + try: + json = urlopen(REQUEST_URL).read() + return loads(json)["version"] + except Exception: + print_exc(1) + + for i in range(10): + sleep(i) + version = get_running_version() + if version == VERSION: + print(version) + exit(0) + print(i, "failed, got", version, file=stderr) + exit(1) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b98323ce8..35190fd82 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -209,32 +209,10 @@ jobs: curl -sSf -T *.whl https://asozial.org/api/update/ \ -H "Authorization: ${{ secrets.UPDATE_API_SECRET }}" - name: Check deployment - shell: python - run: | - from json import loads - from sys import exit, stderr - from time import sleep - from traceback import print_exc - from urllib.request import urlopen - - REQUEST_URL="https://asozial.org/api/version" - VERSION="${{ needs.test-wheel.outputs.version }}" - - def get_running_version(): - try: - json = urlopen(REQUEST_URL).read() - return loads(json)["version"] - except Exception: - print_exc(1) - - for i in range(10): - sleep(i) - version = get_running_version() - if version == VERSION: - print(version) - exit(0) - print(i, version, "!=", VERSION, file=stderr) - exit(1) + uses: ./.github/actions/check_deployment + with: + origin: https://asozial.org + version: ${{ needs.test-wheel.outputs.version }} github-pages: name: GitHub Pages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8093325fc..7b77a5716 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,6 +55,8 @@ jobs: python-version: - 3.12 - 3.13 + outputs: + version: ${{ steps.get-version.outputs.an-website-version }} steps: - name: Setup Python uses: actions/setup-python@v5 @@ -74,6 +76,10 @@ jobs: - name: Test starting timeout-minutes: 1 run: python -m an_website -c + - name: Get version + id: get-version + timeout-minutes: 1 + run: echo "an-website-version=$(python -c 'print(__import__("an_website").VERSION)')" >> "$GITHUB_OUTPUT" tests: name: Run tests @@ -284,6 +290,11 @@ jobs: run: | curl -sSf -T *.whl https://asozial.org/api/update/ \ -H "Authorization: ${{ secrets.UPDATE_API_SECRET }}" + - name: Check deployment + uses: ./.github/actions/check_deployment + with: + origin: https://asozial.org + version: ${{ needs.test-wheel.outputs.version }} github-pages: name: GitHub Pages