|
| 1 | +# Candace Savonen 2021 |
| 2 | +# Updated May 2025 |
| 3 | + |
| 4 | +name: Pull Request |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + branches: [ main, staging ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + |
| 12 | + yaml-check: |
| 13 | + name: Load user automation choices |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + # Install dependencies |
| 22 | + - name: Install system dependencies for spatial R packages |
| 23 | + run: | |
| 24 | + sudo apt-get update |
| 25 | + sudo apt-get install -y gdal-bin libgdal-dev libproj-dev libgeos-dev libudunits2-dev cmake |
| 26 | +
|
| 27 | + # Use the yaml-env-action action. |
| 28 | + - name: Load environment from YAML |
| 29 | + uses: doughepi/yaml-env-action@v1.0.0 |
| 30 | + with: |
| 31 | + files: config_automation.yml # Pass a space-separated list of configuration files. Rightmost files take precedence. |
| 32 | + |
| 33 | + # Delete the branch if this has been run before |
| 34 | + - name: Delete branch locally and remotely |
| 35 | + run: git push origin --delete preview-${{ github.event.pull_request.number }} || echo "No branch to delete" |
| 36 | + |
| 37 | + # Make the branch fresh |
| 38 | + - name: Make the branch fresh |
| 39 | + run: | |
| 40 | + git config --global --add safe.directory $GITHUB_WORKSPACE |
| 41 | + git config --global user.name 'github-actions[bot]' |
| 42 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 43 | +
|
| 44 | + branch_name='preview-${{ github.event.pull_request.number }}' |
| 45 | + echo branch doesnt exist |
| 46 | + git checkout -b $branch_name || echo branch exists |
| 47 | + git push --set-upstream origin $branch_name || echo branch exists remotely |
| 48 | + shell: bash |
| 49 | + |
| 50 | + |
| 51 | + outputs: |
| 52 | + toggle_website: "${{ env.RENDER_WEBSITE }}" |
| 53 | + toggle_spell_check: "${{ env.SPELL_CHECK }}" |
| 54 | + spell_error_min: "${{ env.SPELL_ERROR_MIN }}" |
| 55 | + toggle_style_code: "${{ env.STYLE_CODE }}" |
| 56 | + toggle_url_check: "${{ env.URL_CHECKER }}" |
| 57 | + url_error_min: "${{ env.URL_ERROR_MIN }}" |
| 58 | + toggle_quiz_check: "${{ env.CHECK_QUIZZES }}" |
| 59 | + quiz_error_min: "${{ env.QUIZ_ERROR_MIN }}" |
| 60 | + toggle_md_linter: "${{ env.MARKDOWN_LINTER }}" |
| 61 | + toggle_readability: "${{ env.READABILITY_REPORT }}" |
| 62 | + toggle_render_preview: "${{ env.RENDER_PREVIEW }}" |
| 63 | + toggle_dictionary_sort: "${{ env.DICTIONARY_SORT }}" |
| 64 | + rendering_docker_image: "${{ env.RENDERING_DOCKER_IMAGE }}" |
| 65 | + |
| 66 | +########################## Make the error reports ############################## |
| 67 | + ottr-reports: |
| 68 | + name: Run Reports |
| 69 | + needs: yaml-check |
| 70 | + if: ${{needs.yaml-check.outputs.toggle_spell_check == 'true' || needs.yaml-check.outputs.toggle_url_check == 'true' || needs.yaml-check.outputs.toggle_quiz_check == 'true'}} |
| 71 | + runs-on: ubuntu-latest |
| 72 | + permissions: |
| 73 | + pull-requests: write |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Checkout Actions Repository |
| 77 | + uses: actions/checkout@v4 |
| 78 | + with: |
| 79 | + fetch-depth: 0 |
| 80 | + |
| 81 | + - name: Run Reports |
| 82 | + id: run-reports |
| 83 | + uses: ottrproject/ottr-reports@main |
| 84 | + with: |
| 85 | + check_spelling: ${{needs.yaml-check.outputs.toggle_spell_check}} |
| 86 | + spelling_error_min: ${{needs.yaml-check.outputs.spell_error_min}} |
| 87 | + check_urls: ${{needs.yaml-check.outputs.toggle_url_check}} |
| 88 | + url_error_min: ${{needs.yaml-check.outputs.url_error_min}} |
| 89 | + check_quiz_form: ${{needs.yaml-check.outputs.toggle_quiz_check}} |
| 90 | + quiz_error_min: ${{needs.yaml-check.outputs.quiz_error_min}} |
| 91 | + sort_dictionary: ${{needs.yaml-check.outputs.toggle_dictionary_sort}} |
| 92 | + |
| 93 | +############################# Style the code ################################### |
| 94 | + style-code: |
| 95 | + name: Style code |
| 96 | + needs: yaml-check |
| 97 | + runs-on: ubuntu-latest |
| 98 | + if: ${{needs.yaml-check.outputs.toggle_style_code == 'true'}} |
| 99 | + container: |
| 100 | + image: jhudsl/base_ottr:main |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Checkout files |
| 104 | + uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + fetch-depth: 0 |
| 107 | + |
| 108 | + - name: Run styler |
| 109 | + run: Rscript -e "styler::style_file(list.files(pattern = '(R|q)md$', recursive = FALSE, full.names = TRUE));warnings()" |
| 110 | + |
| 111 | + - name: Commit styled files |
| 112 | + run: | |
| 113 | + git config --system --add safe.directory "$GITHUB_WORKSPACE" |
| 114 | + git add \*md |
| 115 | + git commit -m 'Style *mds' || echo "No changes to commit" |
| 116 | + git push origin || echo "No changes to commit" |
| 117 | +
|
| 118 | +############################# Readability Report ################################### |
| 119 | + |
| 120 | + readability-report: |
| 121 | + name: Readability report |
| 122 | + needs: yaml-check |
| 123 | + runs-on: ubuntu-latest |
| 124 | + if: ${{needs.yaml-check.outputs.toggle_readability == 'true'}} |
| 125 | + |
| 126 | + steps: |
| 127 | + - name: Checkout repo |
| 128 | + uses: actions/checkout@v4 |
| 129 | + with: |
| 130 | + fetch-depth: 0 |
| 131 | + |
| 132 | + - name: Readability report |
| 133 | + uses: Rebilly/lexi@v2 |
| 134 | + with: |
| 135 | + github-token: ${{ secrets.GH_PAT }} |
| 136 | + glob: '**/*.md' |
| 137 | + |
| 138 | +############################# Render Preview ################################### |
| 139 | + render-preview: |
| 140 | + name: Render preview |
| 141 | + needs: yaml-check |
| 142 | + runs-on: ubuntu-latest |
| 143 | + if: ${{needs.yaml-check.outputs.toggle_render_preview == 'true'}} |
| 144 | + permissions: |
| 145 | + pull-requests: write |
| 146 | + contents: write |
| 147 | + |
| 148 | + steps: |
| 149 | + - name: Checkout repo |
| 150 | + uses: actions/checkout@v4 |
| 151 | + with: |
| 152 | + fetch-depth: 0 |
| 153 | + # Install dependencies |
| 154 | + - name: Install system dependencies for spatial R packages |
| 155 | + run: | |
| 156 | + sudo apt-get update |
| 157 | + sudo apt-get install -y gdal-bin libgdal-dev libproj-dev libgeos-dev libudunits2-dev cmake |
| 158 | +
|
| 159 | + - name: Run render |
| 160 | + uses: ottrproject/ottr-preview@main |
| 161 | + with: |
| 162 | + toggle_website: ${{needs.yaml-check.outputs.toggle_website}} |
| 163 | + docker_image: ${{needs.yaml-check.outputs.rendering_docker_image}} |
0 commit comments