<#22951 Using Github actions for pants check> New ...
# github-notifications
q
#22951 Using Github actions for pants check New discussion created by aebrahim How do people do their presubmits on GitHub actions, and is there any way to make them quick? This is the setup we use. It feels pretty hacky and homegrown, and the diff base does not work reliably. on: pull_request: paths: - "**.py" - "**/BUILD" - "**.lock" - mypy.ini - pants.* - .github/workflows/pants_code_quality.yml - 3rdparty/ workflow_dispatch: null push: branches: - main paths: - "**.py" - "**/BUILD" - "**.lock" - mypy.ini - pants.* - .github/workflows/pants_code_quality.yml - 3rdparty/ name: Pants Pull Request jobs: code_quality: runs-on: ubuntu-latest steps: - name: Git metrics id: git_metrics run: | if [ "${{ github.event_name }}" = "pull_request" ]; then echo "fetch_depth=$((${{ github.event.pull_request.commits }} + 1))" >> $GITHUB_OUTPUT echo "diff_base=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT elif [ "${{ github.event_name }}" = "push" ]; then echo "fetch_depth=2" >> $GITHUB_OUTPUT echo "diff_base=${{ github.event.before }}" >> $GITHUB_OUTPUT else echo "fetch_depth=1" >> $GITHUB_OUTPUT echo "diff_base=HEAD^" >> $GITHUB_OUTPUT fi - name: Checkout repo uses: actions/checkout@v6 with: # The pull request base sha is right below the merge commit GH checked out for us fetch-depth: ${{ steps.git_metrics.outputs.fetch_depth }} - uses: actions/setup-python@v6 with: python-version: '3.11' - name: Initialize Pants uses: pantsbuild/actions/init-pants@main with: base-branch: ${{ github.event.pull_request.base.ref || 'main' }} # The Python backend uses named_caches for Pip/PEX state, # so it is appropriate to invalidate on lockfile changes. named-caches-hash: ${{ hashFiles('3rdparty/python/*.lock') }} cache-lmdb-store: 'true' - name: Pants Peek run: pants --no-dynamic-ui --changed-since=${{ steps.git_metrics.outputs.diff_base }} --changed-dependents=direct peek --peek-output-file=/dev/null - name: Pants Lint run: pants --no-dynamic-ui --changed-since=${{ steps.git_metrics.outputs.diff_base }} --changed-dependents=direct lint - name: Pants Check run: pants --no-dynamic-ui --changed-since=${{ steps.git_metrics.outputs.diff_base }} --changed-dependents=direct check pantsbuild/pants