Skip to content

Commit

Permalink
Merge pull request #418 from jhudsl/cansavvy/tweak-git
Browse files Browse the repository at this point in the history
Some tweaks to git branch handling on GHA
  • Loading branch information
jhudsl-robot authored Jan 26, 2022
2 parents 125cad2 + 800cb6b commit 65579db
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
35 changes: 25 additions & 10 deletions .github/workflows/render-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ jobs:
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
git checkout -b "preview-${{ github.event.pull_request.number }}"
branch_name='preview-${{ github.event.pull_request.number }}'
exists=$(git ls-remote https://${{ secrets.GH_PAT }}@github.com/$GITHUB_REPOSITORY $branch_name | wc -l | xargs)
if [[ $exists -gt 0 ]];then
echo branch does exist
git checkout $branch_name
git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }}
else
echo branch doesnt exist
git checkout -b $branch_name
git push --set-upstream origin $branch_name
fi
rm -r docs/*
# Run bookdown rendering
Expand Down Expand Up @@ -58,17 +69,21 @@ jobs:
- name: Commit rendered bookdown files to preview branch
id: commit
run: |
changes=$(git diff --name-only -- docs)
if -z $changes
then
echo ::set-output name=changes::$(echo 'no_changes')
else
branch_name='preview-${{ github.event.pull_request.number }}'
git diff --name-only origin/main -- docs >/dev/null && changes=true || changes=false
echo $changes
if $changes == true; then
echo ::set-output name=changes::$(echo 'changes')
git add . --force
git commit -m 'Render bookdown preview'
git push --force origin "preview-${{ github.event.pull_request.number }}"
git diff --name-only origin/$branch_name -- docs/ >/dev/null && changes=true || changes=false
echo $changes
if $changes == true; then
git add . --force
git commit -m 'Render bookdown preview'
git pull --set-upstream origin $branch_name --allow-unrelated-histories
git push
fi
fi
shell: bash

- name: Find Comment
uses: peter-evans/find-comment@v1
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/starting-course.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,34 @@ jobs:
# Commit modified files
- name: Commit deleted files
id: commit_it
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Template cleanup"
pushed_it=true
git push || pushed_it=false
echo ::set-output name=pushed_it::$pushed_it
# Push changes
- name: Push changes
uses: ad-m/github-push-action@master
# If main is already protected, then file a PR
- name: Create PR with deleted files
if: steps.commit_it.outputs.pushed_it == 'false'
uses: peter-evans/create-pull-request@v3
id: pr
with:
branch: main
commit-message: Delete unnecessary files
signoff: false
branch: auto_copy_rendered_files
delete-branch: true
title: 'Automatic course set up'
body: |
### Description:
This PR was initiated by the github actions. It helps set up this repository to be ready to write your course.
It deletes some remnant files you don't need for your course but were used when this was a template.
labels: |
automated
reviewers: $GITHUB_ACTOR

##### Filing issues!

Expand Down
42 changes: 27 additions & 15 deletions .github/workflows/style-and-sp-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,57 @@ jobs:
container:
image: jhudsl/course_template

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout files
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: login as jhudsl-robot

- name: Configure git
run: |
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
branch_name='preview-${{ github.event.pull_request.number }}'
exists=$(git ls-remote https://${{ secrets.GH_PAT }}@github.com/$GITHUB_REPOSITORY $branch_name | wc -l | xargs)
if [[ $exists -gt 0 ]];then
echo branch does exist
git checkout $branch_name
git merge -s recursive --strategy-option=theirs origin/${{ github.head_ref }}
else
echo branch doesnt exist
git checkout -b $branch_name
git push --set-upstream origin $branch_name
fi
- name: Run spell check
id: spell_check_run
run: |
results=$(Rscript "scripts/spell-check.R")
echo "::set-output name=sp_chk_results::$results"
cat resources/spell_check_results.tsv
- name: Archive spelling errors
uses: actions/upload-artifact@v2
with:
name: spell-check-results
path: resources/spell_check_results.tsv

- name: Spell check errors
- name: Commit spell check errors
run: |
# Get on the preview branch if it exists. If it doesn't create it.
branch_name='preview-${{ github.event.pull_request.number }}'
git rev-parse --quiet --verify $branch_name >/dev/null && exists=true || exists=false
if $exists == true
then
git checkout $branch_name
git pull --set-upstream origin $branch_name --allow-unrelated-histories
else
git checkout -b $branch_name
git diff --name-only origin/main -- resources/spell_check_results.tsv >/dev/null && changes=true || changes=false
echo $changes
if $changes == true; then
git diff --name-only origin/$branch_name -- resources/spell_check_results.tsv >/dev/null && changes=true || changes=false
echo $changes
if $changes == true; then
git add --force resources/spell_check_results.tsv
git diff-index --quiet HEAD || git commit -m 'Add spell check file'
git pull --set-upstream origin $branch_name --allow-unrelated-histories
git push --force origin $branch_name
fi
fi
git add --force resources/spell_check_results.tsv
git commit -m 'Add spell check file'
git push --force --set-upstream origin $branch_name
- name: Build components of the spell check comment
id: build-components
Expand Down

0 comments on commit 65579db

Please sign in to comment.