-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from jhudsl/cansavvy/tweak-git
Some tweaks to git branch handling on GHA
- Loading branch information
Showing
3 changed files
with
73 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,18 @@ jobs: | |
git config --local user.email "[email protected]" | ||
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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,17 +51,34 @@ jobs: | |
# Commit modified files | ||
- name: Commit deleted files | ||
id: commit_it | ||
run: | | ||
git config --local user.email "[email protected]" | ||
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! | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 "[email protected]" | ||
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 | ||
|