|
| 1 | +name: Periodic URL Check |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: '0 0 1 * *' |
| 7 | + |
| 8 | +jobs: |
| 9 | + set-up: |
| 10 | + name: Load user automation choices |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v3 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + # Use the yaml-env-action action. |
| 19 | + - name: Load environment from YAML |
| 20 | + uses: doughepi/yaml-env-action@v1.0.0 |
| 21 | + with: |
| 22 | + files: config_automation.yml # Pass a space-separated list of configuration files. Rightmost files take precedence. |
| 23 | + outputs: |
| 24 | + toggle_url_check_periodically: "${{ env.URL_CHECK_PERIODICALLY }}" |
| 25 | + |
| 26 | + url-check: |
| 27 | + name: Check URLs |
| 28 | + needs: set-up |
| 29 | + if: ${{needs.set-up.outputs.toggle_url_check_periodically == 'yes'}} |
| 30 | + runs-on: ubuntu-latest |
| 31 | + container: |
| 32 | + image: jhudsl/base_ottr:main |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v3 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + |
| 40 | + # Delete the branch if this has been run before |
| 41 | + - name: Delete branch locally and remotely |
| 42 | + run: git push origin --delete preview-spell-error || echo "No branch to delete" |
| 43 | + |
| 44 | + # Make the branch fresh |
| 45 | + - name: Make the branch fresh |
| 46 | + run: | |
| 47 | + git config --global --add safe.directory $GITHUB_WORKSPACE |
| 48 | + git config --global user.name 'github-actions[bot]' |
| 49 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 50 | +
|
| 51 | + echo branch doesnt exist |
| 52 | + git checkout -b preview-spell-error || echo branch exists |
| 53 | + git push --set-upstream origin preview-spell-error || echo echo branch exists remotely |
| 54 | + shell: bash |
| 55 | + |
| 56 | + - name: Run the check |
| 57 | + uses: jhudsl/ottr-reports@main |
| 58 | + id: check_results |
| 59 | + continue-on-error: true |
| 60 | + with: |
| 61 | + check_type: urls |
| 62 | + error_min: 1 |
| 63 | + |
| 64 | + - name: Declare file path and time |
| 65 | + id: check-report |
| 66 | + run: | |
| 67 | + error_num=$(cat check_reports/url_checks.tsv | wc -l) |
| 68 | + error_num="$((error_num-1))" |
| 69 | + echo "error_num=$error_num" >> $GITHUB_OUTPUT |
| 70 | + echo "error_url=https://github.com/${GITHUB_REPOSITORY}/blob/preview-spell-error/check_reports/url_checks.tsv" >> $GITHUB_OUTPUT |
| 71 | + shell: bash |
| 72 | + |
| 73 | + - name: Stop if failure |
| 74 | + if: steps.check_results.outcome == 'failure' |
| 75 | + run: exit 1 |
| 76 | + |
| 77 | + - name: Print out error variables |
| 78 | + run: | |
| 79 | + echo ${{ steps.check-report.outputs.error_url }} |
| 80 | + echo ${{ steps.check-report.outputs.error_num }} |
| 81 | +
|
| 82 | + - name: Find issues |
| 83 | + id: find-issue |
| 84 | + env: |
| 85 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 86 | + run: | |
| 87 | + echo "$GITHUB_REPOSITORY" |
| 88 | + curl -o find_issue.R https://raw.githubusercontent.com/jhudsl/ottr-reports/main/scripts/find_issue.R |
| 89 | + issue_exists=$(Rscript --vanilla find_issue.R --repo $GITHUB_REPOSITORY --git_pat $GH_PAT) |
| 90 | + echo URL issue exists: $issue_exists |
| 91 | + echo "issue_existence=$issue_exists" >> $GITHUB_OUTPUT |
| 92 | +
|
| 93 | + - name: If too many URL errors, then make an issue |
| 94 | + if: ${{ steps.check-report.outputs.error_num >= 1 && steps.find-issue.outputs.issue_existence == 0}} |
| 95 | + uses: JasonEtco/create-an-issue@v2 |
| 96 | + with: |
| 97 | + filename: .github/ISSUE_TEMPLATE/url-error.md |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + FILE_URL: ${{ steps.check-report.outputs.error_url }} |
| 101 | + ERROR_NUM: ${{ steps.check-report.outputs.error_num }} |
| 102 | + |
| 103 | + - name: If no URL errors than delete the branch we made |
| 104 | + if: ${{ steps.check-report.outputs.error_num < 1 }} |
| 105 | + run: | |
| 106 | + git config --system --add safe.directory "$GITHUB_WORKSPACE" |
| 107 | + git push origin --delete preview-spell-error || echo "No branch to delete" |
0 commit comments