Skip to content

Cleanup Temp Repos #169

Cleanup Temp Repos

Cleanup Temp Repos #169

name: Cleanup Temp Repos
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: ''
workflow_run:
workflows: [End to end tests]
types:
- completed
defaults:
run:
shell: pwsh
permissions:
contents: read
jobs:
CleanupRepos:
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} # Run only if dispatched or the End to end tests workflow has succeeded
runs-on: [ ubuntu-latest ]
name: Cleanup Temp Repos
steps:
- name: Harden Runner
if: github.repository_owner == 'microsoft'
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
with:
egress-policy: audit
- name: Check E2E app is set up
run: |
if (('${{ vars.E2E_APP_ID }}' -eq '') -or ('${{ secrets.E2E_PRIVATE_KEY }}' -eq '')) {
Write-Host "::Error:: In order to clean up the temp repositories you must have a secret called E2E_PRIVATE_KEY and a variable called E2E_APP_ID defined in your repository."
exit 1
}
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- name: Get GitHub Owner
id: getGitHubOwner
env:
githubOwner: ${{ github.event.inputs.githubOwner }}
run: |
${{ github.workspace }}/Internal/Scripts/GetOwnerForE2ETests.ps1 -githubOwner $env:githubOwner
- uses: actions/create-github-app-token@7e473efe3cb98aa54f8d4bac15400b15fad77d94 # v2.2.0
id: app-token
if: ${{ vars.E2E_APP_ID != '' }}
with:
app-id: ${{ vars.E2E_APP_ID }}
private-key: ${{ secrets.E2E_PRIVATE_KEY }}
owner: ${{ steps.getGitHubOwner.outputs.githubOwner }}
- name: Cleanup Temp Repositories
env:
githubOwner: ${{ steps.getGitHubOwner.outputs.githubOwner }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
${{ github.workspace }}/Internal/Scripts/RemoveTempRepos.ps1 -githubOwner $env:githubOwner