Skip to content

Commit

Permalink
all in one step
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed May 18, 2023
1 parent f6a40aa commit 4b77f91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,15 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 10
- id: comparison
name: Materialize comparison SHA
run: "\nif [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then\n # push: we need to make sure the parent commit(s) exist\n\
\ git fetch --deepen=1\n comparison_sha=$(git rev-parse HEAD^)\nelse\n # pull request: just fetch what github is\
\ telling us the base is\n git fetch origin --depth=1 \"$GITHUB_EVENT_PULL_REQUEST_BASE_SHA\"\n comparison_sha=\"\
$GITHUB_EVENT_PULL_REQUEST_BASE_SHA\"\nfi\necho \"comparison_sha=$comparison_sha\" | tee -a $GITHUB_OUTPUT\n"
- id: classify
name: Classify changed files
run: "affected=$(git diff --name-only \"${{ steps.comparison.outputs.comparison_sha }}\" HEAD | python build-support/bin/classify_changed_files.py)\n\
echo \"Affected:\"\nif [[ \"${affected}\" == \"docs\" ]]; then\n echo \"docs_only=true\" | tee -a $GITHUB_OUTPUT\n\
fi\nfor i in ${affected}; do\n echo \"${i}=true\" | tee -a $GITHUB_OUTPUT\ndone\n"
run: "if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then\n # push: compare to the immediate parent, which should\
\ already be fetched\n # (checkout's fetch_depth defaults to 10)\n comparison_sha=$(git rev-parse HEAD^)\nelse\n\
\ # pull request: compare to the base branch, ensuring that commit exists\n git fetch --depth=1 \"$GITHUB_EVENT_PULL_REQUEST_BASE_SHA\"\
\n comparison_sha=\"$GITHUB_EVENT_PULL_REQUEST_BASE_SHA\"\nfi\necho \"comparison_sha=$comparison_sha\"\n\naffected=$(git\
\ diff --name-only \"$comparison_sha\" HEAD | python build-support/bin/classify_changed_files.py)\necho \"Affected:\"\
\nif [[ \"${affected}\" == \"docs\" ]]; then\n echo \"docs_only=true\" | tee -a $GITHUB_OUTPUT\nfi\nfor i in ${affected};\
\ do\n echo \"${i}=true\" | tee -a $GITHUB_OUTPUT\ndone\n"
lint_python:
if: (github.repository_owner == 'pantsbuild') && (needs.classify_changes.outputs.docs_only != 'true')
name: Lint Python and Shell
Expand Down
27 changes: 10 additions & 17 deletions build-support/bin/generate_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,22 @@ def classify_changes() -> Jobs:
"steps": [
*checkout(),
{
"id": "comparison",
"name": "Materialize comparison SHA",
"id": "classify",
"name": "Classify changed files",
"run": dedent(
"""
f"""\
if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
# push: we need to make sure the parent commit(s) exist
git fetch --deepen=1
# push: compare to the immediate parent, which should already be fetched
# (checkout's fetch_depth defaults to 10)
comparison_sha=$(git rev-parse HEAD^)
else
# pull request: just fetch what github is telling us the base is
git fetch origin --depth=1 "$GITHUB_EVENT_PULL_REQUEST_BASE_SHA"
# pull request: compare to the base branch, ensuring that commit exists
git fetch --depth=1 "$GITHUB_EVENT_PULL_REQUEST_BASE_SHA"
comparison_sha="$GITHUB_EVENT_PULL_REQUEST_BASE_SHA"
fi
echo "comparison_sha=$comparison_sha" | tee -a $GITHUB_OUTPUT
"""
)
},
{
"id": "classify",
"name": "Classify changed files",
"run": dedent(
f"""\
affected=$(git diff --name-only "{gha_expr("steps.comparison.outputs.comparison_sha")}" HEAD | python build-support/bin/classify_changed_files.py)
echo "comparison_sha=$comparison_sha"
affected=$(git diff --name-only "$comparison_sha" HEAD | python build-support/bin/classify_changed_files.py)
echo "Affected:"
if [[ "${{affected}}" == "docs" ]]; then
echo "docs_only=true" | tee -a $GITHUB_OUTPUT
Expand Down

0 comments on commit 4b77f91

Please sign in to comment.