-
Notifications
You must be signed in to change notification settings - Fork 125
74 lines (68 loc) · 3.49 KB
/
CleanupTempRepos.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Cleanup after failed E2E
on:
workflow_dispatch:
inputs:
githubOwner:
description: GitHub organization set as owner for the temp repositories (default is to use your personal account)
required: false
default: ''
defaults:
run:
shell: pwsh
jobs:
Check:
runs-on: [ ubuntu-latest ]
outputs:
githubOwner: ${{ steps.check.outputs.githubOwner }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Check secrets
id: check
env:
githubOwner: ${{ github.event.inputs.githubOwner }}
run: |
$err = $false
if ('${{ Secrets.E2EPAT }}' -eq '') {
Write-Host "::Error::In order to run end to end tests, you need a Secret called E2EPAT containing a valid Personal Access Token with the following permissions: admin:org, delete_repo, repo, workflow, packages:write"
$err = $true
}
if ('${{ Secrets.adminCenterApiCredentials }}' -eq '') {
Write-Host "::Error::In order to run end to end tests, you need a Secret called adminCenterApiCredentials containing API access credentials for BC Admin Center"
$err = $true
}
if ($err) {
exit 1
}
$githubOwner = $ENV:githubOwner
if (!($githubOwner)) {
$githubOwner = "$ENV:GITHUB_REPOSITORY_OWNER"
}
$orgmap = Get-Content -path (Join-Path "." "e2eTests\orgmap.json") -encoding UTF8 -raw | ConvertFrom-Json
if ($orgmap.PSObject.Properties.Name -eq $githubOwner) {
$githubOwner = $orgmap."$githubOwner"
}
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "githubOwner=$githubOwner"
Write-Host "githubOwner=$githubOwner"
RemoveRepositories:
runs-on: [ ubuntu-latest ]
needs: [ Check ]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Remove Temp Repositories
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
Import-Module (Join-Path "." "e2eTests/e2eTestHelper.psm1") -DisableNameChecking
$owner = '${{ needs.Check.outputs.githubowner }}'
$token = '${{ Secrets.E2EPAT }}'
SetTokenAndRepository -github -githubOwner $owner -token $token -repository ''
@(invoke-gh repo list $owner --limit 1000 -silent -returnValue) | ForEach-Object { $_.Split("`t")[0] } | Where-Object { "$_" -like "$owner/tmp*" } | ForEach-Object {
$repo = $_
Write-Host "https://github.com/$repo"
$repoOwner = $repo.Split('/')[0]
@((invoke-gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/orgs/$repoOwner/packages?package_type=nuget" -silent -returnvalue -ErrorAction SilentlyContinue | ConvertFrom-Json)) | Where-Object { ($_.PSObject.Properties.Name -eq 'repository') -and ($_.repository.full_name -eq $repo) } | ForEach-Object {
Write-Host "- package $($_.name)"
# Pipe empty string into GH API --METHOD DELETE due to https://github.com/cli/cli/issues/3937
'' | invoke-gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/orgs/$repoOwner/packages/nuget/$($_.name)" --input -
}
invoke-gh repo delete "https://github.com/$repo" --yes | Out-Host
}