name: upgrade

on:
  pull_request_review:
  push:
    branches:
      - 'forgejo*'
      - 'v*/forgejo*'

jobs:
  upgrade:
    runs-on: docker
    container:
      image: codeberg.org/forgejo/test_env:main
    steps:
      - run: apt-get install -y -qq zstd

      - name: cache S3 binaries
        id: S3
        uses: https://code.forgejo.org/actions/cache@v3
        with:
          path: |
            /usr/local/bin/minio
            /usr/local/bin/mc
            /usr/local/bin/garage
          key: S3

      - name: skip if S3 cache hit
        if: steps.S3.outputs.cache-hit != 'true'
        run: echo no hit

      - uses: https://code.forgejo.org/actions/checkout@v3
      - uses: https://code.forgejo.org/actions/setup-go@v4
        with:
          go-version: "1.21"
      - run: |
          git config --add safe.directory '*'
          chown -R gitea:gitea . /go
      - run: |
          su gitea -c 'make deps-backend'
      - run: |
          script=$(pwd)/.forgejo/upgrades/test-upgrade.sh
          $script run dependencies
          $script clobber
          su gitea -c "$script test_upgrades"