checksums:
  image: alpine:latest
  before_script:
    - sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
    - apk add --no-cache git git-lfs
    - git config --global user.name "CI"
    - git config --global user.email "ci@haozi.net"
    - git remote set-url origin "https://gitlab-ci-token:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
    - git config lfs.https://gitlab-ci-token:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git/info/lfs.locksverify true
    - git checkout -f $CI_COMMIT_REF_NAME
  script: |
    set -e
    IFS=$'\n'
    git fetch origin
    git reset --hard origin/$CI_COMMIT_REF_NAME
    for file in $(git ls-files | grep "^panel/" | grep -v ".sha256$" | grep -v ".txt$"); do
      filename=$(basename "$file");
      sha256sum -b "$file" | sed "s|$file|$filename|" > "${file}.sha256";
    done
    git add -A
    git commit -m "chore: update checksum files" || true
    git push origin $CI_COMMIT_REF_NAME
    unset IFS