diff --git a/.github/workflows/render-preview.yml b/.github/workflows/render-preview.yml index 6b05df14..bd89778e 100644 --- a/.github/workflows/render-preview.yml +++ b/.github/workflows/render-preview.yml @@ -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 @@ -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 diff --git a/.github/workflows/starting-course.yml b/.github/workflows/starting-course.yml index e5b33ab8..e688ec22 100644 --- a/.github/workflows/starting-course.yml +++ b/.github/workflows/starting-course.yml @@ -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! diff --git a/.github/workflows/style-and-sp-check.yml b/.github/workflows/style-and-sp-check.yml index 3611c75a..f455b6d5 100644 --- a/.github/workflows/style-and-sp-check.yml +++ b/.github/workflows/style-and-sp-check.yml @@ -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