From 0abed91f7c2e7275a6cbfe18a85398e4885c4b5d Mon Sep 17 00:00:00 2001 From: Barbara Peric <50910606+barbaraperic@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:18:10 +0200 Subject: [PATCH] Create main.yml --- .github/workflows/main.yml | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c2cb511 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,69 @@ +name: Check Broken Links + +on: + schedule: + - cron: "0 2 * * 0" # Runs every Sunday at 2 AM + workflow_dispatch: + +jobs: + linkcheck: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE_LABEL: "Content" + ISSUE_TITLE: "[CONTENT] Broken Links Found" + WORKFLOW_FILE_PATH: ".github/workflows/check-broken-links.yml" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check links with linkcheck + uses: filiph/linkcheck@3.0.0 + with: + arguments: "https://www.yourwebsite.com --external --skip-file linkcheck-skip-file.txt > linkcheck-results.txt" + id: linkcheck + + - name: Upload linkcheck-results.txt as artifact + if: ${{ failure() }} + uses: actions/upload-artifact@v3 + with: + name: linkcheck-results + path: linkcheck-results.txt + + - name: Fetch existing issues + if: ${{ failure() }} + run: gh issue list --label "${ISSUE_LABEL}" --search "${ISSUE_TITLE}" --json number -q ".[].number" > issue_numbers.txt + + - name: Close existing issues + if: ${{ failure() }} + run: | + while IFS= read -r ISSUE; do + echo "Attempting to close issue #$ISSUE" + gh issue close $ISSUE --repo ${{ github.repository }} + done < issue_numbers.txt + + - name: Create new issue + if: ${{ failure() }} + id: create_issue + uses: dacbd/create-issue-action@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: ${{ env.ISSUE_TITLE }} + body: | + **Describe the issue** + During our scheduled (or manually-triggered) link check, the workflow [Check Broken Links](https://github.com/${{ github.repository }}/${{ env.WORKFLOW_FILE_PATH }}) identified one or more broken links in the repository. + Details of the broken links, including their locations and the reasons for failure, can be found in the `linkcheck-results.txt` artifact, at the end of the [failed run page here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). + 🔗 **Workflow name** - `${{ github.workflow }}` + 📇 **Job** - `${{ github.job }}` + 🚦 **Status** - `${{ job.status }}` + labels: ${{ env.ISSUE_LABEL }} + assignees: your-github-username + + - name: Update closed issues with new issue link + if: ${{ failure() }} + run: | + NEW_ISSUE_LINK="${{ steps.create_issue.outputs.html_url }}" + while IFS= read -r ISSUE; do + gh issue comment $ISSUE --body "Closed in favor of $NEW_ISSUE_LINK" + done < issue_numbers.txt