Skip to content

Commit

Permalink
Merge pull request #583 from maxim-belkin/better-syncing
Browse files Browse the repository at this point in the history
Template workflow: smarter syncing with the styles repo
  • Loading branch information
zkamvar authored Apr 23, 2021
2 parents 97c32b9 + db953ba commit 2abba21
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
lesson: [swcarpentry/shell-novice, datacarpentry/r-intro-geospatial, librarycarpentry/lc-git]
os: [ubuntu-20.04, macos-latest, windows-latest]
experimental: [false]
remote-theme: [false]
include:
- os: ubuntu-20.04
os-name: Linux
Expand All @@ -34,7 +33,6 @@ jobs:
experimental: true
os: ubuntu-20.04
os-name: Linux
remote-theme: true
- lesson: carpentries/lesson-example
lesson-name: (CP) Lesson Example
experimental: false
Expand Down Expand Up @@ -76,26 +74,54 @@ jobs:
path: lesson
fetch-depth: 0

- name: Determine the proper reference to use
id: styles-ref
- name: Sync lesson with carpentries/styles
working-directory: lesson
run: |
if [[ -n "${{ github.event.pull_request.number }}" ]]; then
echo "::set-output name=ref::refs/pull/${{ github.event.pull_request.number }}/head"
echo "::group::Fetch Styles"
if [[ -n "${{ github.event.pull_request.number }}" ]]
then
ref="refs/pull/${{ github.event.pull_request.number }}/head"
else
echo "::set-output name=ref::gh-pages"
ref="gh-pages"
fi
- name: Sync lesson with carpentries/styles
if: ${{ ! matrix.remote-theme }}
working-directory: lesson
run: |
git config --global user.email "team@carpentries.org"
git config --global user.name "The Carpentries Bot"
git remote add styles https://github.com/carpentries/styles.git
git config --local remote.styles.tagOpt --no-tags
git fetch styles ${{ steps.styles-ref.outputs.ref }}:styles-ref
git merge -s recursive -Xtheirs --no-commit styles-ref
git commit -m "Sync lesson with carpentries/styles"
git fetch styles $ref:styles-ref
echo "::endgroup::"
echo "::group::Synchronize Styles"
# Sync up only if necessary
if [[ $(git rev-list --count HEAD..styles-ref) != 0 ]]
then
# The merge command below might fail for lessons that use remote theme
# https://github.com/carpentries/carpentries-theme
echo "Testing merge using recursive strategy, accepting upstream changes without committing"
if ! git merge -s recursive -Xtheirs --no-commit styles-ref
then
# Remove "deleted by us, unmerged" files from the staging area.
# these are the files that were removed from the lesson
# but are still present in the carpentries/styles repo
echo "Removing previously deleted files"
git rm $(git diff --name-only --diff-filter=DU)
# If there are still "unmerged" files,
# let's raise an error and look into this more closely
if [[ -n $(git diff --name-only --diff-filter=U) ]]
then
echo "There were unmerged files in ${{ matrix.lesson-name }}:"
echo "$(git diff --compact-summary --diff-filter=U)"
exit 1
fi
fi
echo "Committing changes"
git commit -m "Sync lesson with carpentries/styles"
fi
echo "::endgroup::"
- name: Look for R-markdown files
id: check-rmd
Expand Down

0 comments on commit 2abba21

Please sign in to comment.