Hi, did someone successfuly configured a github wo...
# general
a
Hi, did someone successfuly configured a github workflow with
--changed-since=
?
b
We are using it to check the correctness of pull-requests. This part follows recommendations from https://www.pantsbuild.org/docs/using-pants-in-ci
Copy code
- name: Check BUILD files
        run: |
          pants \
          --changed-since=origin/main \
          tailor --check \
          update-build-files --check \
          lint
      - name: Typecheck and test
        run: |
          pants \
          --changed-since=origin/main \
          --changed-dependents=transitive \
          check test
Our github actions pipeline is also calling the following script, which build+publish+deploy (using true foundry) the docker images whose transitive dependencies changed.
Copy code
set -x
REF_BRANCH=${1:-origin/main}
GIT_COMMIT=$(git rev-parse HEAD)
changed_dockers=$( \
    pants --changed-since=${REF_BRANCH} --changed-dependents=transitive \
    --filter-target-type=docker_image --tag=auto_deploy \
    list)
for docker_target in $changed_dockers; do
    GIT_COMMIT=${GIT_COMMIT} pants --level=warn package publish $docker_target
    repository=$(pants peek $docker_target | jq -r '.[0].repository')
    docker_image_uri=<http://datasciencemodels.azurecr.io/${repository}:commit-${GIT_COMMIT}|datasciencemodels.azurecr.io/${repository}:commit-${GIT_COMMIT}>
    app_fqn=$( \
        pants peek $docker_target \
        | jq -r '.[0].tags[]' \
        | grep "fqn=" \
        | sed 's/^fqn=//'
    )
    sfy patch-application --application_fqn=${app_fqn}  \
        --patch="{\"image\": {\"image_uri\": \"${docker_image_uri}\"}}"
done
a
Copy code
# Copyright 2020 Pants project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

# See <https://pants.readme.io/docs/using-pants-in-ci> for tips on how to set up your CI with Pants.

name: Pants

on:
  push:
    branches:
      - main
  pull_request:



jobs:
  changed_since:
    name: get changed since
    runs-on: ubuntu-20.04
    steps:
      - name: set changed-since
        id: changed_since
        run: |
          if [ -z "$GITHUB_BASE_REF" ]; then
            CHANGED_SINCE=$GITHUB_REF
          else
            CHANGED_SINCE=$GITHUB_BASE_REF          
          fi
          echo "CHANGED_SINCE=$CHANGED_SINCE" >> "$GITHUB_OUTPUT"     
          echo "$CHANGED_SINCE" >> $GITHUB_STEP_SUMMARY


  build:
    name: Build
    needs:
      - changed_since
    env:
      CHANGED_SINCE: ${{ needs.changed_since.outputs.CHANGED_SINCE }}


    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version: [3.11]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: pantsbuild/actions/init-pants@v5-scie-pants
        with:
          gha-cache-key: v0
          named-caches-hash: ${{ hashFiles('python-default.lock') }}
          cache-lmdb-store: 'true'  # defaults to 'false'
      - name: Generate stubs
        run: make regenerate-stubs

      - name: Lint and typecheck
        run: |
          pants --changed-since=${CHANGED_SINCE} lint check
      - name: Test
        run: |
          pants test ::
      - name: Package / Run
        run: |
          # We also smoke test that our release process will work by running `package`.
          pants package --changed-since=${CHANGED_SINCE}

      - name: Upload pants log
        uses: actions/upload-artifact@v3
        if: always()  # We want the log even on failures.
        with:
          name: pants-log
          path: .pants.d/pants.log


      - name: Test Report
        uses: mikepenz/action-junit-report@v4
        if: success() || failure()
        with:
          report_paths: dist/test/reports/*.xml

      - name: Coverage Report
        uses: 5monkeys/cobertura-action@master
        if: success() || failure()
        with:
          path: dist/coverage/**/*.xml
          minimum_coverage: 75
          fail_below_threshold: true

  publish:
    name: Publish Monorepo Packages
    needs: build
    runs-on: ubuntu-20.04
    if: github.event_name == 'push'
    strategy:
      matrix:
        python-version: [3.11]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: pantsbuild/actions/init-pants@v5-scie-pants
        with:
          gha-cache-key: v0
          named-caches-hash: ${{ hashFiles('python-default.lock') }}
          cache-lmdb-store: 'true'  # defaults to 'false'

      - name: Generate Assets
        run: |
          pants --changed-since=${CHANGED_SINCE} export-codegen 

      - name: Publish / Run
        env:
          TWINE_USERNAME: ${{ secrets.TWINE_USER }}
          TWINE_PASSWORD: ${{ secrets.TWINE_PASS }}
        run: |
          pants --changed-since=${CHANGED_SINCE} publish
So this is what I ended with, I needed to calculate the changed since so it could work in many branches