Path-Check / safeplaces-dct-app

COVID Safe Paths (based on Private Kit) is an open and privacy preserving system to use personal information to battle COVID
https://covidsafepaths.org
MIT License
465 stars 285 forks source link

Cause workflows to alway run, but pass when not needed #1314

Closed JacobJaffe closed 4 years ago

JacobJaffe commented 4 years ago

Improves our workflows so we can require all tests on PRs, but they will auto succeed if no changes detected. We can adjust what "changes detected" means as we see fit.

How this works:

URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${{ github.event.pull_request.number }}/files"
FILES=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s -X GET -G $URL |  jq -r '.[] | .filename')
echo "Checking Files: $FILES"
REGEX="\.js\|\.jsx\|\.ts\|\.tsx"
if echo $FILES | grep -q $REGEX; then
  echo "Detected iOS changes. Running tests!"
  echo "Changed Files:"
  echo $FILES | grep $REGEX
  echo "::set-env name=RUN_TESTS::1"
else
  echo "No iOS changed detected. Skipping tests."
  echo "::set-env name=RUN_TESTS::0"
fi
  1. Fetch JSON of files from current PR. Do this in an authorized request, otherwise we face rate limiting by GitHub.
  2. Define a regex for our files we watch for. This is like what we previously did with --paths, except this happens within the job.
  3. if those files match the changed files, set the RUN_TESTS command
  4. make each step conditional RUN_TESTS

step 4 is a little tedious, but it seems that there is no way to succeed a workflow early, only fail it.

How to test this:

change files matching the regex, make a PR with this code