Skip to content

Commit 8ad7f65

Browse files
Merge pull request #100 from Muckenbatscher/bugfix/create-test-branch
create test branch
2 parents c98635a + af8f760 commit 8ad7f65

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

.github/workflows/create_tests.yml

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
name: generated-testcase-cs-files
6565
path: ${{ env.OUTPUT_PATH }}
6666
retention-days: 1
67-
67+
6868
create-refs:
6969
needs: build-java
7070
runs-on: ubuntu-latest
@@ -76,7 +76,6 @@ jobs:
7676
TEST_THEME_DIR: MaterialTheming.Tests/KnownTestThemes
7777

7878
outputs:
79-
existing_branch: ${{ steps.existing_branch.outputs.exists }}
8079
has_changes: ${{ steps.check_diff.outputs.has_changes }}
8180

8281
steps:
@@ -102,11 +101,9 @@ jobs:
102101
git fetch origin ${{ env.PR_SOURCE_BRANCH_NAME }}
103102
git checkout -B ${{ env.PR_SOURCE_BRANCH_NAME }} origin/${{ env.PR_SOURCE_BRANCH_NAME }}
104103
105-
- name: Create and push new branch
104+
- name: Create new branch
106105
if: steps.existing_branch.outputs.exists != 'true'
107-
run: |
108-
git checkout -B ${{ env.PR_SOURCE_BRANCH_NAME }}
109-
git push --set-upstream origin ${{ env.PR_SOURCE_BRANCH_NAME }}
106+
run: git checkout -B ${{ env.PR_SOURCE_BRANCH_NAME }}
110107

111108
- uses: actions/download-artifact@v8
112109
with:
@@ -119,7 +116,10 @@ jobs:
119116
- name: Check for changes in the testcases
120117
id: check_diff
121118
run: |
122-
CHANGES=$(git diff --name-only -- ${{ env.TEST_THEME_DIR }} .official-commit-sha)
119+
git add ${{ env.TEST_THEME_DIR }}
120+
git add .official-commit-sha
121+
122+
CHANGES=$(git diff --staged --name-only)
123123
124124
if [ -z "$CHANGES" ]; then
125125
echo "No changes found in '${{ env.TEST_THEME_DIR }}'"
@@ -135,13 +135,11 @@ jobs:
135135
git config user.name "github-actions[bot]"
136136
git config user.email "github-actions[bot]@users.noreply.github.com"
137137
138-
- name: Commit generated tests
138+
- name: Commit and push generated tests
139139
if: steps.check_diff.outputs.has_changes == 'true'
140140
run: |
141-
git add ${{ env.TEST_THEME_DIR }}
142-
git add .official-commit-sha
143141
git commit -m "Update C# testcase files. Generated from Java reference implementation."
144-
git push
142+
git push -u origin ${{ env.PR_SOURCE_BRANCH_NAME }}
145143
146144
generate-pr:
147145
needs: create-refs
@@ -152,9 +150,11 @@ jobs:
152150

153151
steps:
154152
- uses: actions/checkout@v6
153+
with:
154+
fetch-depth: 0 # fetch whole history, to be able to compare
155155

156156
- name: Check for existing PR
157-
id: exsting_pr
157+
id: existing_pr
158158
env:
159159
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160160
run: |
@@ -166,9 +166,33 @@ jobs:
166166
echo "Existing PR found for the branch ${{ env.PR_SOURCE_BRANCH_NAME }}."
167167
echo "exists=true" >> $GITHUB_OUTPUT
168168
fi
169-
169+
170+
- name: Check for differences in existing branch
171+
id: branch_diff
172+
if: steps.existing_pr.outputs.exists == 'false'
173+
run: |
174+
if git ls-remote --exit-code --heads origin ${{ env.PR_SOURCE_BRANCH_NAME }}; then
175+
echo "Branch '${{ env.PR_SOURCE_BRANCH_NAME }}' exists on remote. Fetching latest changes..."
176+
177+
git fetch origin ${{ env.PR_TARGET_BRANCH_NAME }}
178+
git fetch origin ${{ env.PR_SOURCE_BRANCH_NAME }}
179+
180+
CHANGES=$(git diff origin/${{ env.PR_TARGET_BRANCH_NAME }}..origin/${{ env.PR_SOURCE_BRANCH_NAME }} --name-only)
181+
182+
if [ -z "$CHANGES" ]; then
183+
echo "Branch '${{ env.PR_SOURCE_BRANCH_NAME }}' is identical to '${{ env.PR_TARGET_BRANCH_NAME }}'."
184+
echo "has_diff=false" >> $GITHUB_OUTPUT
185+
else
186+
echo "Branch '${{ env.PR_SOURCE_BRANCH_NAME }}' has differences to '${{ env.PR_TARGET_BRANCH_NAME }}'."
187+
echo "has_diff=true" >> $GITHUB_OUTPUT
188+
fi
189+
else
190+
echo "Branch '${{ env.PR_SOURCE_BRANCH_NAME }}' does not exist on remote."
191+
echo "has_diff=false" >> $GITHUB_OUTPUT
192+
fi
193+
170194
- name: Create Pull Request
171-
if: steps.exsting_pr.outputs.exists != 'true' && (needs.create-refs.outputs.existing_branch == 'true' || needs.create-refs.outputs.has_changes == 'true')
195+
if: steps.existing_pr.outputs.exists == 'false' && steps.branch_diff.outputs.has_diff == 'true'
172196
env:
173197
GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOW }}
174198
run: |

0 commit comments

Comments
 (0)