Skip to content

Commit 2abba21

Browse files
authored
Merge pull request #583 from maxim-belkin/better-syncing
Template workflow: smarter syncing with the styles repo
2 parents 97c32b9 + db953ba commit 2abba21

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

.github/workflows/template.yml

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
lesson: [swcarpentry/shell-novice, datacarpentry/r-intro-geospatial, librarycarpentry/lc-git]
1616
os: [ubuntu-20.04, macos-latest, windows-latest]
1717
experimental: [false]
18-
remote-theme: [false]
1918
include:
2019
- os: ubuntu-20.04
2120
os-name: Linux
@@ -34,7 +33,6 @@ jobs:
3433
experimental: true
3534
os: ubuntu-20.04
3635
os-name: Linux
37-
remote-theme: true
3836
- lesson: carpentries/lesson-example
3937
lesson-name: (CP) Lesson Example
4038
experimental: false
@@ -76,26 +74,54 @@ jobs:
7674
path: lesson
7775
fetch-depth: 0
7876

79-
- name: Determine the proper reference to use
80-
id: styles-ref
77+
- name: Sync lesson with carpentries/styles
78+
working-directory: lesson
8179
run: |
82-
if [[ -n "${{ github.event.pull_request.number }}" ]]; then
83-
echo "::set-output name=ref::refs/pull/${{ github.event.pull_request.number }}/head"
80+
echo "::group::Fetch Styles"
81+
if [[ -n "${{ github.event.pull_request.number }}" ]]
82+
then
83+
ref="refs/pull/${{ github.event.pull_request.number }}/head"
8484
else
85-
echo "::set-output name=ref::gh-pages"
85+
ref="gh-pages"
8686
fi
8787
88-
- name: Sync lesson with carpentries/styles
89-
if: ${{ ! matrix.remote-theme }}
90-
working-directory: lesson
91-
run: |
9288
git config --global user.email "[email protected]"
9389
git config --global user.name "The Carpentries Bot"
90+
9491
git remote add styles https://github.com/carpentries/styles.git
95-
git config --local remote.styles.tagOpt --no-tags
96-
git fetch styles ${{ steps.styles-ref.outputs.ref }}:styles-ref
97-
git merge -s recursive -Xtheirs --no-commit styles-ref
98-
git commit -m "Sync lesson with carpentries/styles"
92+
git fetch styles $ref:styles-ref
93+
echo "::endgroup::"
94+
echo "::group::Synchronize Styles"
95+
# Sync up only if necessary
96+
if [[ $(git rev-list --count HEAD..styles-ref) != 0 ]]
97+
then
98+
99+
# The merge command below might fail for lessons that use remote theme
100+
# https://github.com/carpentries/carpentries-theme
101+
echo "Testing merge using recursive strategy, accepting upstream changes without committing"
102+
if ! git merge -s recursive -Xtheirs --no-commit styles-ref
103+
then
104+
105+
# Remove "deleted by us, unmerged" files from the staging area.
106+
# these are the files that were removed from the lesson
107+
# but are still present in the carpentries/styles repo
108+
echo "Removing previously deleted files"
109+
git rm $(git diff --name-only --diff-filter=DU)
110+
111+
# If there are still "unmerged" files,
112+
# let's raise an error and look into this more closely
113+
if [[ -n $(git diff --name-only --diff-filter=U) ]]
114+
then
115+
echo "There were unmerged files in ${{ matrix.lesson-name }}:"
116+
echo "$(git diff --compact-summary --diff-filter=U)"
117+
exit 1
118+
fi
119+
fi
120+
121+
echo "Committing changes"
122+
git commit -m "Sync lesson with carpentries/styles"
123+
fi
124+
echo "::endgroup::"
99125
100126
- name: Look for R-markdown files
101127
id: check-rmd

0 commit comments

Comments
 (0)