Skip to content

Commit d3f553d

Browse files
committed
Template workflow: smarter syncing with the styles repo
Current syncing procedure that used in the Template workflow fails for: 1. Lessons that are, in fact, nsync with the styles repo. 2. For lessons that use The Carpentries' remote theme and have deleted some of the files. This PR makes this step a little bit more intelligent and takes into account the above two scenarios.
1 parent 97c32b9 commit d3f553d

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

.github/workflows/template.yml

Lines changed: 33 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,46 @@ 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+
if [[ -n "${{ github.event.pull_request.number }}" ]]
81+
then
82+
ref="refs/pull/${{ github.event.pull_request.number }}/head"
8483
else
85-
echo "::set-output name=ref::gh-pages"
84+
ref="gh-pages"
8685
fi
8786
88-
- name: Sync lesson with carpentries/styles
89-
if: ${{ ! matrix.remote-theme }}
90-
working-directory: lesson
91-
run: |
9287
git config --global user.email "[email protected]"
9388
git config --global user.name "The Carpentries Bot"
89+
9490
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"
91+
git fetch styles $ref:styles-ref
92+
93+
# Sync up only if necessary
94+
if [[ $(git rev-list --count HEAD..styles-ref) != 0 ]]
95+
then
96+
97+
# The merge command below might fail for lessons that use remote theme
98+
# https://github.com/carpentries/carpentries-theme
99+
if ! git merge -s recursive -Xtheirs --no-commit styles-ref
100+
then
101+
102+
# Remove "deleted by us, unmerged" files from the staging area.
103+
# these are the files that were removed from the lesson
104+
# but are still present in the carpentries/styles repo
105+
git rm $(git diff --name-only --diff-filter=DU)
106+
107+
# If there are still "unmerged" files,
108+
# let's raise an error and look into this more closely
109+
if [[ -n $(git diff --name-only --diff-filter=U) ]]
110+
then
111+
exit 1
112+
fi
113+
fi
114+
115+
git commit -m "Sync lesson with carpentries/styles"
116+
fi
99117
100118
- name: Look for R-markdown files
101119
id: check-rmd

0 commit comments

Comments
 (0)