Fix CI (due to python 3.12 update) + Fix migration CI check (#2306)

* Fix migration check not always failing when it should on main
 - Fix check due to Github using `refs/heads/gh-readonly-queue/main/` as ref when merging a PR from merge-queue to main
 - Add migration due to changes made in #2161

* Fix missing migration error message being showed when it shouldn't
 - Filter out empty migrations files from check testing if a migration is missing

* Prevent inner grep from failling the whole command
 - Fix last grep outputting gibberish when not receiving any file

* Fix xargs and grep command on macOS

* auto format

* Configure python 3.11 version on Github CI
 - Python 3.12 is the default on CI now, which breaks node-gyp and most of the native dependencies installations
 - Fix _new_migrations having lead and trailing spaces

* Remove migration, already included in #2302
This commit is contained in:
Vítor Vasconcellos 2024-04-10 13:32:46 -03:00 committed by GitHub
parent 67554c89b3
commit 56cee3c64d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 6 deletions

View file

@ -8,6 +8,10 @@ inputs:
runs:
using: 'composite'
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install pnpm
uses: pnpm/action-setup@v3
with:

View file

@ -73,12 +73,21 @@ runs:
# Check if a new migration should be created due to changes in the schema
cargo prisma migrate dev -n test --create-only --skip-generate
if git ls-files --others --exclude-standard | grep -q '^prisma/migrations/'; then
echo "::error file=core/prisma/schema.prisma,title=Missing migration::New migration should be generated due to changes in prisma schema"
# Fail action if we are on main or a release tag, to avoid releasing a app with broken db
if [ "$GITHUB_REF" == "refs/heads/main" ] || [[ "$GITHUB_REF" == refs/tags/* ]]; then
exit 1
fi
_new_migrations="$(
git ls-files --others --exclude-standard \
| { grep '^prisma/migrations/' || true; } \
| xargs sh -euxc '[ "$#" -lt 2 ] || grep -L "$@" || true' sh 'This is an empty migration' \
| wc -l \
| awk '{$1=$1};1'
)"
if [ "$_new_migrations" -gt 0 ]; then
echo "::error file=core/prisma/schema.prisma,title=Missing migration::New migration should be generated due to changes in prisma schema"
case "$GITHUB_REF" in
"refs/heads/main" | "refs/heads/gh-readonly-queue/main/"* | "refs/tags/"*)
# Fail action if we are on main or a release tag, to avoid releasing an app with a broken db
exit 1
;;
esac
fi
- name: Save Prisma codegen

View file

@ -169,6 +169,27 @@ Once that has completed, run `xcode-select --install` in the terminal to install
Also ensure that Rosetta is installed, as a few of our dependencies require it. You can install Rosetta with `softwareupdate --install-rosetta --agree-to-license`.
#### `ModuleNotFoundError: No module named 'distutils'`
If you run into this issue, or some other error involving `node-gyp`:
```
File "pnpm@8.15.6/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
import gyp # noqa: E402
^^^^^^^^^^
File "pnpm@8.15.6/node_modules/pnpm/dist/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
import gyp.input
File "pnpm@8.15.6/node_modules/pnpm/dist/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module>
from distutils.version import StrictVersion
```
Some pnpm dependencies require compilation steps that depend on Python to execute.
However, a recent change in Python version 3.12 broke the utility used to bridge these compilation steps to node/npm/pnpm.
Currently, there is no definitive solution to this issue due to it being fairly new. But there are two workarounds:
1. Downgrade your system Python version to 3.11 or lower.
2. Update pnpm to version v9.0.0-rc.0 (Release Candidate, not fully stable yet).
### Credits
This CONTRIBUTING.md file was inspired by the [github/docs CONTRIBUTING.md](https://github.com/github/docs/blob/main/CONTRIBUTING.md) file, and we extend our gratitude to the original author.