Cleanup Temp Repos #163
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1 | |
| 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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.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@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4 | |
| 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 |