diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..5d53bff --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,58 @@ +name: Bench Build Test + +on: + pull_request: + +concurrency: + group: ${{ github.repository }}-${{ github.event.number }} + cancel-in-progress: true + +jobs: + Bench-Build-Test: + runs-on: ubuntu-latest + container: + image: docker.io/frappe/bench:latest + options: --user root + + steps: + - name: Setup Github ENV + run: | + echo "HOME=/home/frappe" >> $GITHUB_ENV + echo "PATH=/home/frappe/.local/bin:$PATH" >> $GITHUB_ENV + + - name: Create a new minimal bench + run: | + cd /home/frappe + su frappe bash -c "bench init frappe-bench --skip-redis-config-generation --no-procfile --skip-assets" + + - name: Get Dependent Apps + run: | + cd /home/frappe/frappe-bench + # Use public URL for public repos, authenticated URL for private repos + if [ "${{ github.event.pull_request.head.repo.private }}" = "false" ]; then + # This is a public repository (could be a fork or not) + git clone https://github.com/${{ github.event.pull_request.head.repo.full_name }} -b ${{ github.event.pull_request.head.ref }} --depth=1 app_repo + else + # Private repository, use authentication + git clone https://rtbot:${{ secrets.RTBOT_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }} -b ${{ github.event.pull_request.head.ref }} --depth=1 app_repo + fi + DEPS=$(grep -E "required_apps\s*=\s*\[" app_repo/*/hooks.py | sed 's/.*\[\(.*\)\]/\1/g' | tr -d '"' | tr -d "'" | tr ',' '\n' | awk '{$1=$1};1') + rm -rf app_repo + for dep in $DEPS; do + su frappe bash -c "bench get-app $dep" + done + + - name: Get APP and Build + run: | + cd /home/frappe/frappe-bench + if [ "${{ github.event.pull_request.head.repo.private }}" = "false" ]; then + # Public fork + su frappe bash -c "bench get-app https://github.com/${{ github.event.pull_request.head.repo.full_name }} --branch ${{ github.event.pull_request.head.ref }}" + else + # Private fork (requires token) + su frappe bash -c "bench get-app https://rtbot:${{ secrets.RTBOT_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }} --branch ${{ github.event.pull_request.head.ref }}" + fi + + - name: Cleanup + if: ${{ always() }} + uses: rtCamp/action-cleanup@master \ No newline at end of file diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..d49b1a1 --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,52 @@ +name: Linters + +on: + pull_request: + workflow_dispatch: +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pre-commit: + name: "Frappe Linter" + runs-on: ubuntu-latest + container: + image: alpine:latest # latest used here for simplicity, not recommended + defaults: + run: + shell: sh + steps: + - name: fix tar dependency in alpine container image + run: | + apk --no-cache add tar nodejs npm python3 git bash py3-pip + apk --no-cache add prettier --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing + # check python modules installed versions + python3 -m pip freeze --local + pip install pre-commit --break-system-packages + + - uses: actions/checkout@v4 + - run: | + git config --global --add safe.directory $GITHUB_WORKSPACE + git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* + + - name: Get changed files + id: file_changes + run: | + export DIFF=$(git diff --name-only origin/${{ github.base_ref }} ${{ github.sha }}) + echo "Diff between ${{ github.base_ref }} and ${{ github.sha }}" + echo "files=$( echo "$DIFF" | xargs echo )" >> $GITHUB_OUTPUT + + + - name: Cache pre-commit since we use pre-commit from container + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }} + + - name: Execute pre-commit + run: | + pre-commit run --color=always --show-diff-on-failure --files ${{ steps.file_changes.outputs.files }} \ No newline at end of file