Skip to content

Commit 787ec83

Browse files
authored
Update deploy.yml
1 parent 4b73a1f commit 787ec83

1 file changed

Lines changed: 16 additions & 61 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ jobs:
3333
- name: Build the MkDocs site
3434
run: mkdocs build
3535

36+
- name: Check if gh-pages branch exists
37+
id: check_branch
38+
run: |
39+
if git ls-remote --heads origin gh-pages | grep -q 'refs/heads/gh-pages'; then
40+
echo "Branch exists"
41+
echo "branch_exists=true" >> $GITHUB_OUTPUT
42+
else
43+
echo "Branch does not exist"
44+
echo "branch_exists=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
3648
- name: Generate GitHub App token
3749
id: generate_token
3850
uses: tibdex/github-app-token@v1
@@ -47,22 +59,6 @@ jobs:
4759
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
4860
git clone --branch ${{ env.DOCS_BRANCH }} https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/acceleratescience/resource-hub.git temp_docs
4961
50-
# - name: Deploy to Documentation Repo
51-
# run: |
52-
# # Ensure the target directory exists
53-
# mkdir -p temp_docs/${{ env.DOCS_SUBDIR }}
54-
55-
# # Sync the built site to the target directory
56-
# rsync -av --delete ${{ env.MKDOCS_SITE_DIR }}/ temp_docs/${{ env.DOCS_SUBDIR }}/
57-
58-
# # Commit and push changes
59-
# cd temp_docs
60-
# git add .
61-
# git diff-index --quiet HEAD || (git stash && git pull --rebase origin ${{ env.DOCS_BRANCH }} && git stash pop)
62-
# git add .
63-
# git diff-index --quiet HEAD || git commit -m "Update ${{ env.DOCS_SUBDIR }} workshops"
64-
# git push origin ${{ env.DOCS_BRANCH }}
65-
6662
- name: Deploy to Documentation Repo
6763
run: |
6864
# Ensure the target directory exists
@@ -74,51 +70,10 @@ jobs:
7470
# Commit and push changes
7571
cd temp_docs
7672
git add .
77-
78-
# Try to pull and push multiple times
79-
max_attempts=5
80-
attempt=1
81-
while [ $attempt -le $max_attempts ]; do
82-
echo "Attempt $attempt of $max_attempts"
83-
84-
# Stash any changes
85-
git stash
86-
87-
# Pull with rebase
88-
if git pull --rebase origin ${{ env.DOCS_BRANCH }}; then
89-
# If pull successful, apply stashed changes
90-
git stash pop
91-
else
92-
echo "Pull failed, retrying..."
93-
git stash drop
94-
attempt=$((attempt+1))
95-
sleep 5
96-
continue
97-
fi
98-
99-
# Check for changes
100-
if git diff-index --quiet HEAD; then
101-
echo "No changes to commit"
102-
exit 0
103-
fi
104-
105-
# Commit changes
106-
git add .
107-
git commit -m "Update ${{ env.DOCS_SUBDIR }} resource-hub"
108-
109-
# Try to push
110-
if git push origin ${{ env.DOCS_BRANCH }}; then
111-
echo "Push successful"
112-
exit 0
113-
else
114-
echo "Push failed, retrying..."
115-
attempt=$((attempt+1))
116-
sleep 5
117-
fi
118-
done
119-
120-
echo "Failed to push after $max_attempts attempts"
121-
exit 1
73+
git diff-index --quiet HEAD || (git stash && git pull --rebase origin ${{ env.DOCS_BRANCH }} && git stash pop)
74+
git add .
75+
git diff-index --quiet HEAD || git commit -m "Update ${{ env.DOCS_SUBDIR }} resource-hub"
76+
git push origin ${{ env.DOCS_BRANCH }}
12277
12378
- name: Clean up
12479
if: always()

0 commit comments

Comments
 (0)