From 49a2e5136765d7d3505f75b9f173f276478a5888 Mon Sep 17 00:00:00 2001 From: Mahe Tardy Date: Mon, 25 Mar 2024 18:52:45 +0100 Subject: [PATCH] workflows: only check links added by a PR Previously the PR link checker was checking any link, with this update it should just try the links added by the PR. Signed-off-by: Mahe Tardy --- .github/workflows/check-links-pr.yaml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check-links-pr.yaml b/.github/workflows/check-links-pr.yaml index 05ec1237268..9d192dc40ce 100644 --- a/.github/workflows/check-links-pr.yaml +++ b/.github/workflows/check-links-pr.yaml @@ -12,6 +12,8 @@ on: jobs: links-checker: runs-on: ubuntu-latest + env: + PATCH_FILE: "additions.patch" steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -24,22 +26,17 @@ jobs: hugo-version: '0.120.4' extended: true - - name: Replace GitHub main links with local branch + - name: Retrieve diff and replace GitHub main links with local branch shell: bash run: | REPO=${{ github.event.pull_request.head.repo.full_name }} BRANCH=${{ github.event.pull_request.head.ref }} - find docs/content/ -type f -name "*.md" -exec sed -i "s#/cilium/tetragon/tree/main#/$REPO/tree/$BRANCH#g" {} \; - sed -i "s#/cilium/tetragon/tree/main#/$REPO/tree/$BRANCH#g" README.md + git diff -U0 origin/${{ github.base_ref }} -- docs/content README.md | grep ^\+[^+] > $PATCH_FILE - find docs/content/ -type f -name "*.md" -exec sed -i "s#/cilium/tetragon/blob/main#/$REPO/blob/$BRANCH#g" {} \; - sed -i "s#/cilium/tetragon/blob/main#/$REPO/blob/$BRANCH#g" README.md - - find docs/content/ -type f -name "*.md" -exec sed -i "s#/cilium/tetragon/main#/$REPO/$BRANCH#g" {} \; - sed -i "s#/cilium/tetragon/main#/$REPO/$BRANCH#g" README.md - - git diff -U0 + sed -i "s#/cilium/tetragon/tree/main#/$REPO/tree/$BRANCH#g" $PATCH_FILE + sed -i "s#/cilium/tetragon/blob/main#/$REPO/blob/$BRANCH#g" $PATCH_FILE + sed -i "s#/cilium/tetragon/main#/$REPO/$BRANCH#g" $PATCH_FILE - name: Serve the Hugo website working-directory: docs @@ -61,5 +58,5 @@ jobs: env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} with: - args: --config .github/lychee.toml --base http://localhost:1313 docs/content README.md + args: --config .github/lychee.toml --base http://localhost:1313 $PATCH_FILE fail: true