forge: seed CI machine gate
This commit is contained in:
parent
7428bccb28
commit
d9156db126
1 changed files with 86 additions and 0 deletions
86
.forgejo/workflows/ci.yml
Normal file
86
.forgejo/workflows/ci.yml
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
name: ci
|
||||||
|
on: [pull_request]
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: |
|
||||||
|
set -u
|
||||||
|
apt_updated=0
|
||||||
|
install_packages() {
|
||||||
|
command -v apt-get >/dev/null || { echo 'Java build requires apt-get on this runner'; exit 1; }
|
||||||
|
if [ "$apt_updated" -eq 0 ]; then
|
||||||
|
apt-get update
|
||||||
|
apt_updated=1
|
||||||
|
fi
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends "$@"
|
||||||
|
}
|
||||||
|
ensure_java() {
|
||||||
|
command -v java >/dev/null || install_packages openjdk-17-jdk-headless
|
||||||
|
}
|
||||||
|
if [ -f mvnw ]; then
|
||||||
|
ensure_java
|
||||||
|
chmod +x mvnw
|
||||||
|
./mvnw -B test
|
||||||
|
elif [ -f pom.xml ]; then
|
||||||
|
ensure_java
|
||||||
|
if ! command -v mvn >/dev/null; then
|
||||||
|
install_packages maven
|
||||||
|
fi
|
||||||
|
mvn -B test
|
||||||
|
elif [ -f gradlew ]; then
|
||||||
|
ensure_java
|
||||||
|
chmod +x gradlew
|
||||||
|
./gradlew test
|
||||||
|
elif [ -f build.gradle ] || [ -f build.gradle.kts ]; then
|
||||||
|
ensure_java
|
||||||
|
command -v gradle >/dev/null || { echo 'Gradle build requires a wrapper or installed Gradle'; exit 1; }
|
||||||
|
gradle test
|
||||||
|
elif [ -f package.json ]; then
|
||||||
|
command -v node >/dev/null || { echo 'package.json requires Node.js'; exit 1; }
|
||||||
|
package_manager=$(node -p "String(require('./package.json').packageManager || '').split('@')[0]")
|
||||||
|
if [ -n "$package_manager" ] && [ "$package_manager" != npm ] && [ "$package_manager" != pnpm ] && [ "$package_manager" != yarn ]; then
|
||||||
|
echo "unsupported packageManager: $package_manager"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "$package_manager" = pnpm ] || { [ -z "$package_manager" ] && [ -f pnpm-lock.yaml ]; }; then
|
||||||
|
command -v corepack >/dev/null || { echo 'pnpm lockfile requires corepack'; exit 1; }
|
||||||
|
corepack enable
|
||||||
|
command -v pnpm >/dev/null || { echo 'pnpm is unavailable after corepack enable'; exit 1; }
|
||||||
|
pnpm install --frozen-lockfile
|
||||||
|
pnpm run --if-present test
|
||||||
|
pnpm run --if-present build
|
||||||
|
elif [ "$package_manager" = yarn ] || { [ -z "$package_manager" ] && [ -f yarn.lock ]; }; then
|
||||||
|
command -v corepack >/dev/null || { echo 'yarn lockfile requires corepack'; exit 1; }
|
||||||
|
corepack enable
|
||||||
|
command -v yarn >/dev/null || { echo 'yarn is unavailable after corepack enable'; exit 1; }
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
if node -e "process.exit(require('./package.json').scripts?.test ? 0 : 1)"; then
|
||||||
|
yarn test
|
||||||
|
fi
|
||||||
|
if node -e "process.exit(require('./package.json').scripts?.build ? 0 : 1)"; then
|
||||||
|
yarn build
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
command -v npm >/dev/null || { echo 'package.json requires npm'; exit 1; }
|
||||||
|
if [ -f package-lock.json ]; then
|
||||||
|
npm ci
|
||||||
|
else
|
||||||
|
npm install
|
||||||
|
fi
|
||||||
|
npm run --if-present test
|
||||||
|
npm run --if-present build
|
||||||
|
fi
|
||||||
|
elif [ -f pyproject.toml ] || [ -f pytest.ini ] || [ -d tests ]; then
|
||||||
|
python3 -m pip install --quiet pytest
|
||||||
|
rc=0
|
||||||
|
pytest -q || rc=$?
|
||||||
|
[ "$rc" -eq 5 ] && exit 0
|
||||||
|
exit "$rc"
|
||||||
|
elif find . -type f \( -path '*/src/test/*' -o -name '*Test.java' -o -name '*_test.py' -o -name '*.test.*' -o -name '*.spec.*' \) -print -quit | grep -q .; then
|
||||||
|
echo 'test files found but no supported build manifest'
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo 'artifact-only change: no executable build contract'
|
||||||
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue