Skip to content

Commit 20f9e49

Browse files
committed
Enhance error handling for Git push in fetch-sfs-workflow.yml
1 parent e51f7c7 commit 20f9e49

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

.github/workflows/fetch-sfs-workflow.yml

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,35 @@ jobs:
7777
echo "has_changes=true" >> $GITHUB_OUTPUT
7878
echo "commit_branch=${COMMIT_BRANCH}" >> $GITHUB_OUTPUT
7979
80-
# Push the new branch
81-
git push origin "$COMMIT_BRANCH"
80+
# Push the new branch with error handling
81+
echo "Försöker pusha branch '${COMMIT_BRANCH}' till origin..."
82+
83+
if git push origin "$COMMIT_BRANCH" 2>&1; then
84+
echo "✅ Git push lyckades för branch '${COMMIT_BRANCH}'"
85+
echo "push_success=true" >> $GITHUB_OUTPUT
86+
echo "push_error=" >> $GITHUB_OUTPUT
87+
else
88+
PUSH_EXIT_CODE=$?
89+
PUSH_ERROR="Git push misslyckades med exit code: ${PUSH_EXIT_CODE}"
90+
echo "❌ ${PUSH_ERROR}"
91+
echo "push_success=false" >> $GITHUB_OUTPUT
92+
echo "push_error=${PUSH_ERROR}" >> $GITHUB_OUTPUT
93+
94+
# Logga mer detaljerad information för debugging
95+
echo "Git status:"
96+
git status
97+
echo "Git remote info:"
98+
git remote -v
99+
echo "Git log (senaste commit):"
100+
git log --oneline -1
101+
102+
# Switch back to original branch even if push failed
103+
git checkout "$CURRENT_BRANCH"
104+
105+
# Fail the job if push failed
106+
echo "::error::Git push misslyckades: ${PUSH_ERROR}"
107+
exit 1
108+
fi
82109
83110
# Switch back to original branch
84111
git checkout "$CURRENT_BRANCH"
@@ -87,7 +114,7 @@ jobs:
87114
fi
88115
89116
- name: Trigger HTML export workflow
90-
if: steps.commit_changes.outputs.has_changes == 'true'
117+
if: steps.commit_changes.outputs.has_changes == 'true' && steps.commit_changes.outputs.push_success == 'true'
91118
uses: actions/github-script@v6
92119
with:
93120
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -98,3 +125,9 @@ jobs:
98125
workflow_id: 'html-export-workflow.yml',
99126
ref: context.ref
100127
})
128+
129+
- name: Report push failure
130+
if: steps.commit_changes.outputs.has_changes == 'true' && steps.commit_changes.outputs.push_success == 'false'
131+
run: |
132+
echo "::warning::Git push misslyckades: ${{ steps.commit_changes.outputs.push_error }}"
133+
echo "HTML export workflow kommer inte att triggas på grund av push-fel."

0 commit comments

Comments
 (0)