From 1708e0f19d76f2feebc7cab3ecd81a0bc2b65878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Mu=C3=B1oz?= Date: Thu, 8 Feb 2024 11:55:21 +0100 Subject: [PATCH] Move tests files to .github/workflows --- ql/lib/test/{ => .github/workflows}/test.yml | 0 .../{ => .github/workflows}/changed-files.yml | 0 ql/src/test/.github/workflows/ci-cleanup.yml | 47 ++++++++++++++ .../workflows/image_link_generator.yml | 55 +++++++++++++++++ .../workflows/image_link_generator_2.yml | 61 +++++++++++++++++++ .../workflows/image_link_generator_3.yml | 27 ++++++++ .../test/{ => .github/workflows}/inter1.yml | 0 .../test/{ => .github/workflows}/no-flow1.yml | 0 .../test/{ => .github/workflows}/no-flow2.yml | 0 .../test/{ => .github/workflows}/simple1.yml | 0 .../test/{ => .github/workflows}/simple2.yml | 0 ql/src/test/{ => .github/workflows}/test.yml | 0 12 files changed, 190 insertions(+) rename ql/lib/test/{ => .github/workflows}/test.yml (100%) rename ql/src/test/{ => .github/workflows}/changed-files.yml (100%) create mode 100644 ql/src/test/.github/workflows/ci-cleanup.yml create mode 100644 ql/src/test/.github/workflows/image_link_generator.yml create mode 100644 ql/src/test/.github/workflows/image_link_generator_2.yml create mode 100644 ql/src/test/.github/workflows/image_link_generator_3.yml rename ql/src/test/{ => .github/workflows}/inter1.yml (100%) rename ql/src/test/{ => .github/workflows}/no-flow1.yml (100%) rename ql/src/test/{ => .github/workflows}/no-flow2.yml (100%) rename ql/src/test/{ => .github/workflows}/simple1.yml (100%) rename ql/src/test/{ => .github/workflows}/simple2.yml (100%) rename ql/src/test/{ => .github/workflows}/test.yml (100%) diff --git a/ql/lib/test/test.yml b/ql/lib/test/.github/workflows/test.yml similarity index 100% rename from ql/lib/test/test.yml rename to ql/lib/test/.github/workflows/test.yml diff --git a/ql/src/test/changed-files.yml b/ql/src/test/.github/workflows/changed-files.yml similarity index 100% rename from ql/src/test/changed-files.yml rename to ql/src/test/.github/workflows/changed-files.yml diff --git a/ql/src/test/.github/workflows/ci-cleanup.yml b/ql/src/test/.github/workflows/ci-cleanup.yml new file mode 100644 index 00000000000..11a101cef49 --- /dev/null +++ b/ql/src/test/.github/workflows/ci-cleanup.yml @@ -0,0 +1,47 @@ +run-name: Cleanup ${{ github.head_ref }} +on: + pull_request_target: + types: labeled + paths: + - "images/**" + +jobs: + clean_ci: + name: Clean CI runs + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: pwsh + run: | + $startDate = Get-Date -UFormat %s + $workflows = @("macos11", "macos12", "ubuntu2004", "ubuntu2204", "windows2019", "windows2022") + while ($true) { + $continue = $false + foreach ($wf in $workflows) { + $skippedCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status skipped --json databaseId" + $skippedIds = Invoke-Expression -Command $skippedCommand | ConvertFrom-Json | ForEach-Object { $_.databaseId } + $skippedIds | ForEach-Object { + $deleteCommand = "gh run delete --repo ${{ github.repository }} $_" + Invoke-Expression -Command $deleteCommand + } + $pendingCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status requested --json databaseId --template '{{ . | len }}'" + $pending = Invoke-Expression -Command $pendingCommand + if ($pending -gt 0) { + Write-Host "Pending for ${wf}.yml: $pending run(s)" + $continue = $true + } + } + if ($continue -eq $false) { + Write-Host "All done, exiting" + break + } + $curDate = Get-Date -UFormat %s + if (($curDate - $startDate) -gt 60) { + Write-Host "Reached timeout, exiting" + break + } + Write-Host "Waiting 5 seconds..." + Start-Sleep -Seconds 5 diff --git a/ql/src/test/.github/workflows/image_link_generator.yml b/ql/src/test/.github/workflows/image_link_generator.yml new file mode 100644 index 00000000000..6239f0490d1 --- /dev/null +++ b/ql/src/test/.github/workflows/image_link_generator.yml @@ -0,0 +1,55 @@ +name: Image URL Processing + +on: + issue_comment: + types: [created] + +jobs: + process-image-url: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, 'https://github.com/github/release-assets/assets/') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Extract and Clean Initial URL + id: extract-url + run: | + INITIAL_URL=$(echo "${{ github.event.comment.body }}" | grep -o 'https://github.com/github/release-assets/assets/[^ >]*') + echo "Cleaned Initial URL: $INITIAL_URL" + echo "::set-output name=initial_url::$INITIAL_URL" + + - name: Get Redirected URL with Debugging + id: curl + run: | + REDIRECTED_URL=$(curl -L -o /dev/null -w %{url_effective} -sS "${{ steps.extract-url.outputs.initial_url }}") + echo "Curl Command Executed" + echo "Redirected URL: $REDIRECTED_URL" + echo "::set-output name=redirected_url::$REDIRECTED_URL" + + - name: Trim URL after PNG + id: trim-url + run: | + TRIMMED_URL=$(echo "${{ steps.curl.outputs.redirected_url }}" | sed 's/\(.*\.png\).*/\1/') + echo "Trimmed URL: $TRIMMED_URL" + echo "::set-output name=trimmed_url::$TRIMMED_URL" + + - name: Output Final Trimmed URL + run: | + echo "Final Trimmed Image URL: ${{ steps.trim-url.outputs.trimmed_url }}" + + - name: Update Comment with New URL + run: | + COMMENT_URL="${{ github.event.comment.url }}" + NEW_COMMENT_BODY="Use this link to include this asset in your changelog: ${{ steps.trim-url.outputs.trimmed_url }}" + ORIGINAL_COMMENT_BODY="${{ github.event.comment.body }}" + UPDATED_COMMENT="${ORIGINAL_COMMENT_BODY} 👀 ${NEW_COMMENT_BODY}" + + PAYLOAD=$(jq -n --arg body "$UPDATED_COMMENT" '{"body": $body}') + curl -X PATCH \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + "${COMMENT_URL}" \ + -d "$PAYLOAD" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/ql/src/test/.github/workflows/image_link_generator_2.yml b/ql/src/test/.github/workflows/image_link_generator_2.yml new file mode 100644 index 00000000000..01d33249251 --- /dev/null +++ b/ql/src/test/.github/workflows/image_link_generator_2.yml @@ -0,0 +1,61 @@ +name: Image URL Processing + +on: + issue_comment: + types: [created] + +jobs: + process-image-url: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, 'https://github.com/github/release-assets/assets/') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Extract and Clean Initial URL + id: extract-url + env: + BODY: ${{ github.event.comment.body }} + run: | + INITIAL_URL=$(echo "$BODY" | grep -o 'https://github.com/github/release-assets/assets/[^ >]*') + echo "Cleaned Initial URL: $INITIAL_URL" + echo "::set-output name=initial_url::$INITIAL_URL" + + - name: Get Redirected URL with Debugging + id: curl + env: + INITIAL_URL: ${{ steps.extract-url.outputs.initial_url }} + run: | + REDIRECTED_URL=$(curl -L -o /dev/null -w %{url_effective} -sS "$INITIAL_URL") + echo "Curl Command Executed" + echo "Redirected URL: $REDIRECTED_URL" + echo "::set-output name=redirected_url::$REDIRECTED_URL" + + - name: Trim URL after PNG + id: trim-url + env: + REDIRECTED_URL: ${{ steps.curl.outputs.redirected_url }} + run: | + TRIMMED_URL=$(echo "$REDIRECTED_URL" | sed 's/\(.*\.png\).*/\1/') + echo "Trimmed URL: $TRIMMED_URL" + echo "::set-output name=trimmed_url::$TRIMMED_URL" + + - name: Output Final Trimmed URL + run: | + echo "Final Trimmed Image URL: ${{ steps.trim-url.outputs.trimmed_url }}" + + - name: Update Comment with New URL + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMMENT_URL: ${{ github.event.comment.url }} + ORIGINAL_COMMENT_BODY: ${{ github.event.comment.body }} + run: | + NEW_COMMENT_BODY="Use this link to include this asset in your changelog: ${{ steps.trim-url.outputs.trimmed_url }}" + UPDATED_COMMENT="${ORIGINAL_COMMENT_BODY} 👀 ${NEW_COMMENT_BODY}" + + PAYLOAD=$(jq -n --arg body "$UPDATED_COMMENT" '{"body": $body}') + curl -X PATCH \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + "${COMMENT_URL}" \ + -d "$PAYLOAD" diff --git a/ql/src/test/.github/workflows/image_link_generator_3.yml b/ql/src/test/.github/workflows/image_link_generator_3.yml new file mode 100644 index 00000000000..70aece4f7cf --- /dev/null +++ b/ql/src/test/.github/workflows/image_link_generator_3.yml @@ -0,0 +1,27 @@ +name: Image URL Processing + +on: + issue_comment: + types: [created] + +jobs: + process-image-url: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, 'https://github.com/github/release-assets/assets/') + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Extract and Clean Initial URL + id: source + env: + BODY: ${{ github.event.comment.body }} + run: | + INITIAL_URL=$(echo "$BODY" | grep -o 'https://github.com/github/release-assets/assets/[^ >]*') + echo "Cleaned Initial URL: $INITIAL_URL" + echo "::set-output name=initial_url::$INITIAL_URL" + + - name: Get Redirected URL with Debugging + id: sink + run: | + echo ${{ steps.source.outputs.initial_url }} diff --git a/ql/src/test/inter1.yml b/ql/src/test/.github/workflows/inter1.yml similarity index 100% rename from ql/src/test/inter1.yml rename to ql/src/test/.github/workflows/inter1.yml diff --git a/ql/src/test/no-flow1.yml b/ql/src/test/.github/workflows/no-flow1.yml similarity index 100% rename from ql/src/test/no-flow1.yml rename to ql/src/test/.github/workflows/no-flow1.yml diff --git a/ql/src/test/no-flow2.yml b/ql/src/test/.github/workflows/no-flow2.yml similarity index 100% rename from ql/src/test/no-flow2.yml rename to ql/src/test/.github/workflows/no-flow2.yml diff --git a/ql/src/test/simple1.yml b/ql/src/test/.github/workflows/simple1.yml similarity index 100% rename from ql/src/test/simple1.yml rename to ql/src/test/.github/workflows/simple1.yml diff --git a/ql/src/test/simple2.yml b/ql/src/test/.github/workflows/simple2.yml similarity index 100% rename from ql/src/test/simple2.yml rename to ql/src/test/.github/workflows/simple2.yml diff --git a/ql/src/test/test.yml b/ql/src/test/.github/workflows/test.yml similarity index 100% rename from ql/src/test/test.yml rename to ql/src/test/.github/workflows/test.yml